Commit Graph

1666 Commits

Author SHA1 Message Date
Todd C. Miller
4833ac0f01 Avoid passing sudo_term_is_raw() -1 for the fd.
Coverity CID 330472
Coverity CID 330468
2023-11-02 14:17:51 -06:00
Todd C. Miller
58d6554a78 Use vsnprintf() instead of vfprintf() for sudo_printf() to avoid
problems on systems where the system printf(3) is not C99-compliant.
We use our own snprintf() on such systems.
2023-10-17 20:09:16 -06:00
Todd C. Miller
2f80865e73 Add a little extra debugging info. 2023-10-16 12:07:35 -06:00
Rose
dd8426f9cf Specify 1U over 1 for bitmaps 2023-10-14 16:23:59 -06:00
Todd C. Miller
873e0de078 ptrace_intercept_execve: make flags unsigned to match command_details 2023-10-14 16:12:06 -06:00
Todd C. Miller
f6561bc974 Add more user info to the list of objects to be garbage-collected at exit. 2023-09-28 13:37:42 -06:00
Todd C. Miller
e343e07543 Use #include <foo.h> instead of #include "foo.h" in most cases.
We rely on the include path to find many of these headers.  It
especially doesn't make sense to use #include "foo.h" for headers
in the top-level include directory.
2023-09-25 10:13:28 -06:00
Todd C. Miller
171abbe112 No need to loop reading from/writing to a blocking socketpair.
This removes some infinite loops that can cause static analyzer
warnings.  The fds are not in non-blocking mode and we use restartable
system calls so there is no need to loop.
2023-09-22 10:53:41 -06:00
Todd C. Miller
988d7f60f0 Set ec->term_raw to false even if sudo_term_restore() fails.
Either the fd is not a terminal or we don't have the controlling
terminal.  Either way, we can't know the current status of the
terminal and will need to set to raw mode again (if possible).  Also
make sure to set ec->term_raw to false if sudo_term_raw() fails.
2023-09-21 14:13:17 -06:00
Todd C. Miller
94b80e3ad4 Replace MAX_UID_T_LEN with calls to STRLEN_MAX_UNSIGNED. 2023-09-19 15:16:30 -06:00
Todd C. Miller
d53bbb54b2 Add macros to determine the length of an integer type in string form.
Adapted from answer #6 in:
https://stackoverflow.com/questions/10536207/ansi-c-maximum-number-of-characters-printing-a-decimal-int
2023-09-19 15:15:02 -06:00
Todd C. Miller
0cb3e33444 Wait on a socketpair for the parent to grant child the controlling tty.
This upgrades the error pipe to a bi-directional socketpair that
the parent will write to after it has granted the child process the
controlling terminal.  That fixes an issue where the child could
end up in a tight CPU loop waiting on the parent which may not be
scheduled immediately.
2023-09-18 12:26:19 -06:00
Todd C. Miller
49c7c1f4d3 Only cast TIOCSWINSZ to int on systems that might require it (AIX).
Otherwise we end up with a -Wconversion warning on systems where
the ioctl() request argument is unsigned long.
2023-09-15 10:26:29 -06:00
Todd C. Miller
4117ad1462 Only call ptrace_verify_post_exec() for intercept, not log_subcmds.
This fixes a logic goof introduced in sudo 1.9.14.
2023-09-11 13:11:49 -06:00
Todd C. Miller
c6987aa26e Cast int to size_t before adding instead of casting the result.
Quiets PVS-Studio warning V1028.
2023-08-21 12:50:31 -06:00
Todd C. Miller
e933fc7ba3 Use a global static struct exec_closure for the cleanup hook.
This is safer than storing a pointer to a stack variable in the
cleanup function since we don't need to worry about it ever going
out of scope.  Quiets a clang 15 analyzer warning.
2023-08-21 10:47:34 -06:00
Todd C. Miller
d148e7d8f9 fd_matches_tty: only zero out fd_sb if fstat(2) fails.
We need to preserve the contents of the struct stat if the fd is
some other type so the check for piped output works correctly.
Bug #1057
2023-08-12 10:39:33 -06:00
Todd C. Miller
d6d467b92e Add implementation of SSL_read_ex/SSL_write_ex for those without. 2023-08-05 10:38:02 -06:00
Todd C. Miller
980e0216ac Add basic support for 32-bit and 64-bit LD_PRELOAD equivalents.
The noexec and intercept DSO settings may now include both a 32-bit
DSO and a 64-bit DSO specified by a colon.  For example:
/usr/libexec/sudo/sudo_intercept.so:/usr/libexec/sudo/sudo_intercept_64.so.
2023-07-31 13:46:57 -06:00
Todd C. Miller
7cb1f7f3a9 Cast TIOCSWINSZ to int to avoid overflow warning on 64-bit AIX. 2023-07-31 09:58:13 -06:00
Todd C. Miller
961f23af94 Read path section of sudo.conf for sudo_conf_intercept_path(). 2023-07-28 19:31:19 -06:00
Todd C. Miller
857653f9f5 Remove unused variable introduced in last commit. 2023-07-26 19:49:25 -06:00
Todd C. Miller
760c9c1107 Don't assume that if std{in,out,err} is a tty, it is the user's tty.
Previously, sudo only checked that the fd was a terminal, not that
it matched sudo's idea of the user's terminal.  This matters when
input or output is redirected to a different terminal.  In that
case we want to interpose the fd with a pipe even if it refers to
a terminal.  Bug #1056.
2023-07-26 19:43:49 -06:00
Todd C. Miller
78b712101e Pass SUDO_TERM_OFLAG to sudo_term_raw() when sudo output is piped.
This fixes a problem with "stair-stepped" output when the sudo-run
command's output is piped to another program and the command reads
input from the terminal.
2023-07-14 14:12:18 -06:00
Todd C. Miller
db4bdb7327 Simplify the exec_monitor() foreground flag.
Add cmnd_foreground flag that is only true if sudo is the foreground
process and the CD_EXEC_BG flag is not set and pass it to exec_monitor().
This means exec_monitor() no longer needs to check for CD_EXEC_BG.
2023-07-14 14:08:59 -06:00
Todd C. Miller
ff6ddff39b Fix a crash in intercept mode running a command with NULL argv[0].
Newer Linux kernels replace a NULL argv[0] with the empty string,
we should as well.
2023-07-12 09:29:00 -06:00
Todd C. Miller
b47f1799c5 sudo_conversation_printf: simplify \n -> \r\n handling 2023-07-12 08:39:18 -06:00
Todd C. Miller
a014b0f2aa sudo_conversation: zero out reply even if no password is requested.
This avoids a potential invalid free in the err label and provides
more predictable behavior when mixing message types in a conversation.
2023-07-12 08:16:35 -06:00
Todd C. Miller
dbb95ad214 sudo frontend: make more bit flags unsigned. 2023-07-10 11:06:34 -06:00
Rose
5d758264ab Give every printf-like function restrict qualifiers
The format value has to be a string literal, every time.

Otherwise, you are not using these functions correctly. To reinforce this fact, I putrestrict over every non-contrib example of this I could find.
2023-07-07 20:23:20 -04:00
Todd C. Miller
92860c717d struct exec_closure: make rows and cols int, not short
There's no real space saved by using short and using int avoids a
few casts.
2023-07-07 15:42:53 -06:00
Todd C. Miller
32f4b98f6b sudo frontend: silence most -Wconversion warnings. 2023-07-07 15:07:04 -06:00
Rose
cbed9daa46 Fixed even more signedness and conversion issues
This should be the last of them.
2023-07-03 22:07:35 -04:00
Todd C. Miller
04c7e910ef Fix up indentation. 2023-07-01 16:03:33 -06:00
Rose
45fdfa18f1 Mark functions not returning as sudo_noreturn
We also put NOTREACHED where it applies.
2023-07-01 17:40:16 -04:00
Todd C. Miller
97e574091a Avoid passing debug_return_size_t() a negative number. 2023-07-01 10:39:25 -06:00
Rose
22079c3072 Avoid compiler casting warnings Part 2
This saves instructions that are related to casting as well as compiler warnings.
2023-06-29 13:10:27 -04:00
Rose
e54ba33ea0 Avoid compiler casting warnings by assigning to the same type where possible
This saves instructions that are related to casting as well as compiler warnings.
2023-06-28 17:25:26 -04:00
Todd C. Miller
a0b074cc9c Fix undefined symbol on macOS for intercept mode and log_subcmds.
macOS does not support direct access to the environ pointer from a
shared object.  We need to redirect through _NSGetEnviron() instead.
Fixes GitHub issue #276.
2023-06-28 10:59:26 -06:00
Todd C. Miller
245c56bac1 Only call ptrace_verify_post_exec() for intercept, not log_subcmds. 2023-06-05 16:03:03 -06:00
Todd C. Miller
95cd409079 Make suspend_parent.c out of lib/util and into src.
Nothing else uses it now.
2023-06-04 19:08:52 -06:00
Todd C. Miller
27ea64bacd Use a "%s" format instead of using a translated string as the format. 2023-05-03 13:26:54 -06:00
Todd C. Miller
d4c6ef1222 Add adminconfdir and --enable-adminconf to set it.
Configuration paths in sudo are now a colon-separated list of files
with the adminconfdir instance first (if enabled), followed by a
sysconfdir instance.
2023-05-02 10:37:39 -06:00
Todd C. Miller
4363d03ef7 Convert config file paths to colon-separated path list.
This means that _PATH_SUDO_CONF, _PATH_SUDOERS, _PATH_SUDO_LOGSRVD_CONF,
and _PATH_CVTSUDOERS_CONF can now specify multiple files.  The first
file that exists is used.
2023-05-02 10:37:38 -06:00
Todd C. Miller
b1deffbe5b disable_coredump: only change the soft limit, leave the hard limit as-is
This should avoid problems on Linux in cases where sudo does not
have CAP_SYS_RESOURCE which may be the case in an unprivileged container.
GitHub issue #42
2023-04-24 10:32:40 -06:00
Todd C. Miller
6c3c8acbac More accurate description of what happens for "sudo -b". 2023-04-19 15:09:23 -06:00
Todd C. Miller
ab0f8dda31 Avoid calling isatty()/ttyname() on std{in,out,err} if not a char dev.
The user controls these fds so we should avoid calling ioctl(2) on
them unless they correspond to actual character device files.
2023-04-18 13:52:26 -06:00
Todd C. Miller
fe80c27dec Better support for "sudo -b" when running the command in a pty.
When a command is run via "sudo -b" it has no access to terminal
input.  In non-pty mode, the command runs in an orphaned process
group and reads from the controlling terminal fail with EIO.  We
cannot do the same while running in a pty but if we set stdin to a
half-closed pipe, reads from it will get EOF.  That is close enough.
2023-04-19 14:34:57 -06:00
Todd C. Miller
b24af7b3e6 Hard-code usage() and help() for an 80-column terminal.
Trying to tailor the help and usage output to the terminal width
is simply not worth it and could be abused to mark a socket as
"trusted" on Linux if there are additional kernel bugs like
CVE-2023-2002.
2023-04-18 07:33:12 -06:00
Todd C. Miller
65c0b5a089 Move CONFIGURE_ARGS from sudo_usage.h.in to config.h.in. 2023-04-18 07:29:37 -06:00