From: Frederic Weisbecker Date: Fri, 17 Jul 2020 14:05:40 +0000 (+0200) Subject: timer: Fix wheel index calculation on last level X-Git-Tag: v4.14.189~14 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9d6cc0e9def4a27178dde54c13ad532910893eb6;p=users%2Fdwmw2%2Flinux.git timer: Fix wheel index calculation on last level commit e2a71bdea81690b6ef11f4368261ec6f5b6891aa upstream. When an expiration delta falls into the last level of the wheel, that delta has be compared against the maximum possible delay and reduced to fit in if necessary. However instead of comparing the delta against the maximum, the code compares the actual expiry against the maximum. Then instead of fixing the delta to fit in, it sets the maximum delta as the expiry value. This can result in various undesired outcomes, the worst possible one being a timer expiring 15 days ahead to fire immediately. Fixes: 500462a9de65 ("timers: Switch to a non-cascading wheel") Signed-off-by: Frederic Weisbecker Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org Link: https://lkml.kernel.org/r/20200717140551.29076-2-frederic@kernel.org Signed-off-by: Greg Kroah-Hartman --- diff --git a/kernel/time/timer.c b/kernel/time/timer.c index 9f8e8892e5b0d..7e88c87c35541 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -502,8 +502,8 @@ static int calc_wheel_index(unsigned long expires, unsigned long clk) * Force expire obscene large timeouts to expire at the * capacity limit of the wheel. */ - if (expires >= WHEEL_TIMEOUT_CUTOFF) - expires = WHEEL_TIMEOUT_MAX; + if (delta >= WHEEL_TIMEOUT_CUTOFF) + expires = clk + WHEEL_TIMEOUT_MAX; idx = calc_index(expires, LVL_DEPTH - 1); }