Commit Graph

11831 Commits

Author SHA1 Message Date
Todd C. Miller
532e8218b2 Use unsigned long for addresses so we don't have to worry about sign extension. 2022-05-11 08:04:58 -06:00
Todd C. Miller
6cd461d9f8 ptrace_write_string: make sure we always write the terminating NUL.
We can't check *str for NUL since it may not have been written yet.
2022-05-10 11:23:44 -06:00
Todd C. Miller
8fe1238679 Fix compilation error when SECCOMP_AUDIT_ARCH_COMPAT is not defined. 2022-05-10 08:17:00 -06:00
Todd C. Miller
a40d62b3d5 It is now safe to make WORDALIGN use compat (not native) aligment.
We allocate space for an extra pointer between argv and the string
table for compat binaries so there is no need to align address to
sizeof(long).
2022-05-09 11:03:30 -06:00
Todd C. Miller
f82aa334cc Use the entire word in ptrace_get_vec_len() and ptrace_read_vec().
For compat binaries, use the upper 32-bits as the next word instead
of calling ptrace(2) to get it.  This reduces the number of ptrace(2)
calls when reading argv and envp for compat binaries.
2022-05-09 10:09:30 -06:00
Todd C. Miller
c9a481506d We don't need to align strings in the string table.
We align the start of the string table to a word boundary to help
prevent overlap when writing the pointers.  However, the actual
strings themselves don't need to be aligned.
2022-05-07 18:42:32 -06:00
Todd C. Miller
206cd10ed5 Avoid potentially overwriting string table when writing argv.
In compat mode, if argc is odd, writing the last pointer of argv will
overlap with the address of argv[0], so leave an extra word in between.
Also remove incorrect comments about PTRACE_PEEKDATA unaligned access.
2022-05-06 19:46:22 -06:00
Todd C. Miller
0a2975367e ptrace_intercept_execve: rewrite path to exec if changed by the policy 2022-05-05 19:07:12 -06:00
Todd C. Miller
a15ca9c85b Use native word size for padding and when reading/writing strings.
If we try to use the compat word size we can end up in a situation
where a subsequent PTRACE_POKEDATA overwrites part of what we've
already written since it always writes in sizeof(long) units.
2022-05-06 10:46:06 -06:00
Todd C. Miller
339746730c ptrace_intercept_execve: plug memory leak of get_execve_info() buffer 2022-05-05 19:06:19 -06:00
Todd C. Miller
35ea534b3e Move register definitions to exec_ptrace.h 2022-05-05 13:37:26 -06:00
Todd C. Miller
d3a1bf4216 Add support for intercepting 32-bit binaries on 64-bit systems.
We need to define the ptrace register struct ourselves for the
32-bit system since there is no good way to get it from the system
headers.  Currently only implemented for x86_64 and aarch64.
2022-05-05 09:29:05 -06:00
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
4ab6a87b96 Initialize intercept_allow_setid to true if we use ptrace(2) and seccomp(2). 2022-05-04 13:32:28 -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
4cac34b86d Make SIGCHLD handler more consistent with the pty version.
No real change other than a few debug statements.
2022-05-03 09:38:28 -06:00
Todd C. Miller
4d75b32799 sudoers_lookup_check: preserve intercepted flag when reinitializing cmnd_info
Otherwise we may not reject an attempt to run a set-user-ID command.
2022-05-03 09:30:09 -06:00
Todd C. Miller
3ee8bcefb0 Kill the command if intercept_setup() or ptrace_seize() fail. 2022-05-03 09:25:58 -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
42117a1ce2 Move intercept setid check out of do_stat() and into its own function.
For command_matches_all() we should only perform the setid check
if the file exists and intercept is enabled.  Otherwise, we can end
up returning an error if the fully-qualified command does not exist.
Fixes a regression introduced in sudo 1.9.0 with the support for
digests in conjunction with "sudo ALL".
2022-05-02 18:14:30 -06:00
Todd C. Miller
4ac1237bd3 Sudo 1.9.11 2022-04-29 19:03:24 -06:00
Todd C. Miller
307b4f69b8 Fix typos 2022-04-29 19:03:20 -06:00
Todd C. Miller
77979932b1 New Georgian translation from translationproject.org 2022-04-29 13:32:29 -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
052d3d1d91 Update intercept documentation. 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
5d385b3c58 Enable intercept and log_subcmds for SELinux using ptrace and seccomp. 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
Todd C. Miller
22866f2423 Handle multiple child processes in the SIGCHLD handler.
This is required by the uncoming ptrace intercept code.
2022-04-29 08:02:57 -06:00
Todd C. Miller
46edc4e198 Stop using the WCONTINUED flag with waitpid(2).
We don't use it for anything other than a debug message and it will
cause problems when intercept mode starts using ptrace(2).
2022-04-29 08:02:57 -06:00
Todd C. Miller
c7ed03c986 sudo_logsrvd: update elapsed time for winsize and suspend in journal mode
Fixes a bug in store-first relay mode where the commit point messages
sent by the server were incorrect.
2022-04-24 17:26:05 -06:00
Todd C. Miller
72794ecd75 Fix typo; GitHub issue #144 2022-04-23 07:21:08 -06:00
Todd C. Miller
d2da56dacc Add struct command details * to struct monitor_closure.
This will be used in the future by the ptrace intercept code.
2022-04-20 13:58:22 -06:00
Todd C. Miller
841375783a Don't require a pty for intercept or log_subcmmds.
The code to take back control of the tty before a policy check
doesn't appear to be needed.  If the command is run in its own pty,
sudo has control over the user's tty.  If the command is run in
the user's tty, sudo should be in the foreground process group.
2022-04-20 11:56:26 -06:00
Todd C. Miller
839c189373 Translate "unable to set limit privileges" strings. 2022-04-20 13:55:51 -06:00
Todd C. Miller
ec5164ced2 Define _TIME_BITS=64 on systems that define __TIMESIZE, like GNU libc.
This should be replaced by a specialized autoconf macro when one
becomes available.
2022-04-19 13:28:39 -06:00
Todd C. Miller
c414a89eb3 Remove ABOUT-NLS file, it is no longer maintained as part of GNU gettext.
Expand the Translations section in CONTRIBUTING.md.
2022-04-20 12:58:11 -06:00
Todd C. Miller
c51b81fa53 Expand section about expired accounts to include /etc/shadow info.
GitHub issue #143
2022-04-20 15:47:42 -06:00
Todd C. Miller
930271847a clean_output: prune lines that consisting of '^' characters and whitespace.
Starting with Python 3.11, backtraces may contain a line with '^'
characters to bring attention to the important part of the line.
Also replace "REJECT" with "0" in backtrace output for Python 3.11.
2022-04-11 19:05:06 -06:00
Todd C. Miller
a1e20ddd95 Fix check for EVP_MD_CTX_new() when -pthread is in Libs.private. 2022-04-04 10:13:28 -06:00