Skip to content

Commit 0cbae9e

Browse files
committed
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: 21d1c5e ("Reimplement RLIMIT_NPROC on top of ucounts") Link: https://lkml.kernel.org/r/20220216155832.680775-5-ebiederm@xmission.com Reviewed-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent c923a8e commit 0cbae9e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

kernel/ucount.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ bool is_ucounts_overlimit(struct ucounts *ucounts, enum ucount_type type, unsign
350350
if (rlimit > LONG_MAX)
351351
max = LONG_MAX;
352352
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
353-
if (get_ucounts_value(iter, type) > max)
353+
long val = get_ucounts_value(iter, type);
354+
if (val < 0 || val > max)
354355
return true;
355356
max = READ_ONCE(iter->ns->ucount_max[type]);
356357
}

0 commit comments

Comments
 (0)