DAMON development mailing list
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: SeongJae Park <sj@kernel.org>
Cc: sashiko-bot@kernel.org, damon@lists.linux.dev
Subject: Re: [RFC PATCH v2.1] mm/damon/sysfs-schemes: delete tried region in regions_rmdirs()
Date: Mon, 15 Jun 2026 22:45:04 -0700	[thread overview]
Message-ID: <20260616054505.156611-1-sj@kernel.org> (raw)
In-Reply-To: <20260517205828.6204-1-sj@kernel.org>

On Sun, 17 May 2026 13:58:26 -0700 SeongJae Park <sj@kernel.org> wrote:

> On Sun, 17 May 2026 18:27:49 +0000 sashiko-bot@kernel.org wrote:
> 
> > Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> > - [High] Moving the `sz_filter_passed` assignment to after `kobject_init_and_add()` exposes uninitialized kernel heap memory to user space.
> > - [High] Relying solely on `kobject_put()` to remove directories from sysfs leaves directories visible if references are held.
> > --
> > 
> > commit eda0f7269f695739057cee7bd02d81742d566163
> > Author: SeongJae Park <sj@kernel.org>
> > 
> > mm/damon/sysfs-schemes: delete tried region in regions_rmdirs()
> > 
> > This commit updates DAMON sysfs to remove region objects from the linked list
> > immediately before decrementing the kobject reference count to prevent
> > use-after-free races. It also modifies region population to only add the
> > region to the list after a successful kobject initialization.
> > 
> > Link: https://lore.kernel.org/20260513011920.119183-1-sj@kernel.org
> > 
> > > diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> > > --- a/mm/damon/sysfs-schemes.c
> > > +++ b/mm/damon/sysfs-schemes.c
> > > @@ -163,7 +163,7 @@ static void damon_sysfs_scheme_regions_rm_dirs(
> > >  	struct damon_sysfs_scheme_region *r, *next;
> > >  
> > >  	list_for_each_entry_safe(r, next, &regions->regions_list, list) {
> > > -		/* release function deletes it from the list */
> > > +		list_del(&r->list);
> > >  		kobject_put(&r->kobj);
> > 
> > This is not a new regression, but does relying solely on kobject_put() to
> > remove directories from sysfs leave them visible if references are still
> > held?
> > 
> > If an elevated reference count exists, such as a process having an open file
> > descriptor to a sysfs attribute, the kobject is not immediately released and
> > kobject_del() is delayed.
> > 
> > Could this leave the old region directory accessible in sysfs indefinitely,
> > causing stale directories to accumulate alongside new ones? Should
> > kobject_del(&r->kobj) be called explicitly before kobject_put() to cleanly
> > and synchronously remove the directory?

Because opening sysfs file doesn't increase the reference count of the kobject,
and DAMON sysfs files are managed by only DAMON, elevated reference count issue
cannot happen.  Nonetheless, on CONFIG_DEBUG_KOBJECT_RELEASE enabled kernels,
the kboject deletion is delayed.  As a result, new directory creation can fail
due to name conflicts.

No catastrophic issues like memory corruption can happen, but the user
experience will be arguably bad.

> 
> Makes sense, I will work on this.  Not a blocker of this patch, as Sashiko also
> mentioned, though.

Hence I'm keep working on this issue.  Just wanted to clarify the expected real
user impacts.


Thanks,
SJ

[...]

      reply	other threads:[~2026-06-16  5:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-17 17:59 [RFC PATCH v2.1] mm/damon/sysfs-schemes: delete tried region in regions_rmdirs() SeongJae Park
2026-05-17 18:27 ` sashiko-bot
2026-05-17 20:58   ` SeongJae Park
2026-06-16  5:45     ` SeongJae Park [this message]

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=20260616054505.156611-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