Add a helper that waits for a pid and stores the status in the passed in kernel pointer. Use it to fix the usage of kernel_wait4 in call_usermodehelper_exec_sync that only happens to work due to the implicit set_fs(KERNEL_DS) for kernel threads.
Showing the changes to kernel/exit.c (1 of 3 files). Show all
Unified · Split
| @@ -1626,6 +1626,22 @@ long kernel_wait4(pid_t upid, int __user *stat_addr, int options, · 1625 unmodified lines | ||
| 1626 | 1626 | return ret; |
| 1627 | 1627 | } |
| 1628 | 1628 | |
| 1629 | +int kernel_wait(pid_t pid, int *stat) | |
| 1630 | +{ | |
| 1631 | + struct wait_opts wo = { | |
| 1632 | + .wo_type = PIDTYPE_PID, | |
| 1633 | + .wo_pid = find_get_pid(pid), | |
| 1634 | + .wo_flags = WEXITED, | |
| 1635 | + }; | |
| 1636 | + int ret; | |
| 1637 | + | |
| 1638 | + ret = do_wait(&wo); | |
| 1639 | + if (ret > 0 && wo.wo_stat) | |
| 1640 | + *stat = wo.wo_stat; | |
| 1641 | + put_pid(wo.wo_pid); | |
| 1642 | + return ret; | |
| 1643 | +} | |
| 1644 | + | |
| 1629 | 1645 | SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr, |
| 1630 | 1646 | int, options, struct rusage __user *, ru) |
| 1631 | 1647 | { |