From: SeongJae Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH 2/9] mm/damon/sysfs: kobject_del() region dirs
Date: Tue, 16 Jun 2026 17:18:34 -0700 [thread overview]
Message-ID: <20260617001835.95809-1-sj@kernel.org> (raw)
In-Reply-To: <20260616152911.9CF261F00A3A@smtp.kernel.org>
On Tue, 16 Jun 2026 15:29:11 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] Missing explicit kobject_del() on error paths in _add_dirs loops (Incomplete Fix).
> - [High] Memory leak of stats and scheme structures on the error path of damon_sysfs_scheme_add_dirs().
> --
>
> commit ba4dfdbea398b3306e96fd3662e872e97251fbe9
> Author: SeongJae Park <sj@kernel.org>
>
> mm/damon/sysfs: kobject_del() region dirs
>
> This commit fixes directory creation failures caused by name conflicts
> when CONFIG_DEBUG_KOBJECT_RELEASE is enabled. It achieves this by adding
> missing kobject_del() calls to the region directories removal function.
>
> > diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c
> > index d93f7919c3ca1..f72e1e37df9d8 100644
> > --- a/mm/damon/sysfs.c
> > +++ b/mm/damon/sysfs.c
> > @@ -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;
>
> [Severity: High]
> This is a pre-existing issue, but the fix for this specific bug class seems
> incomplete as it misses initialization error paths. If a nested initialization
> fails after kobject_init_and_add() succeeds, the code jumps to an error path
> and calls kobject_put() without first calling kobject_del().
>
> For example, in mm/damon/sysfs.c:damon_sysfs_targets_add_dirs():
>
> out:
> damon_sysfs_targets_rm_dirs(targets);
> kobject_put(&target->kobj);
> return err;
>
> This same pattern occurs in damon_sysfs_contexts_add_dirs(),
> damon_sysfs_kdamonds_add_dirs(), damon_sysfs_probes_add_dirs(), and
> damon_sysfs_schemes_add_dirs().
>
> Does this cause the directory removal to be delayed asynchronously, meaning
> if userspace immediately retries the operation, it fails with an -EEXIST
> conflict?
Good findings, I will fix these in the next revisioin of this series.
>
> [Severity: High]
> This is also a pre-existing issue, but there appears to be a memory leak
> in the error path of damon_sysfs_scheme_add_dirs() in
> mm/damon/sysfs-schemes.c:
>
> 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, the code jumps to
> put_tried_regions_out and bypasses releasing the successfully created
> scheme->stats kobject. Since damon_sysfs_scheme_release() only frees the
> scheme struct and does not explicitly clean up lingering children, both the
> stats memory and the parent scheme memory are kept referenced.
>
> Could this permanently leak both the stats and its parent scheme when
> triggered from userspace via sysfs configuration?
This may deserve another fix. I will separtely work on this.
Thanks,
SJ
[...]
next prev parent reply other threads:[~2026-06-17 0:18 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-16 15:08 [RFC PATCH 0/9] mm/damon/sysfs: kobject_del() directories that users can create/remove SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 1/9] mm/damon/sysfs: kobject_del() target, context and kdamond dirs SeongJae Park
2026-06-16 15:25 ` sashiko-bot
2026-06-17 0:02 ` SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 2/9] mm/damon/sysfs: kobject_del() region dirs SeongJae Park
2026-06-16 15:29 ` sashiko-bot
2026-06-17 0:18 ` SeongJae Park [this message]
2026-06-16 15:08 ` [RFC PATCH 3/9] mm/damon/sysfs-schemes: kobject_del() scheme dirs SeongJae Park
2026-06-16 15:27 ` sashiko-bot
2026-06-17 0:52 ` SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 4/9] mm/damon/sysfs-schemes: kobject_del() scheme region dirs SeongJae Park
2026-06-16 15:25 ` sashiko-bot
2026-06-17 0:43 ` SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 5/9] mm/damon/sysfs-schemes: kobject_del() scheme filter dirs SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 6/9] mm/damon/sysfs-schemes: kobject_del() scheme quota goal dirs SeongJae Park
2026-06-16 15:27 ` sashiko-bot
2026-06-17 0:55 ` SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 7/9] mm/damon/sysfs-schemes: kobject_del() scheme action destination dirs SeongJae Park
2026-06-16 15:34 ` sashiko-bot
2026-06-17 1:07 ` SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 8/9] mm/damon/sysfs: kobject_del() probe filter dirs SeongJae Park
2026-06-16 15:27 ` sashiko-bot
2026-06-17 1:10 ` SeongJae Park
2026-06-16 15:08 ` [RFC PATCH 9/9] mm/damon/sysfs: kobject_del() probe dirs SeongJae Park
2026-06-16 15:24 ` sashiko-bot
2026-06-17 1:11 ` SeongJae Park
2026-06-17 1:15 ` [RFC PATCH 0/9] mm/damon/sysfs: kobject_del() directories that users can create/remove SeongJae Park
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260617001835.95809-1-sj@kernel.org \
--to=sj@kernel.org \
--cc=damon@lists.linux.dev \
--cc=sashiko-bot@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox