mm/damon/sysfs: skip registration if DAMON core init fails
Subsystems (2)
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.
---
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
@@ -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
[email protected]
AI reviewSashiko 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 allocatedamon_region_cache, starting a kdamond with an initial region can pass a NULL cache tokmem_cache_alloc()viadamon_new_region().
Quoted 5 lines
Check
damon_initialized()before creating the DAMON sysfs directory and return-ENOMEMif the core is unavailable.Fixes a18709442869 ("mm/damon: improve damon_new_region strategy")Signed-off-by Aveline Noir <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
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 allocatedamon_region_cache, starting a kdamond with an initial region can pass a NULL cache tokmem_cache_alloc()viadamon_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-ENOMEMif the core is unavailable.
Thank you for finding and fixing the issue!
Quoted 3 lines
Fixes a18709442869 ("mm/damon: improve damon_new_region strategy")Signed-off-by Aveline Noir <[email protected]>
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
[...]