[PATCH] posix-cpu-timers: Cleanup CPU timers before freeing them during exec
authorThadeu Lima de Souza Cascardo <cascardo@canonical.com>
Fri, 22 Jul 2022 09:52:11 +0000 (06:52 -0300)
committerSalvatore Bonaccorso <carnil@debian.org>
Wed, 10 Aug 2022 18:11:48 +0000 (19:11 +0100)
commitb6044e229880a3751ab32dc0d25e7633da413ff6
tree2923948062a14102d4ce39524ef9be9e8b7f2422
parent241cc981fbe420fddf650b4dd8127c87eb62b3db
[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 <cascardo@canonical.com>
Gbp-Pq: Topic bugfix/all
Gbp-Pq: Name posix-cpu-timers-Cleanup-CPU-timers-before-freeing-t.patch
fs/exec.c