Commit 7e82851b authored by Andrei Vagin's avatar Andrei Vagin Committed by Wen Zhiwei
Browse files

ucounts: fix counter leak in inc_rlimit_get_ucounts()

stable inclusion
from stable-v6.6.61
commit 1e8f31656ac154ad0dbb5ae604ef0fc32f640447
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB4YVY

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=1e8f31656ac154ad0dbb5ae604ef0fc32f640447

--------------------------------

commit 432dc0654c612457285a5dcf9bb13968ac6f0804 upstream.

The inc_rlimit_get_ucounts() increments the specified rlimit counter and
then checks its limit.  If the value exceeds the limit, the function
returns an error without decrementing the counter.

Link: https://lkml.kernel.org/r/20241101191940.3211128-1-roman.gushchin@linux.dev


Fixes: 15bc01ef ("ucounts: Fix signal ucount refcounting")
Signed-off-by: default avatarAndrei Vagin <avagin@google.com>
Co-developed-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
Signed-off-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
Tested-by: default avatarRoman Gushchin <roman.gushchin@linux.dev>
Acked-by: default avatarAlexey Gladkov <legion@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Andrei Vagin <avagin@google.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Alexey Gladkov <legion@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent 8578e0a6
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -323,7 +323,7 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
	for (iter = ucounts; iter; iter = iter->ns->ucounts) {
		long new = atomic_long_add_return(1, &iter->rlimit[type]);
		if (new < 0 || new > max)
			goto unwind;
			goto dec_unwind;
		if (iter == ucounts)
			ret = new;
		if (!override_rlimit)
@@ -341,7 +341,6 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
dec_unwind:
	dec = atomic_long_sub_return(1, &iter->rlimit[type]);
	WARN_ON_ONCE(dec < 0);
unwind:
	do_dec_rlimit_put_ucounts(ucounts, iter, type);
	return 0;
}