Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

signal: Remove the bogus sigkill_pending in ptrace_stop

The existence of sigkill_pending is a little silly as it is
functionally a duplicate of fatal_signal_pending that is used in
exactly one place.

Checking for pending fatal signals and returning early in ptrace_stop
is actively harmful. It casues the ptrace_stop called by
ptrace_signal to return early before setting current->exit_code.
Later when ptrace_signal reads the signal number from
current->exit_code is undefined, making it unpredictable what will
happen.

Instead rely on the fact that schedule will not sleep if there is a
pending signal that can awaken a task.

Removing the explict sigkill_pending test fixes fixes ptrace_signal
when ptrace_stop does not stop because current->exit_code is always
set to to signr.

Cc: stable@vger.kernel.org
Fixes: 3d749b9e676b ("ptrace: simplify ptrace_stop()->sigkill_pending() path")
Fixes: 1a669c2f16d4 ("Add arch_ptrace_stop")
Link: https://lkml.kernel.org/r/87pmsyx29t.fsf@disp2133
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>

+4 -14
+4 -14
kernel/signal.c
··· 2182 2182 return true; 2183 2183 } 2184 2184 2185 - /* 2186 - * Return non-zero if there is a SIGKILL that should be waking us up. 2187 - * Called with the siglock held. 2188 - */ 2189 - static bool sigkill_pending(struct task_struct *tsk) 2190 - { 2191 - return sigismember(&tsk->pending.signal, SIGKILL) || 2192 - sigismember(&tsk->signal->shared_pending.signal, SIGKILL); 2193 - } 2194 2185 2195 2186 /* 2196 2187 * This must be called with current->sighand->siglock held. ··· 2208 2217 * calling arch_ptrace_stop, so we must release it now. 2209 2218 * To preserve proper semantics, we must do this before 2210 2219 * any signal bookkeeping like checking group_stop_count. 2211 - * Meanwhile, a SIGKILL could come in before we retake the 2212 - * siglock. That must prevent us from sleeping in TASK_TRACED. 2213 - * So after regaining the lock, we must check for SIGKILL. 2214 2220 */ 2215 2221 spin_unlock_irq(&current->sighand->siglock); 2216 2222 arch_ptrace_stop(exit_code, info); 2217 2223 spin_lock_irq(&current->sighand->siglock); 2218 - if (sigkill_pending(current)) 2219 - return; 2220 2224 } 2221 2225 2226 + /* 2227 + * schedule() will not sleep if there is a pending signal that 2228 + * can awaken the task. 2229 + */ 2222 2230 set_special_state(TASK_TRACED); 2223 2231 2224 2232 /*