mm/damon/sysfs: kobject_del() directories that users can create/remove
Subsystems (3)
SeongJae Park
maintainercover mm/damon/sysfs: kobject_del() directories that users can create/remove
DAMON sysfs interface allows users to create and remove arbitrary number of directories on sysfs, using a few files having 'nr_' prefix. For example, 'nr_kdamonds'. When the user writes a number 'N' to the files, directories having name starting from '0' to 'N - 1' are created in the same directory. The pre-existing number-named directories are removed before creating the new directories.
For the removal of the existing directories, DAMON sysfs interface use only kobject_put(). Because DAMON sysfs interface is the only kernel component that manages the directories, there is no problem in normal situations. However, if CONFIG_DEBUG_KOBJECT_RELEASE is enabled, the removal of dirs are delayed. Let's suppose a user writes a non-zero number to the 'nr_*' files while there are pre-existing number-named directories, on the config enabled kernel. DAMON sysfs interface decreases the reference counts of the existing directories and immediately creates new directories. Because the removal of the sysfs directories is delayed, it shows some pre-existing directories of the same names when it tries to create the new directories, and fails.
For example, the issue can be triggered like below:
# grep DEBUG_KOBJECT_RELEASE /boot/config-$(uname -r)
CONFIG_DEBUG_KOBJECT_RELEASE=y
# ls
nr_kdamonds
# echo 1 > nr_kdamonds
# echo 1 > nr_kdamonds
bash: echo: write error: File exists
# dmesg
[...]
[ 300.880458] kobject: kobject_add_internal failed for 0 with -EEXIST, don't try to register things with the same name in the same directory.
[...]Some of the error handling paths of the directories also lack the kobject_del() call. If the user uses nr_* file right after the errors, similar issues can happen.
This doesn't cause catastrophic issues like kernel panics or memory corruptions. Users can work around by removing all directories first (write 0 to the nr_* files) and then create new directories after confirming the old directories are gone. But, this is definitely a bug that causes a bad user experience.
Fix the issues by calling kobject_del() before creating new directories.
Patches Sequence
================
There are a number of bugs of this class that are introduced by eleven different commits. The fixes are grouped and ordered for the introducing commits.
Changes from RFC v1.1
- RFC v1.1: https://lore.kernel.org/[email protected]
- Add error path fix for damon_sysfs_schemes_add_dirs().
- Rebase to latest mm-new.
Changes from RFC v1
- RFC v1: https://lore.kernel.org/[email protected]
- Add error path fixes.
SeongJae Park (11):
mm/damon/sysfs: kobject_del() target (normal), context and kdamond
dirs
mm/damon/sysfs: kobject_del() region and target (error) dirs mm/damon/sysfs-schemes: kobject_del() scheme dirs mm/damon/sysfs-schemes: kobject_del() scheme region dirs mm/damon/sysfs-schemes: kobject_del() scheme filter dirs mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirs mm/damon/sysfs-schemes: kobject_del() scheme action destination dirs mm/damon/sysfs: kobject_del() probe dirs
mm/damon/sysfs: kobject_del() probe filter dirs mm/damon/sysfs: kobject_del() probe dirs in probes_addd_dir error path mm/damon/sysfs-schemes: kobject_del() region for populate_region error
mm/damon/sysfs-schemes.c | 22 +++++++++++++++++----- mm/damon/sysfs.c | 25 ++++++++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-)
base-commit: 30941f0c4e32b31d4dcf2956491c5a3ac9c5beb4
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 1/11 mm/damon/sysfs: kobject_del() target (normal), context and kdamond dirs
On CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for normal creation paths of target, context and kdamond directories, and error paths of context and kdamond directories by adding kobject_del() calls.
Note that this fix for target directories is not complete since it has a similar issue in the damon_sysfs_targets_add_dirs() error path. Because the normal path issue and the error path issue are introduced by different commits, this commit is fixing only the normal path issue. A commit for the error path will be added next.
--- mm/damon/sysfs.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +9 -2
@@ -333,6 +333,7 @@ static void damon_sysfs_targets_rm_dirs(struct damon_sysfs_targets *targets)for (i =0 ; i < targets->nr; i++) {damon_sysfs_target_rm_dirs (targets_arr[i]); +kobject_del (&targets_arr[i]->kobj);kobject_put (&targets_arr[i]->kobj); } targets->nr =0 ;
@@ -1642,6 +1643,7 @@ static void damon_sysfs_contexts_rm_dirs(struct damon_sysfs_contexts *contexts)for (i =0 ; i < contexts->nr; i++) {damon_sysfs_context_rm_dirs (contexts_arr[i]); +kobject_del (&contexts_arr[i]->kobj);kobject_put (&contexts_arr[i]->kobj); } contexts->nr =0 ;
@@ -1680,13 +1682,15 @@ static int damon_sysfs_contexts_add_dirs(struct damon_sysfs_contexts *contexts, err =damon_sysfs_context_add_dirs (context);if (err) - goto out; + goto del_out; contexts_arr[i] = context; contexts->nr++; }return 0 ; +del_out: +kobject_del (&context->kobj); out:damon_sysfs_contexts_rm_dirs (contexts);kobject_put (&context->kobj);
@@ -2501,6 +2505,7 @@ static void damon_sysfs_kdamonds_rm_dirs(struct damon_sysfs_kdamonds *kdamonds)for (i =0 ; i < kdamonds->nr; i++) {damon_sysfs_kdamond_rm_dirs (kdamonds_arr[i]); +kobject_del (&kdamonds_arr[i]->kobj);kobject_put (&kdamonds_arr[i]->kobj); } kdamonds->nr =0 ;
@@ -2555,13 +2560,15 @@ static int damon_sysfs_kdamonds_add_dirs(struct damon_sysfs_kdamonds *kdamonds, err =damon_sysfs_kdamond_add_dirs (kdamond);if (err) - goto out; + goto del_out; kdamonds_arr[i] = kdamond; kdamonds->nr++; }return 0 ; +del_out: +kobject_del (&kdamond->kobj); out:damon_sysfs_kdamonds_rm_dirs (kdamonds);kobject_put (&kdamond->kobj);
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 2/11 mm/damon/sysfs: kobject_del() region and target (error) dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for the normal creation path of region directories and the error path of target directories, by adding kobject_del() calls.
--- mm/damon/sysfs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
mm/damon/sysfs.c +6 -2
@@ -107,8 +107,10 @@ static void damon_sysfs_regions_rm_dirs(struct damon_sysfs_regions *regions)struct damon_sysfs_region **regions_arr = regions->regions_arr;int i; -for (i =0 ; i < regions->nr; i++) +for (i =0 ; i < regions->nr; i++) { +kobject_del (®ions_arr[i]->kobj);kobject_put (®ions_arr[i]->kobj); + } regions->nr =0 ;kfree (regions_arr); regions->regions_arr =NULL ;
@@ -372,13 +374,15 @@ static int damon_sysfs_targets_add_dirs(struct damon_sysfs_targets *targets, err =damon_sysfs_target_add_dirs (target);if (err) - goto out; + goto del_out; targets_arr[i] = target; targets->nr++; }return 0 ; +del_out: +kobject_del (&target->kobj); out:damon_sysfs_targets_rm_dirs (targets);kobject_put (&target->kobj);
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 3/11 mm/damon/sysfs-schemes: kobject_del() scheme dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +4 -1
@@ -2683,6 +2683,7 @@ void damon_sysfs_schemes_rm_dirs(struct damon_sysfs_schemes *schemes)for (i =0 ; i < schemes->nr; i++) {damon_sysfs_scheme_rm_dirs (schemes_arr[i]); +kobject_del (&schemes_arr[i]->kobj);kobject_put (&schemes_arr[i]->kobj); } schemes->nr =0 ;
@@ -2724,13 +2725,15 @@ static int damon_sysfs_schemes_add_dirs(struct damon_sysfs_schemes *schemes, goto out; err =damon_sysfs_scheme_add_dirs (scheme);if (err) - goto out; + goto del_out; schemes_arr[i] = scheme; schemes->nr++; }return 0 ; +del_out: +kobject_del (&scheme->kobj); out:damon_sysfs_schemes_rm_dirs (schemes);kobject_put (&scheme->kobj);
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 4/11 mm/damon/sysfs-schemes: kobject_del() scheme region dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme region directories by adding kobject_del() calls.
This issue was discovered [1] by Sashiko, though its analysis was partially incorrect.
[1] https://lore.kernel.org/[email protected]
--- mm/damon/sysfs-schemes.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/sysfs-schemes.c +1 -0
@@ -334,6 +334,7 @@ static void damon_sysfs_scheme_regions_rm_dirs(list_for_each_entry_safe (r, next, ®ions->regions_list, list) {damos_sysfs_region_rm_dirs (r);list_del (&r->list); +kobject_del (&r->kobj);kobject_put (&r->kobj); regions->nr_regions--; }
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 5/11 mm/damon/sysfs-schemes: kobject_del() scheme filter dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme filter directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -914,8 +914,10 @@ static void damon_sysfs_scheme_filters_rm_dirs(struct damon_sysfs_scheme_filter **filters_arr = filters->filters_arr;int i; -for (i =0 ; i < filters->nr; i++) +for (i =0 ; i < filters->nr; i++) { +kobject_del (&filters_arr[i]->kobj);kobject_put (&filters_arr[i]->kobj); + } filters->nr =0 ;kfree (filters_arr); filters->filters_arr =NULL ;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 6/11 mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme quota goal directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -1465,8 +1465,10 @@ static void damos_sysfs_quota_goals_rm_dirs(struct damos_sysfs_quota_goal **goals_arr = goals->goals_arr;int i; -for (i =0 ; i < goals->nr; i++) +for (i =0 ; i < goals->nr; i++) { +kobject_del (&goals_arr[i]->kobj);kobject_put (&goals_arr[i]->kobj); + } goals->nr =0 ;kfree (goals_arr); goals->goals_arr =NULL ;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 7/11 mm/damon/sysfs-schemes: kobject_del() scheme action destination dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for scheme action destination directories by adding kobject_del() calls.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -2145,8 +2145,10 @@ static void damos_sysfs_dests_rm_dirs(struct damos_sysfs_dest **dests_arr = dests->dests_arr;int i; -for (i =0 ; i < dests->nr; i++) +for (i =0 ; i < dests->nr; i++) { +kobject_del (&dests_arr[i]->kobj);kobject_put (&dests_arr[i]->kobj); + } dests->nr =0 ;kfree (dests_arr); dests->dests_arr =NULL ;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 8/11 mm/damon/sysfs: kobject_del() probe dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for data attribute probe directories by adding kobject_del() calls.
--- mm/damon/sysfs.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/sysfs.c +1 -0
@@ -1139,6 +1139,7 @@ static void damon_sysfs_probes_rm_dirs(for (i =0 ; i < probes->nr; i++) {damon_sysfs_probe_rm_dirs (probes_arr[i]); +kobject_del (&probes_arr[i]->kobj);kobject_put (&probes_arr[i]->kobj); } probes->nr =0 ;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 9/11 mm/damon/sysfs: kobject_del() probe filter dirs
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix those issues for data attribute probe filter directories by adding kobject_del() calls.
--- mm/damon/sysfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs.c +3 -1
@@ -962,8 +962,10 @@ static void damon_sysfs_filters_rm_dirs(struct damon_sysfs_filters *filters)struct damon_sysfs_filter **filters_arr = filters->filters_arr;int i; -for (i =0 ; i < filters->nr; i++) +for (i =0 ; i < filters->nr; i++) { +kobject_del (&filters_arr[i]->kobj);kobject_put (&filters_arr[i]->kobj); + } filters->nr =0 ;kfree (filters_arr); filters->filters_arr =NULL ;
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v1.2 09/11] mm/damon/sysfs: kobject_del() probe filter dirs
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Medium] Missing kobject_del() call in damos_sysfs_region_add_dirs() error path causes delayed sysfs directory removal and subsequent -EEXIST name conflicts.
- [Medium] Missing kobject_del() in damos_sysfs_probes_rm_dirs() leaves child probe directories lingering in sysfs on error paths.
--
commit 6a62b56c2acdfd514de2a6e4cd36c3839e0c6db5
Author: SeongJae Park <[email protected]>
Subject: mm/damon/sysfs: kobject_del() probe filter dirs
This commit fixes directory creation failures due to name conflicts on kernels with CONFIG_DEBUG_KOBJECT_RELEASE. It does so by adding missing kobject_del() calls before kobject_put() in the data attribute probe filter directories' teardown path.
Quoted 6 lines
mm/damon/sysfs.c +0
-0@@ -962,8 +962,10 @@ static void damon_sysfs_filters_rm_dirs(struct damon_sysfs_filters *filters)struct damon_sysfs_filter **filters_arr = filters->filters_arr;
mm/damon/sysfs.c static void damon_sysfs_filters_rm_dirs(struct damon_sysfs_filters *filters) · line 971
Quoted 10 lines
mm/damon/sysfs.c +3
-1int i; -for (i =0 ; i < filters->nr; i++) +for (i =0 ; i < filters->nr; i++) { +kobject_del (&filters_arr[i]->kobj);kobject_put (&filters_arr[i]->kobj); + } filters->nr =0 ;kfree (filters_arr); filters->filters_arr =NULL ;
[Severity: Medium]
This is a pre-existing issue, but since we are fixing missing kobject_del() calls here, should we also update damos_sysfs_probes_rm_dirs() in mm/damon/sysfs-schemes.c?
When tearing down probe directories, the loop iterates over child probes and calls kobject_put(), but omitting kobject_del() might leave the successfully added child directories in sysfs pending delayed release:
mm/damon/sysfs-schemes.c:damos_sysfs_probes_rm_dirs() {
...
for (i = 0; i < probes->nr; i++)
kobject_put(&probes_arr[i]->kobj);
...
}Would this also result in -EEXIST name collisions on subsequent retry attempts?
[Severity: Medium]
This isn't a bug introduced by this patch, but does the error path in damos_sysfs_region_add_dirs() need similar handling?
If kobject_init_and_add() succeeds but the subsequent call to damos_sysfs_probes_add_dirs() fails, we jump to the fail path:
mm/damon/sysfs-schemes.c:damos_sysfs_region_add_dirs() {
...
err = kobject_init_and_add(&probes->kobj, &damos_sysfs_probes_ktype,
®ion->kobj, "probes");
if (err)
goto fail;
err = damos_sysfs_probes_add_dirs(probes, ctx, dregion);
if (err)
goto fail;
...
fail:
kobject_put(&probes->kobj);
return err;
}Could the lack of kobject_del(&probes->kobj) here delay the removal of the sysfs directory and cause an unexpected -EEXIST conflict if userspace attempts to recreate the region?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
SeongJae Park
maintainerRe: [RFC PATCH v1.2 09/11] mm/damon/sysfs: kobject_del() probe filter dirs
Quoted 5 lines · On Thu, 18 Jun 2026 15:34:50 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Medium] Missingkobject_del()call indamos_sysfs_region_add_dirs()error path causes delayed sysfs directory removal and subsequent-EEXISTname conflicts.
- [Medium] Missingkobject_del()indamos_sysfs_probes_rm_dirs()leaves child probe directories lingering in sysfs on error paths.
Both are wrong. Since users cannot arbitrarily add/remove probe dirs without it's parent, and because the parent is patched too call kobject_del(), probe directories don't need to be kobject_del()-ed.
Thanks,
SJ
[...]
SeongJae Park
maintainerRFC PATCH 10/11 mm/damon/sysfs: kobject_del() probe dirs in probes_addd_dir error path
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix the issue for data attribute probe filter directories in the error handling path of damon_sysfs_probes_add_dirs() by adding a kobject_del() call.
--- mm/damon/sysfs.c | 1 + 1 file changed, 1 insertion(+)
mm/damon/sysfs.c +1 -0
@@ -1183,6 +1183,7 @@ static int damon_sysfs_probes_add_dirs( err =damon_sysfs_probe_add_dirs (probe);if (err) { +kobject_del (&probe->kobj);kobject_put (&probe->kobj);damon_sysfs_probes_rm_dirs (probes);return err;
Signature · 1 line
2.47.3
SeongJae Park
maintainerRFC PATCH 11/11 mm/damon/sysfs-schemes: kobject_del() region for populate_region error
In reply to SeongJae ParkOn CONFIG_DEBUG_KOBJECT_RELEASE enabled kernel, lack of kobject_del() could cause directories creation failures due to the name conflicts. Fix the issue for tried region directories in the error handling path of damon_sysfs_populate_region_dir() by adding a kobject_del() call.
--- mm/damon/sysfs-schemes.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
mm/damon/sysfs-schemes.c +3 -1
@@ -3134,12 +3134,14 @@ void damos_sysfs_populate_region_dir(struct damon_sysfs_schemes *sysfs_schemes, sysfs_regions->nr_regions)) goto out;if (damos_sysfs_region_add_dirs (region, ctx, r)) - goto out; + goto del_out;list_add_tail (®ion->list, &sysfs_regions->regions_list); sysfs_regions->nr_regions++;return ; +del_out: +kobject_del (®ion->kobj); out:kobject_put (®ion->kobj); }
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [RFC PATCH v1.2 11/11] mm/damon/sysfs-schemes: kobject_del() region for populate_region error
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Memory leak in the error path of damon_sysfs_scheme_add_dirs() due to skipped cleanup of the 'stats' kobject. --
commit 73251d9a8366deae80fbc88ff7d3d42f79676704
Author: SeongJae Park <[email protected]>
mm/damon/sysfs-schemes: kobject_del() region for populate_region error
This patch fixes directory creation failures due to name conflicts when CONFIG_DEBUG_KOBJECT_RELEASE is enabled. It adds a missing kobject_del() call to properly clean up tried region directories in the error path of damos_sysfs_populate_region_dir().
mm/damon/sysfs-schemes.c
Quoted 4 lines
mm/damon/sysfs-schemes.c +0
-0
[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the kobject cleanup in this file, I noticed a memory leak in the error path of damon_sysfs_scheme_add_dirs():
mm/damon/sysfs-schemes.c:damon_sysfs_scheme_add_dirs() {
...
err = damon_sysfs_scheme_set_stats(scheme);
if (err)
goto put_filters_watermarks_quotas_access_pattern_out;
err = damon_sysfs_scheme_set_tried_regions(scheme);
if (err)
goto put_tried_regions_out;
return 0;put_tried_regions_out:
kobject_put(&scheme->tried_regions->kobj);
scheme->tried_regions = NULL;
put_filters_watermarks_quotas_access_pattern_out:
kobject_put(&scheme->ops_filters->kobj);
...
}If damon_sysfs_scheme_set_tried_regions() fails, it jumps to put_tried_regions_out. This attempts to clean up the failed tried_regions allocation, but then falls through to the next label.
Does this completely skip cleaning up the successfully allocated scheme->stats->kobj? Missing a call to kobject_put(&scheme->stats->kobj) here appears to permanently leak the stats kobject and its associated sysfs state.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
SeongJae Park
maintainerRe: [RFC PATCH v1.2 11/11] mm/damon/sysfs-schemes: kobject_del() region for populate_region error
Quoted 45 lines · On Thu, 18 Jun 2026 15:38:37 +0000 [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Memory leak in the error path ofdamon_sysfs_scheme_add_dirs()due to skipped cleanup of the 'stats' kobject. --commit
73251d9a8366deae80fbc88ff7d3d42f79676704
Author: SeongJae Park <[email protected]>
mm/damon/sysfs-schemes:kobject_del()region forpopulate_regionerrorThis patch fixes directory creation failures due to name conflicts when
CONFIG_DEBUG_KOBJECT_RELEASEis enabled. It adds a missingkobject_del()call to properly clean up tried region directories in the error path ofdamos_sysfs_populate_region_dir().mm/damon/sysfs-schemes.c
Quoted 4 lines
mm/damon/sysfs-schemes.c +0
-0[ ... ]
[Severity: High]
This isn't a bug introduced by this patch, but while reviewing the kobject cleanup in this file, I noticed a memory leak in the error path ofdamon_sysfs_scheme_add_dirs():mm/damon/sysfs-schemes.c:damon_sysfs_scheme_add_dirs() { ... err = damon_sysfs_scheme_set_stats(scheme); if (err) goto put_filters_watermarks_quotas_access_pattern_out; err = damon_sysfs_scheme_set_tried_regions(scheme); if (err) goto put_tried_regions_out; return 0;
put_tried_regions_out:kobject_put(&scheme->tried_regions->kobj); scheme->tried_regions = NULL; put_filters_watermarks_quotas_access_pattern_out: kobject_put(&scheme->ops_filters->kobj); ... }
Quoted 8 lines
If
damon_sysfs_scheme_set_tried_regions()fails, it jumps toput_tried_regions_out. This attempts to clean up the failedtried_regionsallocation, but then falls through to the next label.Does this completely skip cleaning up the successfully allocated
scheme->stats->kobj? Missing a call tokobject_put(&scheme->stats->kobj)here appears to permanently leak the stats kobject and its associated sysfs state.
Yes. And I was separately working on this. The patch is now added [1] to mm-hotfixes-unstable.
[1] https://lore.kernel.org/[email protected]
Thanks,
SJ
[...]
SeongJae Park
maintainerOn Thu, 18 Jun 2026 08:15:04 -0700 SeongJae Park <[email protected]> wrote:
[...]
Quoted 8 lines
This doesn't cause catastrophic issues like kernel panics or memory corruptions. Users can work around by removing all directories first (write 0 to the nr_* files) and then create new directories after confirming the old directories are gone. But, this is definitely a bug that causes a bad user experience.
Fix the issues by calling
kobject_del()before creating new directories.
Sashiko found no real issue from this patch, or pre-existing ones that better to be fixed together with this series. I will drop RFC tag in the next revision.
I consider this series as hotfixes, and therefore Cc-ed stable@. But, because the impact is minor, I will post the next revision after I believe all MM pull requests for this merge windoow are completed.
Thanks,
SJ