Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Brendan Higgins" <brendan.higgins@linux.dev>,
	"David Gow" <davidgow@davidgow.net>,
	"Usama Arif" <usamaarif642@gmail.com>,
	damon@lists.linux.dev, linux-mm@kvack.org
Subject: Re: [PATCH 6.18.y 3/5] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
Date: Sun,  8 Nov 2026 11:49:33 -0800	[thread overview]
Message-ID: <20261108194935.115238-1-sj@kernel.org> (raw)
In-Reply-To: <sashiko-outbox-203953@kernel.org>

On Sun, 08 Nov 2026 19:30:36 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found no new issues
> in this patch, but noticed 1 related pre-existing issue it does not
> introduce:
> - [High] mm/damon/sysfs: TOCTOU race in damos_sysfs_add_quota_score()
>   [1]
> --
> 
> commit 244e62bfada7cc56b0025da40ea03dad6d9c6420
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once
> 
> This commit copies sysfs_filter->sz_range into filter->sz_range before
> validating it in damon_sysfs_add_scheme_filters() so that a concurrent
> sysfs update cannot pass an unvalidated size range to the core layer.
> 
> Link: https://lore.kernel.org/20260914142327.92510-3-sj@kernel.org
> 
> > diff --git a/mm/damon/sysfs-schemes.c b/mm/damon/sysfs-schemes.c
> > index 37e0a8bef4b1f..0f945ef043709 100644
> > --- a/mm/damon/sysfs-schemes.c
> > +++ b/mm/damon/sysfs-schemes.c
> > @@ -2493,12 +2493,11 @@ static int damon_sysfs_add_scheme_filters(struct damos *scheme,
> >  		} else if (filter->type == DAMOS_FILTER_TYPE_TARGET) {
> >  			filter->target_idx = sysfs_filter->target_idx;
> >  		} else if (filter->type == DAMOS_FILTER_TYPE_HUGEPAGE_SIZE) {
> > -			if (sysfs_filter->sz_range.min >
> > -					sysfs_filter->sz_range.max) {
> > +			filter->sz_range = sysfs_filter->sz_range;
> > +			if (filter->sz_range.min > filter->sz_range.max) {
> >  				damos_destroy_filter(filter);
> >  				return -EINVAL;
> >  			}
> > -			filter->sz_range = sysfs_filter->sz_range;
> >  		}
> >  
> >  		damos_add_filter(scheme, filter);
> 
> [Severity: High]
> This problem wasn't introduced by this patch, but can
> damos_sysfs_add_quota_score() just below hit a similar double-read race on
> sysfs_goal->target_value [1]?
> 
> mm/damon/sysfs-schemes.c:damos_sysfs_add_quota_score() {
> 	...
> 		if (!sysfs_goal->target_value)
> 			continue;
> 
> 		goal = damos_new_quota_goal(sysfs_goal->metric,
> 				sysfs_goal->target_value);
> 	...
> }
> 
> target_value_store() updates sysfs_goal->target_value without holding
> damon_sysfs_lock:
> 
> CPU0                              CPU1
> damos_sysfs_add_quota_score()
>   if (!sysfs_goal->target_value)
>                                   target_value_store()
>                                     kstrtoul(..., &goal->target_value)
>   damos_new_quota_goal(...,
>       sysfs_goal->target_value)
>   ...
> damos_quota_score()
>   mult_frac(...,
>       goal->target_value)  <-- divide-by-zero
> 
> If a concurrent write sets sysfs_goal->target_value to 0 between the check
> and the second read, damos_new_quota_goal() creates a goal with a zero
> target_value, which later causes a divide-by-zero in damos_quota_score().
> sysfs_goal->metric is also read twice in damos_sysfs_add_quota_score(), so
> a concurrent metric_store() between damos_new_quota_goal() and the switch
> can leave goal->nid or goal->current_value uninitialized.

No.  damon_sysfs_valid_start_ctx() [1] avoids the divide-by-zero.

[1] https://lore.kernel.org/all/20260903010722.94244-2-sj@kernel.org/

> 
> [1] https://sashiko.dev/#/bug/linux-7f814c9a-986f-4103-a55a-ef9537dcf62b
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20261108192221.114362-1-sj@kernel.org?part=3
> 


Thanks,
SJ


  reply	other threads:[~2026-11-08 19:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-08 19:22 [PATCH 6.18.y 0/5] mm/damon: porting fixes that cherry-pick failed on 2026-11-07 SJ Park
2026-11-08 19:22 ` [PATCH 6.18.y 1/5] mm/damon/core: skip applying scheme if region split for quota fails SJ Park
2026-11-08 19:35   ` sashiko-bot
2026-11-08 19:46     ` SJ Park
2026-11-08 19:22 ` [PATCH 6.18.y 2/5] mm/damon/core: handle uninitialized damos_quota_goal->last_psi_total SJ Park
2026-11-08 19:22 ` [PATCH 6.18.y 3/5] mm/damon/sysfs-schemes: read sysfs_filter->sz_range only once SJ Park
2026-11-08 19:30   ` sashiko-bot
2026-11-08 19:49     ` SJ Park [this message]
2026-11-09 15:53   ` Sasha Levin
2026-11-08 19:22 ` [PATCH 6.18.y 4/5] mm/damon/core: remove unreachable damos charge_{target,addr}_from SJ Park
2026-11-08 19:22 ` [PATCH 6.18.y 5/5] mm/damon/core: filter out damos address filter-split failed region 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=20261108194935.115238-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=brendan.higgins@linux.dev \
    --cc=damon@lists.linux.dev \
    --cc=davidgow@davidgow.net \
    --cc=linux-mm@kvack.org \
    --cc=sashiko-bot@kernel.org \
    --cc=usamaarif642@gmail.com \
    /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