Skip to content

Commit 432dc06

Browse files
avaginakpm00
authored andcommitted
ucounts: fix counter leak in inc_rlimit_get_ucounts()
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: 15bc01e ("ucounts: Fix signal ucount refcounting") Signed-off-by: Andrei Vagin <avagin@google.com> Co-developed-by: Roman Gushchin <roman.gushchin@linux.dev> Signed-off-by: Roman Gushchin <roman.gushchin@linux.dev> Tested-by: Roman Gushchin <roman.gushchin@linux.dev> Acked-by: Alexey 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: Andrew Morton <akpm@linux-foundation.org>
1 parent 0268d45 commit 432dc06

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

kernel/ucount.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type)
317317
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
318318
long new = atomic_long_add_return(1, &iter->rlimit[type]);
319319
if (new < 0 || new > max)
320-
goto unwind;
320+
goto dec_unwind;
321321
if (iter == ucounts)
322322
ret = new;
323323
max = get_userns_rlimit_max(iter->ns, type);
@@ -334,7 +334,6 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type)
334334
dec_unwind:
335335
dec = atomic_long_sub_return(1, &iter->rlimit[type]);
336336
WARN_ON_ONCE(dec < 0);
337-
unwind:
338337
do_dec_rlimit_put_ucounts(ucounts, iter, type);
339338
return 0;
340339
}

0 commit comments

Comments
 (0)