From 61f63f47b38b4724078f04f2c81e135df54f28d6 Mon Sep 17 00:00:00 2001 From: Gleb Smirnoff Date: Fri, 15 Jun 2018 21:36:16 +0000 Subject: [PATCH] Since 'ticks' is an int, it may wrap around and cr_ticks at a certain counter_rate will be greater than ticks, resulting in counter_ratecheck() failure. To fix this take an absolute value of the difference between ticks and cr_ticks. Reported by: jtl Sponsored by: Netflix --- sys/kern/subr_counter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sys/kern/subr_counter.c b/sys/kern/subr_counter.c index 340f27d9b16a..300e67ea51ef 100644 --- a/sys/kern/subr_counter.c +++ b/sys/kern/subr_counter.c @@ -140,7 +140,7 @@ counter_ratecheck(struct counter_rate *cr, int64_t limit) val = cr->cr_over; now = ticks; - if (now - cr->cr_ticks >= hz) { + if (abs(now - cr->cr_ticks) >= hz) { /* * Time to clear the structure, we are in the next second. * First try unlocked read, and then proceed with atomic. @@ -151,7 +151,7 @@ counter_ratecheck(struct counter_rate *cr, int64_t limit) * Check if other thread has just went through the * reset sequence before us. */ - if (now - cr->cr_ticks >= hz) { + if (abs(now - cr->cr_ticks) >= hz) { val = counter_u64_fetch(cr->cr_rate); counter_u64_zero(cr->cr_rate); cr->cr_over = 0;