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/[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]>
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)