Skip to content

Commit 7bce2c7

Browse files
avagingregkh
authored andcommitted
ucounts: fix counter leak in inc_rlimit_get_ucounts()
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/[email protected] Fixes: 15bc01e ("ucounts: Fix signal ucount refcounting") Signed-off-by: Andrei Vagin <[email protected]> Co-developed-by: Roman Gushchin <[email protected]> Signed-off-by: Roman Gushchin <[email protected]> Tested-by: Roman Gushchin <[email protected]> Acked-by: Alexey Gladkov <[email protected]> Cc: Kees Cook <[email protected]> Cc: Andrei Vagin <[email protected]> Cc: "Eric W. Biederman" <[email protected]> Cc: Alexey Gladkov <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 86dd0e8 commit 7bce2c7

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
@@ -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)