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 v1.2] mm/damon/core: validate ranges in damon_set_regions()
Date: Sun, 28 Jun 2026 17:09:21 +0000	[thread overview]
Message-ID: <20260628170922.597F81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260628165447.86217-1-sj@kernel.org>

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 AI review · https://sashiko.dev/#/patchset/20260628165447.86217-1-sj@kernel.org?part=1

  reply	other threads:[~2026-06-28 17:09 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 [this message]
2026-06-28 17:45   ` 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=20260628170922.597F81F000E9@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.