This is a note to let you know that I've just added the patch titled posix-cpu-timers: Cleanup CPU timers before freeing them during exec to the 5.18-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: posix-cpu-timers-cleanup-cpu-timers-before-freeing-them-during-exec.patch and it can be found in the queue-5.18 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From e362359ace6f87c201531872486ff295df306d13 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo <cascardo@xxxxxxxxxxxxx> Date: Tue, 9 Aug 2022 14:07:51 -0300 Subject: posix-cpu-timers: Cleanup CPU timers before freeing them during exec From: Thadeu Lima de Souza Cascardo <cascardo@xxxxxxxxxxxxx> commit e362359ace6f87c201531872486ff295df306d13 upstream. 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") Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@xxxxxxxxxxxxx> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Reviewed-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: <stable@xxxxxxxxxxxxxxx> Link: https://lore.kernel.org/r/20220809170751.164716-1-cascardo@xxxxxxxxxxxxx Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- fs/exec.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/exec.c +++ b/fs/exec.c @@ -1297,6 +1297,9 @@ int begin_new_exec(struct linux_binprm * 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 Patches currently in stable-queue which might be from cascardo@xxxxxxxxxxxxx are queue-5.18/netfilter-nf_tables-do-not-allow-chain_id-to-refer-to-another-table.patch queue-5.18/netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch queue-5.18/posix-cpu-timers-cleanup-cpu-timers-before-freeing-them-during-exec.patch queue-5.18/netfilter-nf_tables-do-not-allow-rule_id-to-refer-to-another-chain.patch