From: Hui Zhu calculate_high_delay() squares max_overage and scales it by HZ in u64. max_overage is the ratio ((usage - high) << 20) / high, and memory.high has no lower bound, so the product wraps once a cgroup is about 130x over its limit (at HZ=1000). The wrapped value is arbitrary and can be exactly zero: with memory.high set to one page and usage at 2049 pages, max_overage is 2^31, the product wraps to zero and the penalty comes out 0 jiffies instead of the 2 seconds the formula calls for. The caller then takes its "penalty_jiffies <= HZ / 100" exit, skipping both the throttle and the reclaim retry loop. Use check_mul_overflow() for the two multiplications and return MEMCG_MAX_HIGH_DELAY_JIFFIES when either of them wraps. An overflow means the exact product is at least 2^64, so the delay is past its cap even when nr_pages is a single page, and the caller clamps to the same value anyway. Song Hu reported this and proposed check_mul_overflow(). Zhang Jiao posted an earlier fix using an overage cap; per Johannes Weiner's review this version uses check_mul_overflow() instead. Fixes: 0e4b01df8659 ("mm, memcg: throttle allocators when failing reclaim over memory.high") Link: https://lore.kernel.org/all/20260818012115.65838-1-husong@kylinos.cn/ Link: https://lore.kernel.org/all/20261029073857.974-1-zhangjiao2@cmss.chinamobile.com/ Cc: stable@vger.kernel.org Co-developed-by: Song Hu Signed-off-by: Song Hu Signed-off-by: Hui Zhu --- mm/memcontrol.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 2625107a1096..85b6654e254f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2589,7 +2589,11 @@ static u64 calculate_high_delay(unsigned int nr_pages, * its crazy behaviour, so we exponentially increase the delay based on * overage amount. */ - penalty_jiffies = max_overage * max_overage * HZ; + /* An overflow puts the delay far past the cap the caller applies. */ + if (check_mul_overflow(max_overage, max_overage, &penalty_jiffies) || + check_mul_overflow(penalty_jiffies, (u64)HZ, &penalty_jiffies)) + return MEMCG_MAX_HIGH_DELAY_JIFFIES; + penalty_jiffies >>= MEMCG_DELAY_PRECISION_SHIFT; penalty_jiffies >>= MEMCG_DELAY_SCALING_SHIFT; -- 2.53.0