Commit 0cbae9e2 authored by Eric W. Biederman's avatar Eric W. Biederman

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: 21d1c5e3 ("Reimplement RLIMIT_NPROC on top of ucounts")
Link: https://lkml.kernel.org/r/20220216155832.680775-5-ebiederm@xmission.comReviewed-by: default avatarShuah Khan <skhan@linuxfoundation.org>
Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
parent c923a8e7
...@@ -350,7 +350,8 @@ bool is_ucounts_overlimit(struct ucounts *ucounts, enum ucount_type type, unsign ...@@ -350,7 +350,8 @@ bool is_ucounts_overlimit(struct ucounts *ucounts, enum ucount_type type, unsign
if (rlimit > LONG_MAX) if (rlimit > LONG_MAX)
max = LONG_MAX; max = LONG_MAX;
for (iter = ucounts; iter; iter = iter->ns->ucounts) { 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; return true;
max = READ_ONCE(iter->ns->ucount_max[type]); max = READ_ONCE(iter->ns->ucount_max[type]);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment