mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
mm/damon/core: disallow probe_hits overflow on attrs only monitoring
When any damon_probe->weight is set, DAMON will do only probe monitoring. probe_hits is 'unsigned char'. It could overflow when the aggregation interval is larger than the sampling interval times 256. damon_as_probe_weights() always return false, so such overflow cannot happen. Even if it happens, it only degrades the monitoring results. That said, the overflow is not intentional. It is better to be prevented as long as the cost is not expensive. Disallow the overflow by adding a validation logic on the core layer parameters validation function. Link: https://lore.kernel.org/20260710134651.18084-10-sj@kernel.org Signed-off-by: SJ Park <sj@kernel.org> Cc: David Hildenbrand <david@kernel.org> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Liam R. Howlett <liam@infradead.org> Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Michal Hocko <mhocko@suse.com> Cc: Mike Rapoport <rppt@kernel.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Vlastimil Babka <vbabka@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
0d1daaed8b
commit
93508425db
|
|
@ -1332,6 +1332,19 @@ static void damos_set_filters_default_reject(struct damos *s)
|
|||
damos_filters_default_reject(&s->ops_filters);
|
||||
}
|
||||
|
||||
static bool damon_valid_probe_params(struct damon_ctx *ctx)
|
||||
{
|
||||
unsigned long sample_interval;
|
||||
|
||||
if (!damon_has_probe_weights(ctx))
|
||||
return true;
|
||||
|
||||
sample_interval = ctx->attrs.sample_interval ? : 1;
|
||||
if (ctx->attrs.aggr_interval / sample_interval > U8_MAX)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* damos_commit_dests() - Copy migration destinations from @src to @dst.
|
||||
* @dst: Destination structure to update.
|
||||
|
|
@ -1736,6 +1749,9 @@ static int __damon_commit_ctx(struct damon_ctx *dst, struct damon_ctx *src)
|
|||
}
|
||||
}
|
||||
|
||||
if (!damon_valid_probe_params(src))
|
||||
return -EINVAL;
|
||||
|
||||
err = damon_commit_schemes(dst, src);
|
||||
if (err)
|
||||
return err;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user