Commit Graph

67 Commits

Author SHA1 Message Date
Todd C. Miller
de678ba775 Add setters and getters for ptrace(2) register access.
This will be used when running 32-bit binaries from a 64-bit sudo.
2022-05-05 09:17:58 -06:00
Todd C. Miller
f53053a66f exec_ptrace_handled: don't return early if ptrace_intercept_execve() fails.
We need to continue the traced process even if there is a fatal
error.  Otherwise, sudo will appear to hang as the running process
is left in PTRACE_EVENT stop.
2022-05-05 09:15:50 -06:00
Todd C. Miller
bbbb6e2ace Don't use PTRACE_GETREGS, it is too complicated when runing compat binaries.
Unlike PTRACE_GETREGSET, PTRACE_GETREGS requires that we manually
map registers from 64-bit to 32-bit layouts when running, e.g. a
32-bit binary from a 64-bit sudo process.
2022-05-05 08:53:51 -06:00
Todd C. Miller
e84fdd99fd If the process is already being traced, just resume it and clear flags.
This makes it possible to run sudo in ptrace intercept mode from within
a shell (or other process) that is already being traced by sudo.
2022-05-03 13:34:40 -06:00
Todd C. Miller
cc52ab770c exec_ptrace_handled: fix delivery of non-stop signals.
We need to deliver signals to the tracee as long as it is not
a group stop.  Fixes a hang while tracing another sudo process.
2022-05-03 12:54:10 -06:00
Todd C. Miller
1d17415b69 Add support for intercepting x32 binaries on Linux x64_64. 2022-05-02 14:36:34 -06:00
Todd C. Miller
307b4f69b8 Fix typos 2022-04-29 19:03:20 -06:00
Todd C. Miller
cdc35afff3 Short-circuit the policy check if the command doesn't exist.
Otherwise, both sudo and the shell will report the error.
2022-04-29 13:22:51 -06:00
Todd C. Miller
b75a8be34d Use PTRACE_GETREGS/PTRACE_SETREGS on platforms that support it.
This has a better chance of working on things like user-mode Linux.
2022-04-29 13:09:03 -06:00
Todd C. Miller
4010d06ed0 In ptrace(2) intercept mode, add execveat to the seccomp(2) filter.
This allows us to avoid logging the initial command twice regardless
of whether the kernel supports execveat(2) or not.
2022-04-29 13:09:03 -06:00
Todd C. Miller
52cacfc302 For ptrace intercept mode, do not do a policy check for the initial command.
We can skip the policy check for the execve(2) of the initial command
since it has already been check.  Otherwise, we would log the command
twice.  When using fexecve(2) due to a digest check, there should
be no need to skip the initial command since it will be executed
via execveat(2) not execve(2).  However, on older kernels without
execveat(2), glibc will emulate fexecve(2) using /proc which will
result in the extra log entry.
2022-04-29 13:09:03 -06:00
Todd C. Miller
423fbedb65 Suspend the child process and wait for SIGUSR when using ptrace.
This fixes a race condition in ptrace-based intercept mode when
running the command in a pty.  It was possible for the monitor to
receive SIGCHLD when the command sent itself SIGSTOP before the
main sudo process did.
2022-04-29 13:09:03 -06:00
Todd C. Miller
fe80dc0bc2 Check architecture in the seccomp filter.
Currently only supports the native architecture.
2022-04-29 13:09:03 -06:00
Todd C. Miller
8e7ead57f6 Add support for replacing argv in ptrace intecept mode.
The new argv is written below the tracee's stack and the system
call argument is replaced with the new argv address.
2022-04-29 13:09:03 -06:00
Todd C. Miller
8e375445fb Check the policy for ptrace-based intercept mode. 2022-04-29 13:08:59 -06:00
Todd C. Miller
3e73644cde Add support for getting the execve(2) arguments via ptrace(2).
This will be used to perform a policy check in intercept mode.
2022-04-29 12:35:34 -06:00
Todd C. Miller
01733a5214 Add scaffolding for ptrace-based intercept mode. 2022-04-29 12:35:31 -06:00