[RFC PATCH v1.2 09/19] mm/damon/core: disallow probe_hits overflow on attrs only monitoring
From: SJ Park
Date: Thu Jul 09 2026 - 10:25:14 EST
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.
Signed-off-by: SJ Park <sj@xxxxxxxxxx>
---
mm/damon/core.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/mm/damon/core.c b/mm/damon/core.c
index 7d49420ea26c4..4f1425e56950b 100644
--- a/mm/damon/core.c
+++ b/mm/damon/core.c
@@ -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;
--
2.47.3