signal: clear JOBCTL_PENDING_MASK for caller in zap_other_threads()
PATCH v2 1/1 signal: clear JOBCTL_PENDING_MASK for caller in zap_other_threads()
When a multi-threaded process receives a stop signal (e.g., SIGSTOP), do_signal_stop() sets JOBCTL_STOP_PENDING and JOBCTL_STOP_CONSUME on all threads and sets signal->group_stop_count to the number of threads. If one of the threads concurrently calls execve(), de_thread() invokes zap_other_threads() to kill all other threads. zap_other_threads() aborts the pending group stop by resetting signal->group_stop_count to 0 and clears the JOBCTL_PENDING_MASK for all other threads. However, it fails to clear the job control flags for the calling thread.
When execve() completes, the calling thread returns to user mode and checks for pending signals. Seeing the stale JOBCTL_STOP_PENDING flag, it calls do_signal_stop(), which invokes task_participate_group_stop(). Since JOBCTL_STOP_CONSUME is still set, it attempts to decrement the already-zero signal->group_stop_count, triggering a warning:
sig->group_stop_count == 0
WARNING: CPU: 1 PID: 6475 at kernel/signal.c:373 task_participate_group_stop+0x215/0x2d0 Call Trace: <TASK> do_signal_stop+0x3be/0x5c0 kernel/signal.c:2619 get_signal+0xa8c/0x1330 kernel/signal.c:2884 arch_do_signal_or_restart+0xbc/0x840 arch/x86/kernel/signal.c:337 exit_to_user_mode_loop+0x8c/0x4d0 kernel/entry/common.c:98 do_syscall_64+0x33e/0xf80 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f </TASK>
Fix this race condition by clearing the JOBCTL_PENDING_MASK for the calling thread in zap_other_threads(), ensuring it does not retain any stale job control state after the thread group is destroyed. This aligns with other functions that tear down a thread group and abort group stops, such as zap_process() and complete_signal(), which correctly clear these flags for all threads including the current one.
---
v2:
Resending my from own name to comply with the rules.
v1:
https://lore.kernel.org/all/[email protected]/
--- kernel/signal.c | 1 + 1 file changed, 1 insertion(+)
kernel/signal.c +1 -0
@@ -1338,6 +1338,7 @@ int zap_other_threads(struct task_struct *p)int count =0 ; p->signal->group_stop_count =0 ; +task_clear_jobctl_pending (p,JOBCTL_PENDING_MASK ); for_other_threads(p, t) {task_clear_jobctl_pending (t,JOBCTL_PENDING_MASK );
base-commit: 5200f5f493f79f14bbdc349e402a40dfb32f23c8
Signature · 1 line
2.54.0.669.g59709faab0-goog
Christian Brauner
AppliedQuoted 10 lines · Aleksandr Nogikh
When a multi-threaded process receives a stop signal (e.g., SIGSTOP),
do_signal_stop()setsJOBCTL_STOP_PENDINGandJOBCTL_STOP_CONSUMEon all threads and setssignal->group_stop_countto the number of threads. If one of the threads concurrently callsexecve(),de_thread()invokeszap_other_threads()to kill all other threads.zap_other_threads()aborts the pending group stop by resettingsignal->group_stop_countto 0 and clears theJOBCTL_PENDING_MASKfor all other threads. However, it fails to clear the job control flags for the calling thread.[...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree. Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.fixes
[1/1] signal: clear JOBCTL_PENDING_MASK for caller in zap_other_threads()
https://git.kernel.org/vfs/vfs/c/90918794a4e2
Oleg Nesterov
Acked-byQuoted 3 lines · Christian Brauner
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
I have already acked V1, let me ack V2 as well.