diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-19 15:27:52 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-06-19 15:27:52 +0200 |
commit | 5d324c239c4f955261d4669afc85c46a94e8a58b (patch) | |
tree | 62c511481a1a38f7d9cc0e03ec48cc1bae4b7e2f | |
parent | 5d7bdaaf0bd7b5a28ad196109f5ec3cdb550bd02 (diff) |
ratelimiter: mitigate reference underflow
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/ratelimiter.c | 2 | ||||
-rw-r--r-- | src/selftest/ratelimiter.h | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/src/ratelimiter.c b/src/ratelimiter.c index 78096cc..2107c8e 100644 --- a/src/ratelimiter.c +++ b/src/ratelimiter.c @@ -183,7 +183,7 @@ err: void ratelimiter_uninit(void) { - if (atomic64_dec_return(&refcnt)) + if (atomic64_dec_if_positive(&refcnt)) return; cancel_delayed_work_sync(&gc_work); diff --git a/src/selftest/ratelimiter.h b/src/selftest/ratelimiter.h index 7e017ce..0bdff1e 100644 --- a/src/selftest/ratelimiter.h +++ b/src/selftest/ratelimiter.h @@ -146,6 +146,8 @@ err_nofree: ratelimiter_uninit(); ratelimiter_uninit(); ratelimiter_uninit(); + /* Uninit one extra time to check underflow detection. */ + ratelimiter_uninit(); out: if (ret) pr_info("ratelimiter self-tests: pass\n"); |