]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
ucounts: Enforce RLIMIT_NPROC not RLIMIT_NPROC+1
authorEric W. Biederman <ebiederm@xmission.com>
Thu, 10 Feb 2022 02:03:19 +0000 (20:03 -0600)
committerPaolo Pisati <paolo.pisati@canonical.com>
Mon, 7 Mar 2022 10:44:17 +0000 (11:44 +0100)
commita7b7b7df3f327f210121ffd433e7c868942fc3c8
treee01cc56a78d3420819b4f564c7198167633d15b6
parent6722db02601e0f65896b593a8967b5b9bfa14dbc
ucounts: Enforce RLIMIT_NPROC not RLIMIT_NPROC+1

BugLink: https://bugs.launchpad.net/bugs/1963890
commit 8f2f9c4d82f24f172ae439e5035fc1e0e4c229dd upstream.

Michal Koutný <mkoutny@suse.com> wrote:

> It was reported that v5.14 behaves differently when enforcing
> RLIMIT_NPROC limit, namely, it allows one more task than previously.
> This is consequence of the commit 21d1c5e386bc ("Reimplement
> RLIMIT_NPROC on top of ucounts") that missed the sharpness of
> equality in the forking path.

This can be fixed either by fixing the test or by moving the increment
to be before the test.  Fix it my moving copy_creds which contains
the increment before is_ucounts_overlimit.

In the case of CLONE_NEWUSER the ucounts in the task_cred changes.
The function is_ucounts_overlimit needs to use the final version of
the ucounts for the new process.  Which means moving the
is_ucounts_overlimit test after copy_creds is necessary.

Both the test in fork and the test in set_user were semantically
changed when the code moved to ucounts.  The change of the test in
fork was bad because it was before the increment.  The test in
set_user was wrong and the change to ucounts fixed it.  So this
fix only restores the old behavior in one lcation not two.

Link: https://lkml.kernel.org/r/20220204181144.24462-1-mkoutny@suse.com
Link: https://lkml.kernel.org/r/20220216155832.680775-2-ebiederm@xmission.com
Cc: stable@vger.kernel.org
Reported-by: Michal Koutný <mkoutny@suse.com>
Reviewed-by: Michal Koutný <mkoutny@suse.com>
Fixes: 21d1c5e386bc ("Reimplement RLIMIT_NPROC on top of ucounts")
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
kernel/fork.c