Skip to contentSkip to conversation

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

PATCH New SJ Park 3 participants 3 messages Nov 30 – Dec 1

Subsystems (3)
lore
Share & tools
lore

SJ Park

author maintainer
#0 lore raw

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

From: Aveline Noir <[email protected]>

DAMON sysfs registers its 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.

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")
Cc <[email protected]> # 6.1.x
Cc Lian Wang <[email protected]>
Cc Dawei Li <[email protected]>

---
Changes from v1
- v1: https://lore.kernel.org/[email protected]
- Update commit message.
- Collect R-b: from SJ.
- Collect T-b: and R-b: from Enze Li.
- Cc stable@.
- Rebase to the latest mm-new.

 mm/damon/sysfs.c | 3 +++
 1 file changed, 3 insertions(+)
mm/damon/sysfs.c +3 -0
index 70a4b64fb8ea..973213e4313a 100644
@@ -3031,6 +3031,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: d1d23727a7f0d50eef2075d78d7fa26200303217

Signature · 1 line
2.47.3
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

From: Aveline Noir <[email protected]>

DAMON sysfs registers its 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.

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

Quoted 9 lines
Fixes a18709442869 ("mm/damon: improve damon_new_region strategy")
Cc <[email protected]> # 6.1.x
Cc Lian Wang <[email protected]>
Cc Dawei Li <[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
maintainer tree notice
#2 lore raw

+ mm-damon-sysfs-skip-registration-if-damon-core-init-fails.patch added to mm-hotfixes-unstable branch

In reply to SJ Park
The patch titled Subject: mm/damon/sysfs: skip registration if DAMON core init fails has been added to the -mm mm-hotfixes-unstable branch. Its filename is…

The patch titled
Subject: mm/damon/sysfs: skip registration if DAMON core init fails
has been added to the -mm mm-hotfixes-unstable branch. Its filename is
mm-damon-sysfs-skip-registration-if-damon-core-init-fails.patch

This patch will shortly appear at
https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-damon-sysfs-skip-registration-if-damon-core-init-fails.patch

This patch will later appear in the mm-hotfixes-unstable branch at
git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Aveline Noir <[email protected]>
Subject: mm/damon/sysfs: skip registration if DAMON core init fails
Date: Mon, 30 Nov 2026 07:07:28 -0800

DAMON sysfs registers its 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.

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")
Cc Lian Wang <[email protected]>
Cc Dawei Li <[email protected]>
Cc <[email protected]> # 6.1.x
 mm/damon/sysfs.c |    3 +++
 1 file changed, 3 insertions(+)
mm/damon/sysfs.c renamed from mm/damon/sysfs.c~mm-damon-sysfs-skip-registration-if-damon-core-init-fails +3 -0
@@ -3031,6 +3031,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;

_

Patches currently in -mm which might be from [email protected] are

mm-hmm-account-for-subpage-offsets-in-device-private-pmds.patch mm-damon-sysfs-skip-registration-if-damon-core-init-fails.patch mm-damon-ops-common-align-mmu-notifier-range-when-clearing-pmd-young-bit.patch mm-damon-stat-avoid-32-bit-overflow-in-idle-percentiles.patch mm-damon-pvaddr-skip-folios-already-on-the-migration-target-node.patch docs-admin-guide-mm-damon-start-fix-grammar.patch docs-admin-guide-mm-damon-stat-fix-pronoun-agreement.patch docs-admin-guide-mm-damon-usage-fix-grammar.patch docs-admin-guide-mm-damon-lru_sort-fix-remaining-grammar.patch docs-mm-damon-design-fix-grammar-and-typos.patch docs-mm-damon-api-fix-verb-form.patch docs-mm-damon-maintainer-profile-fix-subject-verb-agreement.patch docs-mm-damon-monitoring_intervals_tuning_example-fix-grammar-and-typos.patch mm-damon-paddr-add-kunit-tests-for-addr_unit-conversion.patch mm-damon-paddr-add-kunit-tests-for-addr_unit-conversion-fix.patch mm-damon-paddr-skip-non-lru-folios-as-a-whole-in-pageout.patch mm-damon-core-skip-apply_probes-when-no-probes-are-installed.patch selftests-damon-damos_quota-skip-the-last-sample-when-counting-exceeds.patch