From: sashiko-bot@kernel.org
To: "SeongJae Park" <sj@kernel.org>
Cc: damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.2 1/2] mm/damon/core: handle zero intervals in damon_max_nr_accesses()
Date: Mon, 22 Jun 2026 14:29:36 +0000 [thread overview]
Message-ID: <20260622142937.579571F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260622141027.29145-2-sj@kernel.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Integer underflow and state corruption in `nr_accesses_bp` calculation when `sample_interval == 0`.
- [High] 32-bit integer overflow in access rate scaling and hotness scoring silently breaks region statistics for long aggregation intervals.
--
commit 4e734fc35404d39d1209a202d1c72aa4e9ef543f
Author: SeongJae Park <sj@kernel.org>
mm/damon/core: handle zero intervals in damon_max_nr_accesses()
This commit addresses a divide-by-zero error in damon_max_nr_accesses()
by forcing a denominator of 1 when the sampling interval is zero. It also
ensures the function always returns at least 1.
Link: https://lore.kernel.org/20260619202459.145010-1-sj@kernel.org
> diff --git a/include/linux/damon.h b/include/linux/damon.h
> index 6f7edb3590ef9..888570f55b416 100644
> --- a/include/linux/damon.h
> +++ b/include/linux/damon.h
> @@ -1065,9 +1065,13 @@ static inline bool damon_target_has_pid(const struct damon_ctx *ctx)
>
> static inline unsigned int damon_max_nr_accesses(const struct damon_attrs *attrs)
> {
> - /* {aggr,sample}_interval are unsigned long, hence could overflow */
> - return min(attrs->aggr_interval / attrs->sample_interval,
> + unsigned long sample_interval;
> + unsigned long max_nr_accesses;
> +
> + sample_interval = attrs->sample_interval ? : 1;
> + max_nr_accesses = min(attrs->aggr_interval / sample_interval,
> (unsigned long)UINT_MAX);
> + return max_nr_accesses ? : 1;
> }
[Severity: High]
This isn't a bug introduced by this patch, but while this commit fixes the
zero interval handling inside damon_max_nr_accesses(), there is a bypass in
mm/damon/core.c that still relies on sample_interval:
mm/damon/core.c:damon_update_region_access_rate()
if (attrs->sample_interval)
len_window = damon_max_nr_accesses(attrs);
When sample_interval is 0, this bypass circumvents the properly fixed
damon_max_nr_accesses() function, locking len_window at 1. During the
next aggregation window, damon_moving_sum() recalculates the moving
average. Because len_window is stuck at 1, the entire nomvsum is
subtracted from a smaller mvsum.
Will this cause nr_accesses_bp to massively underflow its unsigned int
type and wrap around, corrupting the region's access metrics?
[Severity: High]
This is also a pre-existing issue, but does damon_update_monitoring_result()
suffer from a 32-bit integer overflow for long aggregation intervals?
When a long aggregation interval and short sample interval are configured,
the accesses can be quite large:
mm/damon/core.c:damon_update_monitoring_result()
r->nr_accesses_bp = r->nr_accesses * 10000;
If nr_accesses is very high, does this 32-bit unsigned int arithmetic
silently wrap around, heavily corrupting nr_accesses_bp?
A similar overflow appears in damon_hot_score():
mm/damon/ops-common.c:damon_hot_score()
freq_subscore = r->nr_accesses * DAMON_MAX_SUBSCORE /
damon_max_nr_accesses(&c->attrs);
Does the numerator multiplication overflow the 32-bit bounds before
the division, resulting in an artificially skewed, low hotness score?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260622141027.29145-1-sj@kernel.org?part=1
next prev parent reply other threads:[~2026-06-22 14:29 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 14:10 [RFC PATCH v1.2 0/2] mm/damon: handle zero {sample,aggr} intervals for DAMOS quota score SeongJae Park
2026-06-22 14:10 ` [RFC PATCH v1.2 1/2] mm/damon/core: handle zero intervals in damon_max_nr_accesses() SeongJae Park
2026-06-22 14:29 ` sashiko-bot [this message]
2026-06-22 14:36 ` SeongJae Park
2026-06-22 14:10 ` [RFC PATCH v1.2 2/2] mm/damon/ops-common: prevent >DAMON_MAX_SUBSCORE freq_subscore SeongJae Park
2026-06-22 14:24 ` sashiko-bot
2026-06-22 14:42 ` SeongJae Park
2026-06-22 14:53 ` SeongJae 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=20260622142937.579571F000E9@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox