Skip to content

Commit 94cd8fa

Browse files
compudjPeter Zijlstra
authored andcommitted
futex: Fix futex_waitv() hrtimer debug object leak on kcalloc error
In a scenario where kcalloc() fails to allocate memory, the futex_waitv system call immediately returns -ENOMEM without invoking destroy_hrtimer_on_stack(). When CONFIG_DEBUG_OBJECTS_TIMERS=y, this results in leaking a timer debug object. Fixes: bf69bad ("futex: Implement sys_futex_waitv()") Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net> Cc: stable@vger.kernel.org Cc: stable@vger.kernel.org # v5.16+ Link: https://lore.kernel.org/r/20221214222008.200393-1-mathieu.desnoyers@efficios.com
1 parent 1c0908d commit 94cd8fa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

kernel/futex/syscalls.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,22 @@ SYSCALL_DEFINE5(futex_waitv, struct futex_waitv __user *, waiters,
286286
}
287287

288288
futexv = kcalloc(nr_futexes, sizeof(*futexv), GFP_KERNEL);
289-
if (!futexv)
290-
return -ENOMEM;
289+
if (!futexv) {
290+
ret = -ENOMEM;
291+
goto destroy_timer;
292+
}
291293

292294
ret = futex_parse_waitv(futexv, waiters, nr_futexes);
293295
if (!ret)
294296
ret = futex_wait_multiple(futexv, nr_futexes, timeout ? &to : NULL);
295297

298+
kfree(futexv);
299+
300+
destroy_timer:
296301
if (timeout) {
297302
hrtimer_cancel(&to.timer);
298303
destroy_hrtimer_on_stack(&to.timer);
299304
}
300-
301-
kfree(futexv);
302305
return ret;
303306
}
304307

0 commit comments

Comments
 (0)