DAMON development mailing list
 help / color / mirror / Atom feed
From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.2] mm/damon/core: validate ranges in damon_set_regions()
Date: Sun, 28 Jun 2026 10:45:23 -0700	[thread overview]
Message-ID: <20260628174524.88480-1-sj@kernel.org> (raw)
In-Reply-To: <20260628170922.597F81F000E9@smtp.kernel.org>

On Sun, 28 Jun 2026 17:09:21 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] Flawed Validation Logic for Empty and Inverted Regions
> --
> 
> commit 663c371bd35c3a6e3044a1a0a7c4a31852e3924f
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/core: validate ranges in damon_set_regions()
> 
> This commit adds validation logic to damon_set_regions() to ensure that 
> empty monitoring target regions are rejected. This prevents division-by-zero 
> errors and sanity check warnings within the DAMON core logic.
> 
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> > @@ -358,6 +358,12 @@ int damon_set_regions(struct damon_target *t, struct damon_addr_range *ranges,
> >  	unsigned int i;
> >  	int err;
> >  
> > +	for (i = 0; i < nr_ranges; i++) {
> > +		if (ALIGN_DOWN(ranges[i].start, min_region_sz) >> +				ALIGN(ranges[i].end, min_region_sz))
> > +			return -EINVAL;
> > +	}
> > +
> 
> [Severity: Medium]
> Does this validation logic correctly reject unaligned empty or inverted
> ranges?
> 
> It looks like the alignment macros are applied before evaluating the bounds.
> If a caller provides an unaligned empty range like [4097, 4097], ALIGN_DOWN 
> makes the start 4096, and ALIGN makes the end 8192. This evaluates to 
> 4096 >= 8192, which is false, allowing the empty range to bypass the check 
> and silently expand into a valid monitoring region.
> 
> Conversely, a page-aligned empty range like [4096, 4096] evaluates as 
> 4096 >= 4096 and is correctly rejected. Similarly, an inverted range like 
> [4000, 3000] would align to [0, 4096) and be accepted.
> 
> Should the raw input bounds (ranges[i].start >= ranges[i].end) be validated
> prior to applying the alignment macros?

Sashiko's behavior expectation is correct.  And that could be not really good
user experience.  But I think that's what we could improve in future unless it
introduces too much complexity, rather than somewhat need to be implemented
right now blocking this fix.

So, no blocker.  I will consider improving the user experience as a future
work.


Thanks,
SJ

[...]

      reply	other threads:[~2026-06-28 17:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-28 16:54 [RFC PATCH v1.2] mm/damon/core: validate ranges in damon_set_regions() SJ Park
2026-06-28 17:09 ` sashiko-bot
2026-06-28 17:45   ` SJ 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=20260628174524.88480-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