Skip to contentSkip to conversation

mm/damon/sysfs: skip registration if DAMON core init fails

PATCH In review Aveline Noir 3 participants 3 messages Nov 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/damon/sysfs: skip registration if DAMON core init fails

Hi SJ,

Here's the sysfs fix I mentioned in the report queue review.

-- >8 --

While reviewing the DAMON report queue series, I noticed that DAMON sysfs still registers its interface if DAMON core initialization fails. If damon_init() fails to allocate damon_region_cache, starting a kdamond with an initial region can pass a NULL cache to kmem_cache_alloc() via damon_new_region().

Check damon_initialized() before creating the DAMON sysfs directory and return -ENOMEM if the core is unavailable.

Fixes a18709442869 ("mm/damon: improve damon_new_region strategy")

---
Tests passed in x86-64 QEMU TCG guests on 9f004372ebeb.

---
 mm/damon/sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
mm/damon/sysfs.c +3 -0
index 779c98205a94..7de0f03a3fd5 100644
@@ -3035,6 +3035,9 @@ static int __init damon_sysfs_init(void)
 	struct damon_sysfs_ui_dir *admin;
 	int err;
 
+	if (!damon_initialized())
+		return -ENOMEM;
+
 	damon_sysfs_root = kobject_create_and_add("damon", mm_kobj);
 	if (!damon_sysfs_root)
 		return -ENOMEM;

---
base-commit: 9f004372ebeb18fdeb699f9880a0e472df90135b
change-id: 20261123-damon-sysfs-init-guard-fc87e688acae

Signature · 2 lines
Thanks,
Aveline Noir
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

Hi SJ,

Here's the sysfs fix I mentioned in the report queue review.

-- >8 --

While reviewing the DAMON report queue series, I noticed that DAMON sysfs still registers its interface if DAMON core initialization fails. If damon_init() fails to allocate damon_region_cache, starting a kdamond with an initial region can pass a NULL cache to kmem_cache_alloc() via damon_new_region().

Quoted 5 lines

Check damon_initialized() before creating the DAMON sysfs directory and return -ENOMEM if the core is unavailable.

Fixes a18709442869 ("mm/damon: improve damon_new_region strategy")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Aveline Noir
Quoted 11 lines · On Mon, 23 Nov 2026 18:51:45 +1100 Aveline Noir <[email protected]> wrote:

Hi SJ,

Here's the sysfs fix I mentioned in the report queue review.

-- >8 --

While reviewing the DAMON report queue series, I noticed that DAMON sysfs still registers its interface if DAMON core initialization fails. If damon_init() fails to allocate damon_region_cache, starting a kdamond with an initial region can pass a NULL cache to kmem_cache_alloc() via damon_new_region().

"While reviewing ..." part seems unnecessary for git history. The user impact (NULL dereference) could better be documented. What about below?

'''
DAMON sysfs registers ints interface even if DAMON core initialization fails. If damon_init() fails to allocate damon_region_cache, starting a kdamond with an initial region can pass a NULL cache to kmem_cache_alloc() via damon_new_region(). As a result, NULL dereference can happen. The initialization failure is unlikely, but the consequence is quite bad. '''

Quoted 3 lines

Check damon_initialized() before creating the DAMON sysfs directory and return -ENOMEM if the core is unavailable.

Thank you for finding and fixing the issue!

Quoted 3 lines
Fixes a18709442869 ("mm/damon: improve damon_new_region strategy")

Other than the above commit message,

With the above assumption, I applied this patch to damon/next [1] tree with the commit message update. I will repost it soon (~1 week) as an mm.git merge request. So, no action from your side is needed for now.

[1] https://origin.kernel.org/doc/html/latest/mm/damon/maintainer-profile.html#scm-trees

Thanks,
SJ

[...]