From: Eric W. Biederman Date: Thu, 10 Feb 2022 00:09:41 +0000 (-0600) Subject: ucounts: Handle wrapping in is_ucounts_overlimit X-Git-Tag: baikal/aarch64/sdk6.1~4633^2 X-Git-Url: https://git.baikalelectronics.ru/sdk/?a=commitdiff_plain;h=cf5343002b2640472bda574e13c5d5a45976e601;p=kernel.git ucounts: Handle wrapping in is_ucounts_overlimit While examining is_ucounts_overlimit and reading the various messages I realized that is_ucounts_overlimit fails to deal with counts that may have wrapped. Being wrapped should be a transitory state for counts and they should never be wrapped for long, but it can happen so handle it. Cc: stable@vger.kernel.org Fixes: 0575577973b8 ("Reimplement RLIMIT_NPROC on top of ucounts") Link: https://lkml.kernel.org/r/20220216155832.680775-5-ebiederm@xmission.com Reviewed-by: Shuah Khan Signed-off-by: "Eric W. Biederman" --- diff --git a/kernel/ucount.c b/kernel/ucount.c index 65b597431c861..06ea04d446852 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -350,7 +350,8 @@ bool is_ucounts_overlimit(struct ucounts *ucounts, enum ucount_type type, unsign if (rlimit > LONG_MAX) max = LONG_MAX; for (iter = ucounts; iter; iter = iter->ns->ucounts) { - if (get_ucounts_value(iter, type) > max) + long val = get_ucounts_value(iter, type); + if (val < 0 || val > max) return true; max = READ_ONCE(iter->ns->ucount_max[type]); }