From: SJ Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SJ Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [PATCH v3] samples/damon/mtier: fail early if address range parameters are invalid
Date: Mon, 29 Jun 2026 17:27:18 -0700 [thread overview]
Message-ID: <20260630002719.141332-1-sj@kernel.org> (raw)
In-Reply-To: <20260629150116.1C6EE1F000E9@smtp.kernel.org>
On Mon, 29 Jun 2026 15:01:15 +0000 sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
>
> Pre-existing issues:
> - [High] The sysfs interface allows creating zero-sized regions, leading to a division by zero kernel panic in `damon_merge_two_regions()` when merging adjacent zero-sized regions.
> --
>
> commit 049fc008d25fe73be336de6b00bf5512c8f6ec71
> Author: Zenghui Yu <yuzenghui@huawei.com>
>
> samples/damon/mtier: fail early if address range parameters are invalid
>
> This commit fixes an issue where invalid node address ranges could trigger a
> WARN_ONCE. It prevents zero-sized or negatively-sized regions by adding an
> early failure check if the start address is greater than or equal to the end
> address.
>
> > diff --git a/samples/damon/mtier.c b/samples/damon/mtier.c
> > index faaaaa12e6206..e567f4edd80ea 100644
> > --- a/samples/damon/mtier.c
> > +++ b/samples/damon/mtier.c
> [ ... ]
> > @@ -120,6 +120,9 @@ static struct damon_ctx *damon_sample_mtier_build_ctx(bool promote)
> > addr.end = promote ? node1_end_addr : node0_end_addr;
> > }
> >
> > + if (addr.start >= addr.end)
> > + goto free_out;
> > +
>
> [Severity: High]
> This is a pre-existing issue,
So no blocker of this patch.
> but while you are fixing zero-sized regions
> here, does the DAMON sysfs interface have a similar vulnerability that can
> cause a kernel panic?
>
> Looking at damon_sysfs_set_regions() in mm/damon/sysfs.c, the bounds check
> only uses strictly greater than instead of greater than or equal to:
>
> if (sys_region->ar.start > sys_region->ar.end)
> goto out;
>
> If a user configures two identical zero-sized regions via sysfs (e.g.,
> start@96 and end@96), this check passes. Furthermore, the overlap
> check allows consecutive identical zero-sized regions because exact boundary
> matches evaluate to false.
>
> When DAMON executes damon_merge_regions_of(), it identifies these as
> perfectly adjacent and attempts to merge them in damon_merge_two_regions():
>
> mm/damon/core.c:damon_merge_two_regions() {
> ...
> l->nr_accesses = (l->nr_accesses * sz_l + r->nr_accesses * sz_r) /
> (sz_l + sz_r);
> ...
> }
>
> Since both regions are zero-sized, sz_l + sz_r evaluates to 0, which would
> cause a division by zero kernel panic. Should the sysfs interface also be
> updated to use >= to prevent this?
Correct. And we are working [1] on the fix.
[1] https://lore.kernel.org/20260628165447.86217-1-sj@kernel.org
Thanks,
SJ
[...]
prev parent reply other threads:[~2026-06-30 0:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-29 14:44 [PATCH v3] samples/damon/mtier: fail early if address range parameters are invalid SJ Park
2026-06-29 15:01 ` sashiko-bot
2026-06-30 0:27 ` 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=20260630002719.141332-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