DAMON_MIN_REGION_SZ / addr_unit is used as min_region_sz, which is passed to ALIGN() and ALIGN_DOWN() in core.c. These macros require power-of-2 alignment. When addr_unit is not a power of 2 (e.g., 3), the division produces a non-power-of-2 min_region_sz, causing silent undefined behavior in ALIGN before damon_commit_ctx() gets a chance to reject it. Validate that addr_unit is a power of 2 in the store function so the user gets immediate -EINVAL feedback instead of a silent failure. Signed-off-by: Josh Law --- mm/damon/reclaim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 43d76f5bed44..9b55df304e51 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -321,7 +321,7 @@ static int damon_reclaim_addr_unit_store(const char *val, if (err) return err; - if (!input_addr_unit) + if (!input_addr_unit || !is_power_of_2(input_addr_unit)) return -EINVAL; addr_unit = input_addr_unit; -- 2.34.1 min_age / aggr_interval can exceed UINT_MAX with extreme but valid module parameter values, silently truncating min_age_region and lowering the cold-page age threshold below what the user intended. Clamp the result to UINT_MAX to match the field's type. Signed-off-by: Josh Law --- mm/damon/reclaim.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/damon/reclaim.c b/mm/damon/reclaim.c index 9b55df304e51..303c64a56073 100644 --- a/mm/damon/reclaim.c +++ b/mm/damon/reclaim.c @@ -170,8 +170,8 @@ static struct damos *damon_reclaim_new_scheme(void) .min_nr_accesses = 0, .max_nr_accesses = 0, /* for min_age or more micro-seconds */ - .min_age_region = min_age / - damon_reclaim_mon_attrs.aggr_interval, + .min_age_region = min_t(unsigned long, min_age / + damon_reclaim_mon_attrs.aggr_interval, UINT_MAX), .max_age_region = UINT_MAX, }; -- 2.34.1