Re: [PATCH] signal: Prevent exec() race

From: Thomas Gleixner

Date: Tue Sep 01 2026 - 08:56:29 EST


On Mon, Aug 31 2026 at 14:44, Oleg Nesterov wrote:
> On 08/31, Thomas Gleixner wrote:
>>
>> +static inline void flush_pending_unlocked(struct task_struct *tsk)
>> +{
>> + flush_sigqueue(&tsk->pending);
>> +}
>> +
>> void exit_signals(struct task_struct *tsk)
>> {
>> int group_stop = 0;
>> @@ -3130,8 +3147,10 @@ void exit_signals(struct task_struct *ts
>> cgroup_threadgroup_change_begin(tsk);
>>
>> if (thread_group_empty(tsk) || (tsk->signal->flags & SIGNAL_GROUP_EXIT)) {
>> - tsk->flags |= PF_EXITING;
>> + scoped_guard(spinlock_irq, &tsk->sighand->siglock)
>> + tsk->flags |= PF_EXITING;
>> cgroup_threadgroup_change_end(tsk);
>> + flush_pending_unlocked(tsk);
>
> Hmm... the exiting thread is still visible to for_each_thread().
> Can't this flush_pending_unlocked() race with (say) do_sigaction() ?

Bah. Yes.