All of 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>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.3 6/7] mm/damon/core: update probe hits for new parameter commit
Date: Tue,  7 Jul 2026 20:56:04 -0700	[thread overview]
Message-ID: <20260708035606.118344-1-sj@kernel.org> (raw)
In-Reply-To: <20260708030544.6EBC61F000E9@smtp.kernel.org>

On Wed, 08 Jul 2026 03:05:43 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
> - [High] Unbounded iteration over `ctx->probes` list writing to the statically sized `probe_hits` array can lead to buffer overflow.
> - [Medium] Scaling `probe_hits` and `last_probe_hits` using `damon_nr_samples_for_new_attrs()` assigns an `unsigned int` to an `unsigned char`, causing silent truncation and data corruption when the scaled count exceeds 255.
> --
> 
> --- Patch [6]: [RFC PATCH v1.3 6/7] mm/damon/core: update probe hits for new parameter commit ---
> commit 5d7c7277de18e07d88cf49d1f16d870a9dfc0f23
> Author: SJ Park <sj@kernel.org>
> 
> mm/damon/core: update probe hits for new parameter commit
> 
> Users can update DAMON parameters at runtime.  If the samples and/or
> aggregation intervals are updated in this way, monitoring results
> depending on the intervals should also be updated for a more accurate
> snapshot.  The age and nr_accesses are properly updated, while
> probe_hits are not updated in the way.  Do the update.
> 
> > diff --git a/mm/damon/core.c b/mm/damon/core.c
> > index 800ff6b6d2473..15d31285515d6 100644
> > --- a/mm/damon/core.c
> > +++ b/mm/damon/core.c
> 
> [ ... ]
> 
> > @@ -897,10 +897,32 @@ static unsigned int damon_nr_samples_for_new_attrs(unsigned int nr,
> >  			damon_sample_count_to_bp(nr, old_attrs), new_attrs);
> >  }
> >  
> > +static void damon_update_probe_hits(struct damon_region *r,
> > +		struct damon_attrs *old_attrs, struct damon_attrs *new_attrs,
> > +		bool aggregating, struct damon_ctx *ctx)
> > +{
> > +	struct damon_probe *p;
> > +	int i = 0;
> > +
> > +	damon_for_each_probe(p, ctx) {
> 
> [Severity: High]
> Does this loop overflow the r->last_probe_hits[] and r->probe_hits[] arrays?
> 
> The probe_hits and last_probe_hits members are defined as fixed-size arrays of
> size DAMON_MAX_PROBES. Since there is no bounds checking on i, if there are
> more than DAMON_MAX_PROBES in the ctx->probes list, this will write past the
> end of the arrays and corrupt adjacent fields in struct damon_region.

That cannot happen since DAMON_SYSFS is not accepting that input.   Read
nr_probes_store() for more details.

> 
> > +		r->last_probe_hits[i] = damon_nr_samples_for_new_attrs(
> > +				r->last_probe_hits[i], old_attrs, new_attrs);
> 
> [Severity: Medium]
> Will this assignment cause silent truncation and data corruption?
> 
> The last_probe_hits and probe_hits arrays are declared as unsigned char
> (8-bit) in struct damon_region, but damon_nr_samples_for_new_attrs() returns an
> unsigned int (32-bit).
> 
> If the scaled count exceeds 255, assigning it directly will truncate the value
> to a meaningless modulo-256 wrapped value rather than clamping it at a maximum.

Known low priority issue.

> 
> > +		if (!aggregating)
> > +			r->probe_hits[i] = damon_nr_samples_for_new_attrs(
> > +					r->probe_hits[i], old_attrs,
> > +					new_attrs);
> > +		else
> > +			r->probe_hits[i] = 0;
> > +		i++;
> > +	}
> > +}
> > +
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/20260708024855.116614-1-sj@kernel.org?part=6


Thanks,
SJ

  reply	other threads:[~2026-07-08  3:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  2:48 [RFC PATCH v1.3 0/7] mm/damon: update probe hits for runtime parameter commits SJ Park
2026-07-08  2:48 ` [RFC PATCH v1.3 1/7] mm/damon/core: remove comment and test for nr_to_bp() divide-by-zero SJ Park
2026-07-08  2:48 ` [RFC PATCH v1.3 2/7] mm/damon/core: s/damon_max_nr_accesses()/damon_nr_samples_per_aggr()/ SJ Park
2026-07-08  2:58   ` sashiko-bot
2026-07-08  3:52     ` SJ Park
2026-07-08  2:48 ` [RFC PATCH v1.3 3/7] mm/damon/core: s/accesses_bp_to_nr_accesses/sample_bp_to_count/ SJ Park
2026-07-08  2:48 ` [RFC PATCH v1.3 4/7] mm/damon/core: s/nr_accesses_to_accesses_bp/sample_count_to_bp/ SJ Park
2026-07-08  2:48 ` [RFC PATCH v1.3 5/7] mm/damon/core: s/nr_accesses_for_new_attrs/nr_samples_for_new_attrs/ SJ Park
2026-07-08  3:01   ` sashiko-bot
2026-07-08  3:53     ` SJ Park
2026-07-08  2:48 ` [RFC PATCH v1.3 6/7] mm/damon/core: update probe hits for new parameter commit SJ Park
2026-07-08  3:05   ` sashiko-bot
2026-07-08  3:56     ` SJ Park [this message]
2026-07-08  2:48 ` [RFC PATCH v1.3 7/7] mm/damon/core: handle unreset probe_hits in probe_hits_mvsum() 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=20260708035606.118344-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 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.