All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Junxi Qian" <qjx1298677004@gmail.com>
Cc: damon@lists.linux.dev
Subject: Re: [PATCH] mm/damon/sysfs-schemes: fix use-after-free on memcg_path and goal path
Date: Mon, 20 Apr 2026 11:53:04 +0000	[thread overview]
Message-ID: <20260420115304.D21A4C19425@smtp.kernel.org> (raw)
In-Reply-To: <20260420085332.178473-1-qjx1298677004@gmail.com>

Sashiko AI review found 1 potential issue(s):
- [High] The sysfs show functions `memcg_path_show()` and `path_show()` read string pointers without holding `damon_sysfs_lock`, leaving a Use-After-Free vulnerability.
--

commit a381c30634b7e486fce5448c7aae9e23da7aecf9
Author: Junxi Qian <qjx1298677004@gmail.com>

mm/damon/sysfs-schemes: fix use-after-free on memcg_path and goal path

This commit fixes a use-after-free race between the kdamond thread and
sysfs store operations. It does this by acquiring damon_sysfs_lock while
swapping the memcg_path and path string pointers, and freeing the old
pointers outside the lock.

> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> index 5186966dafb35..005cfecb11c5d 100644
> --- a/mm/damon/sysfs-schemes.c
> +++ b/mm/damon/sysfs-schemes.c
[ ... ]
> @@ -543,15 +543,20 @@ static ssize_t memcg_path_store(struct kobject *kobj,
[ ... ]
>  	strscpy(path, buf, count + 1);
> -	kfree(filter->memcg_path);
> +
> +	mutex_lock(&damon_sysfs_lock);
> +	old = filter->memcg_path;
>  	filter->memcg_path = path;
> +	mutex_unlock(&damon_sysfs_lock);
> +
> +	kfree(old);

Could this explicit free race with the lockless read in memcg_path_show()?

The VFS and sysfs core layers do not serialize concurrent show and store
operations for the same attribute. If one thread calls memcg_path_show(),
it evaluates the pointer without holding damon_sysfs_lock:

static ssize_t memcg_path_show(...)
{
        ...
        return sysfs_emit(buf, "%s\n",
                          filter->memcg_path ? filter->memcg_path : "");
}

Can a concurrent store operation swap the pointer and kfree() the old one
just before sysfs_emit() dereferences it? Does memcg_path_show() also need
to acquire damon_sysfs_lock?

[ ... ]
> @@ -1196,15 +1201,20 @@ static ssize_t path_store(struct kobject *kobj,
[ ... ]
>  	strscpy(path, buf, count + 1);
> -	kfree(goal->path);
> +
> +	mutex_lock(&damon_sysfs_lock);
> +	old = goal->path;
>  	goal->path = path;
> +	mutex_unlock(&damon_sysfs_lock);
> +
> +	kfree(old);

Similarly, does path_show() have the same vulnerability?

static ssize_t path_show(...)
{
        ...
        return sysfs_emit(buf, "%s\n", goal->path ? goal->path : "");
}

Since goal->path is accessed locklessly here, can a concurrent path_store()
free the string right before path_show() reads it?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260420085332.178473-1-qjx1298677004@gmail.com?part=1

  reply	other threads:[~2026-04-20 11:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-20  8:53 [PATCH] mm/damon/sysfs-schemes: fix use-after-free on memcg_path and goal path Junxi Qian
2026-04-20 11:53 ` sashiko-bot [this message]
2026-04-20 12:54 ` [PATCH v2] " Junxi Qian
2026-04-20 18:31   ` sashiko-bot
2026-04-21  1:20   ` SeongJae Park
2026-04-21  1:23     ` SeongJae Park
2026-04-21 15:01     ` SeongJae Park
2026-04-21  7:06 ` [PATCH] " Junxi Qian
2026-04-21 23:47   ` SeongJae Park
2026-04-22  4:31     ` junxi qian
2026-04-22  4:35       ` 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=20260420115304.D21A4C19425@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=qjx1298677004@gmail.com \
    --cc=sashiko@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.