Skip to content

Commit e362359

Browse files
Thadeu Lima de Souza CascardoKAGA-KOKO
authored andcommitted
posix-cpu-timers: Cleanup CPU timers before freeing them during exec
Commit 55e8c8e ("posix-cpu-timers: Store a reference to a pid not a task") started looking up tasks by PID when deleting a CPU timer. When a non-leader thread calls execve, it will switch PIDs with the leader process. Then, as it calls exit_itimers, posix_cpu_timer_del cannot find the task because the timer still points out to the old PID. That means that armed timers won't be disarmed, that is, they won't be removed from the timerqueue_list. exit_itimers will still release their memory, and when that list is later processed, it leads to a use-after-free. Clean up the timers from the de-threaded task before freeing them. This prevents a reported use-after-free. Fixes: 55e8c8e ("posix-cpu-timers: Store a reference to a pid not a task") Signed-off-by: Thadeu Lima de Souza Cascardo <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 46dae32 commit e362359

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/exec.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,6 +1304,9 @@ int begin_new_exec(struct linux_binprm * bprm)
13041304
bprm->mm = NULL;
13051305

13061306
#ifdef CONFIG_POSIX_TIMERS
1307+
spin_lock_irq(&me->sighand->siglock);
1308+
posix_cpu_timers_exit(me);
1309+
spin_unlock_irq(&me->sighand->siglock);
13071310
exit_itimers(me);
13081311
flush_itimer_signals();
13091312
#endif

0 commit comments

Comments
 (0)