All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "SJ Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH 1/8] mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once
Date: Sat, 12 Sep 2026 19:37:16 +0000	[thread overview]
Message-ID: <20260912193716.99EE41F0089A@smtp.kernel.org> (raw)
In-Reply-To: <20260912191807.138502-2-sj@kernel.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] A double-read of `sysfs_goal->metric` in `damos_sysfs_add_quota_score()` causes uninitialized memory use in the core DAMOS quota auto-tuning logic.
--

commit 4b90a6724a684c24da0cc60a260ec280b6d479ac
Author: SJ Park <sj@kernel.org>
Subject: mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once

This commit fixes a potential race in the DAMON sysfs interface where
sysfs_filter->addr_range is read twice. By copying the address range first
and validating the copy, it prevents invalid configurations from reaching
the core layer.

> diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> index 3de4d804e049f..3c1c1cb387fec 100644
> --- a/mm/damon/sysfs-schemes.c
> +++ b/mm/damon/sysfs-schemes.c
> @@ -2831,12 +2831,12 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme,
>  				return err;
>  			}
>  		} else if (filter->type == DAMOS_FILTER_TYPE_ADDR) {
> -			if (sysfs_filter->addr_range.end <
> -					sysfs_filter->addr_range.start) {
> +			filter->addr_range = sysfs_filter->addr_range;
> +			if (filter->addr_range.end <
> +					filter->addr_range.start) {
>  				damos_destroy_filter(filter);
>  				return -EINVAL;
>  			}
> -			filter->addr_range = sysfs_filter->addr_range;
>  		} else if (filter->type == DAMOS_FILTER_TYPE_TARGET) {
>  			filter->target_idx = sysfs_filter->target_idx;
>  		} else if (filter->type == DAMOS_FILTER_TYPE_HUGEPAGE_SIZE) {

[ ... ]

While reviewing this fix for the double-read of addr_range, I noticed a
similar pattern in the same file:

mm/damon/sysfs-schemes.c:damos_sysfs_add_quota_score() {
    ...
		goal = damos_new_quota_goal(sysfs_goal->metric,
				sysfs_goal->target_value);
		if (!goal)
			return -ENOMEM;
		switch (sysfs_goal->metric) {
		case DAMOS_QUOTA_USER_INPUT:
			goal->current_value = sysfs_goal->current_value;
			break;
    ...
}

[Severity: High]
This is a pre-existing issue, but does this code double-read
sysfs_goal->metric?

The sysfs_goal->metric value is read first to allocate and initialize
goal->metric via damos_new_quota_goal(), and then read a second time
in the switch statement.

If the metric changes concurrently from DAMOS_QUOTA_USER_INPUT to another
value between these two reads, could the switch statement branch away and
skip the initialization of goal->current_value?

Since kmalloc does not zero memory, wouldn't goal->current_value be left
uninitialized, causing the core auto-tuning logic to read garbage data?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260912191807.138502-1-sj@kernel.org?part=1

  reply	other threads:[~2026-09-12 19:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-12 19:17 [RFC PATCH 0/8] mm/damon: move damos filter range arguments validation to core SJ Park
2026-09-12 19:17 ` [RFC PATCH 1/8] mm/damon/sysfs-schemes: read sysfs_filter->addr_range only once SJ Park
2026-09-12 19:37   ` sashiko-bot [this message]
2026-09-12 19:18 ` [RFC PATCH 2/8] mm/damon/sysfs-schemes: read sysfs_filter->sz_range " SJ Park
2026-09-12 19:26   ` sashiko-bot
2026-09-12 19:18 ` [RFC PATCH 3/8] mm/damon/core: return an error from damos_commit_filter_arg() SJ Park
2026-09-12 19:29   ` sashiko-bot
2026-09-12 19:37     ` SJ Park
2026-09-12 19:18 ` [RFC PATCH 4/8] mm/damon/core: disallow max < min damos filter range arguments commit SJ Park
2026-09-12 19:29   ` sashiko-bot
2026-09-12 19:42     ` SJ Park
2026-09-12 19:18 ` [RFC PATCH 5/8] mm/damon/sysfs-schemes: drop centralized filter range arg validations SJ Park
2026-09-12 19:30   ` sashiko-bot
2026-09-12 19:43     ` SJ Park
2026-09-12 19:18 ` [RFC PATCH 6/8] mm/damon/sysfs-schemes: use switch-case in add_scheme_filters() SJ Park
2026-09-12 19:23   ` sashiko-bot
2026-09-12 19:18 ` [RFC PATCH 7/8] mm/damon/core-kunit: extend damos_commit_filter_for() for wrong input SJ Park
2026-09-12 19:28   ` sashiko-bot
2026-09-12 19:18 ` [RFC PATCH 8/8] mm/damon/core-kunit: test invalid damos filter commits SJ Park
2026-09-12 19:36   ` sashiko-bot
2026-09-12 19:47     ` SJ 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=20260912193716.99EE41F0089A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sj@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 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.