History

signal: Don't always set SA_IMMUTABLE for forced signals

Recently to prevent issues with SECCOMP_RET_KILL and similar signals being changed before they are delivered SA_IMMUTABLE was added. Unfortunately this broke debuggers[1][2] which reasonably expect to be able to trap synchronous SIGTRAP and SIGSEGV even when the target process is not configured to handle those signals. Update force_sig_to_task to support both the case when we can allow the debugger to intercept and possibly ignore the signal and the case when it is not safe to let userspace know about the signal until the process has exited.

Eric W. Biederman committed 4 years ago

Commit e349d941 parent fa55b7d1 file · +16 −7Browse files

Showing the changes to kernel (1 of 1 file). Show all

Unified · Split

kernel/signal.c+16−7
@@ -1298,6 +1298,12 @@ int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p · 1297 unmodified lines
12981298 return ret;
12991299 }
13001300
1301+enum sig_handler {
1302+ HANDLER_CURRENT, /* If reachable use the current handler */
1303+ HANDLER_SIG_DFL, /* Always use SIG_DFL handler semantics */
1304+ HANDLER_EXIT, /* Only visible as the process exit code */
1305+};
1306+
13011307 /*
13021308 * Force a signal that the process can't ignore: if necessary
13031309 * we unblock the signal and change any SIG_IGN to SIG_DFL.
@@ -1310,7 +1316,8 @@ int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p · 6 unmodified lines
13101316 * that is why we also clear SIGNAL_UNKILLABLE.
13111317 */
13121318 static int
1313−force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t, bool sigdfl)
1319+force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t,
1320+ enum sig_handler handler)
13141321 {
13151322 unsigned long int flags;
13161323 int ret, blocked, ignored;
@@ -1321,9 +1328,10 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t, bool · 4 unmodified lines
13211328 action = &t->sighand->action[sig-1];
13221329 ignored = action->sa.sa_handler == SIG_IGN;
13231330 blocked = sigismember(&t->blocked, sig);
1324− if (blocked || ignored || sigdfl) {
1331+ if (blocked || ignored || (handler != HANDLER_CURRENT)) {
13251332 action->sa.sa_handler = SIG_DFL;
1326− action->sa.sa_flags |= SA_IMMUTABLE;
1333+ if (handler == HANDLER_EXIT)
1334+ action->sa.sa_flags |= SA_IMMUTABLE;
13271335 if (blocked) {
13281336 sigdelset(&t->blocked, sig);
13291337 recalc_sigpending_and_wake(t);
@@ -1343,7 +1351,7 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t, bool · 13 unmodified lines
13431351
13441352 int force_sig_info(struct kernel_siginfo *info)
13451353 {
1346− return force_sig_info_to_task(info, current, false);
1354+ return force_sig_info_to_task(info, current, HANDLER_CURRENT);
13471355 }
13481356
13491357 /*
@@ -1660,7 +1668,7 @@ void force_fatal_sig(int sig) · 310 unmodified lines
16601668 info.si_code = SI_KERNEL;
16611669 info.si_pid = 0;
16621670 info.si_uid = 0;
1663− force_sig_info_to_task(&info, current, true);
1671+ force_sig_info_to_task(&info, current, HANDLER_SIG_DFL);
16641672 }
16651673
16661674 /*
@@ -1693,7 +1701,7 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr · 26 unmodified lines
16931701 info.si_flags = flags;
16941702 info.si_isr = isr;
16951703 #endif
1696− return force_sig_info_to_task(&info, t, false);
1704+ return force_sig_info_to_task(&info, t, HANDLER_CURRENT);
16971705 }
16981706
16991707 int force_sig_fault(int sig, int code, void __user *addr
@@ -1813,7 +1821,8 @@ int force_sig_seccomp(int syscall, int reason, bool force_coredump) · 113 unmodified lines
18131821 info.si_errno = reason;
18141822 info.si_arch = syscall_get_arch(current);
18151823 info.si_syscall = syscall;
1816− return force_sig_info_to_task(&info, current, force_coredump);
1824+ return force_sig_info_to_task(&info, current,
1825+ force_coredump ? HANDLER_EXIT : HANDLER_CURRENT);
18171826 }
18181827
18191828 /* For the crazy architectures that include trap information in