From: Thadeu Lima de Souza Cascardo Date: Fri, 22 Jul 2022 09:52:11 +0000 (-0300) Subject: [PATCH] posix-cpu-timers: Cleanup CPU timers before freeing them during exec X-Git-Tag: archive/raspbian/5.18.16-1+rpi1^2~25 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b6044e229880a3751ab32dc0d25e7633da413ff6;p=linux.git [PATCH] posix-cpu-timers: Cleanup CPU timers before freeing them during exec Commit 55e8c8eb2c7b ("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: 55e8c8eb2c7b ("posix-cpu-timers: Store a reference to a pid not a task") Reported-by: "An independent security researcher working with SSD Secure Disclosure" Signed-off-by: Thadeu Lima de Souza Cascardo Gbp-Pq: Topic bugfix/all Gbp-Pq: Name posix-cpu-timers-Cleanup-CPU-timers-before-freeing-t.patch --- diff --git a/fs/exec.c b/fs/exec.c index 5a75e92b1a0..a9f5acf8f0e 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1297,6 +1297,9 @@ int begin_new_exec(struct linux_binprm * bprm) bprm->mm = NULL; #ifdef CONFIG_POSIX_TIMERS + spin_lock_irq(&me->sighand->siglock); + posix_cpu_timers_exit(me); + spin_unlock_irq(&me->sighand->siglock); exit_itimers(me); flush_itimer_signals(); #endif