Skip to content

Commit 30fe6b1

Browse files
avagingregkh
authored andcommitted
ucounts: fix counter leak in inc_rlimit_get_ucounts()
commit 432dc06 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: 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2b53695 commit 30fe6b1

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

kernel/ucount.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
318318
for (iter = ucounts; iter; iter = iter->ns->ucounts) {
319319
long new = atomic_long_add_return(1, &iter->rlimit[type]);
320320
if (new < 0 || new > max)
321-
goto unwind;
321+
goto dec_unwind;
322322
if (iter == ucounts)
323323
ret = new;
324324
if (!override_rlimit)
@@ -336,7 +336,6 @@ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type,
336336
dec_unwind:
337337
dec = atomic_long_sub_return(1, &iter->rlimit[type]);
338338
WARN_ON_ONCE(dec < 0);
339-
unwind:
340339
do_dec_rlimit_put_ucounts(ucounts, iter, type);
341340
return 0;
342341
}

0 commit comments

Comments
 (0)