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.
Showing the changes to kernel (1 of 1 file). Show all
Unified · Split
| @@ -1298,6 +1298,12 @@ int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p · 1297 unmodified lines | ||
| 1298 | 1298 | return ret; |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 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 | + | |
| 1301 | 1307 | /* |
| 1302 | 1308 | * Force a signal that the process can't ignore: if necessary |
| 1303 | 1309 | * 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 | ||
| 1310 | 1316 | * that is why we also clear SIGNAL_UNKILLABLE. |
| 1311 | 1317 | */ |
| 1312 | 1318 | 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) | |
| 1314 | 1321 | { |
| 1315 | 1322 | unsigned long int flags; |
| 1316 | 1323 | 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 | ||
| 1321 | 1328 | action = &t->sighand->action[sig-1]; |
| 1322 | 1329 | ignored = action->sa.sa_handler == SIG_IGN; |
| 1323 | 1330 | blocked = sigismember(&t->blocked, sig); |
| 1324 | − if (blocked || ignored || sigdfl) { | |
| 1331 | + if (blocked || ignored || (handler != HANDLER_CURRENT)) { | |
| 1325 | 1332 | 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; | |
| 1327 | 1335 | if (blocked) { |
| 1328 | 1336 | sigdelset(&t->blocked, sig); |
| 1329 | 1337 | 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 | ||
| 1343 | 1351 | |
| 1344 | 1352 | int force_sig_info(struct kernel_siginfo *info) |
| 1345 | 1353 | { |
| 1346 | − return force_sig_info_to_task(info, current, false); | |
| 1354 | + return force_sig_info_to_task(info, current, HANDLER_CURRENT); | |
| 1347 | 1355 | } |
| 1348 | 1356 | |
| 1349 | 1357 | /* |
| @@ -1660,7 +1668,7 @@ void force_fatal_sig(int sig) · 310 unmodified lines | ||
| 1660 | 1668 | info.si_code = SI_KERNEL; |
| 1661 | 1669 | info.si_pid = 0; |
| 1662 | 1670 | info.si_uid = 0; |
| 1663 | − force_sig_info_to_task(&info, current, true); | |
| 1671 | + force_sig_info_to_task(&info, current, HANDLER_SIG_DFL); | |
| 1664 | 1672 | } |
| 1665 | 1673 | |
| 1666 | 1674 | /* |
| @@ -1693,7 +1701,7 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr · 26 unmodified lines | ||
| 1693 | 1701 | info.si_flags = flags; |
| 1694 | 1702 | info.si_isr = isr; |
| 1695 | 1703 | #endif |
| 1696 | − return force_sig_info_to_task(&info, t, false); | |
| 1704 | + return force_sig_info_to_task(&info, t, HANDLER_CURRENT); | |
| 1697 | 1705 | } |
| 1698 | 1706 | |
| 1699 | 1707 | 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 | ||
| 1813 | 1821 | info.si_errno = reason; |
| 1814 | 1822 | info.si_arch = syscall_get_arch(current); |
| 1815 | 1823 | 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); | |
| 1817 | 1826 | } |
| 1818 | 1827 | |
| 1819 | 1828 | /* For the crazy architectures that include trap information in |