Commit Graph

1172 Commits

Author SHA1 Message Date
Todd C. Miller
f5b60ef749 Add debug warning when we have wait status but don't overwrite the
existing cstat.
2017-06-15 07:51:02 -06:00
Todd C. Miller
c8c586ee0b Better handling of SIGCONT from in command in the monitor. It is
useful to know when the command continued but we don't want to
inform the parent or store the wait status in this case.  Fixes a
hang after multiple suspends on Linux.
2017-06-15 07:51:00 -06:00
Todd C. Miller
ab59834a00 Don't treat an unchanged file as an error. From Xin Li. 2017-06-05 07:47:43 -06:00
Todd C. Miller
0d70e868f1 sudo_edit() must return a wait status but if there is an error, or
even if no changes were made to the file, it was returning 1 instead
which would be interpreted as the command having received SIGHUP.
Use the W_EXITCODE() to construct a proper wait status in the error
case too.
2017-06-05 07:11:09 -06:00
Todd C. Miller
26d9043bf4 Avoid sign extension when assigning the value of tty_nr in
/proc/self/stat on Linux.  It is an unsigned int value that
is printed as a signed int but dev_t is unsigned long long.
We need to cast to unsigned int before assigning to a dev_t.
2017-06-03 08:45:29 -06:00
Todd C. Miller
c13ebffbce A command name may also contain newline characters so read
/proc/self/stat until EOF.  It is not legal for /proc/self/stat to
contain embedded NUL bytes so treat the file as corrupt if we see
any.  With help from Qualys.

This is not exploitable due to the /dev traversal changes in sudo
1.8.20p1 (thanks Solar!).
2017-05-31 09:14:31 -06:00
Todd C. Miller
15901c9487 Use /proc/self consistently on Linux. As far as I know, only AIX
doesn't support /proc/self.
2017-05-30 10:44:11 -06:00
Todd C. Miller
cc71b99849 Add a new "devsearch" Path setting to sudo.conf for configuring the
/dev paths to traverse instead of hard-coding a list in ttyname.c
The default value can be set at configure time.
2017-05-30 10:44:11 -06:00
Todd C. Miller
777abca382 After opening a tty device, fstat() and error out if it is not
a character device.
2017-05-30 10:44:11 -06:00
Todd C. Miller
b3fe46ce65 Fix for CVE-2017-1000367, parsing of /proc/pid/stat on Linux when
the process name contains spaces.  Since the user has control over
the command name this could be used by a user with sudo access to
overwrite an arbitrary file.
Thanks to Qualys for investigating and reporting this bug.

Also stop performing a breadth-first traversal of /dev when looking
for the device.  Only the directories specified in search_devs[]
are checked.
2017-05-29 14:32:53 -06:00
Todd C. Miller
ad8c1ae07a To avoid overwriting existing command status, check for CMD_INVALID
instead of CMD_ERRNO or CMD_WSTATUS.
2017-05-18 13:53:15 -06:00
Todd C. Miller
c91b6777d3 On HP-UX 11.0, sys/ioctl.h is not sufficient to make struct winsize
visisble, we need termios.h too.
2017-05-15 09:37:58 -06:00
Todd C. Miller
6a8eaef4b8 Move exec_setup(), unlimit_nproc() and restore_nproc() from sudo.c
to exec.c.
2017-05-15 09:01:10 -06:00
Todd C. Miller
befa862f75 No need to include selinux.h here. 2017-05-15 09:00:15 -06:00
Todd C. Miller
d979898e71 Remove use of non-standard sigaction_t 2017-05-12 10:02:18 -06:00
Todd C. Miller
b5c88e52b1 Remove use of the non-standard SA_INTERRUPT 2017-05-12 10:02:17 -06:00
Todd C. Miller
15790b69c2 Add SIGCHLD to the list of signals we install sudo_handler() for.
Otherwise, it is possible for the command to exit before the SIGCHLD
handler is installed.  POSIX says that signals that are ignored by
default are still ignored even if the signal mask would block them.
We need to have a handler installed for SIGCHLD before the fork().
2017-05-12 10:02:17 -06:00
Todd C. Miller
1186f39842 Use SUDO_EV_SIGNAL and SUDO_EV_SIGINFO instead of managing the
signal_pipe explicitly.
2017-05-12 10:02:17 -06:00
Todd C. Miller
e18a5c7d74 Fix a hang introduced in the last commit. Don't close the pty slave
until after we have the controlling tty.
2017-05-05 14:45:35 -06:00
Todd C. Miller
44dc15d02d If any of std{in,out,err} are not hooked up to a tty only interpose
ourselves with a pipe if the plugin will actually log the data.
This avoids a problem with non-interactive commands where no tty
is present where sudo will consume stdin even when log_input is not
enabled in sudoers.
2017-05-05 14:27:42 -06:00
Todd C. Miller
80f8960fc6 Move the invocation of check_noexec into the main "check" target
but only run it if not cross compiling and whe CHECK_NOEXEC is not
empty.
2017-05-03 11:58:40 -06:00
Todd C. Miller
ecbf895097 Move @CHECK_NOEXEC@ to TEST_PROGS so it gets cleaned up properly. 2017-05-03 11:32:56 -06:00
Todd C. Miller
dab8651ed2 We no longer need to write to the tty if the command was killed by
a signal.  Sudo will terminate itself with the same signal the
command died from.  Unfortunately, we lose the "core dumped" bit
since sudo itself will not dump core, but there doesn't appear to
be a way around that.
2017-04-28 10:32:15 -06:00
Todd C. Miller
f57629c953 On Linux, if the command we ran dumped core, set PR_SET_DUMPABLE
to 0.  This will prevent sudo itself from dumping core in this case.
2017-04-27 12:28:08 -06:00
Todd C. Miller
91aec9730e If the command terminated due to a signal, sudo will send that same
signal to itself so the parent shell knows the command died from
a signal.  However, we don't want sudo itself to dump core.
2017-04-27 10:34:30 -06:00
Todd C. Miller
9ee50beaa7 The fix for Bug #722 contained a typo/thinko that resulted in the
exit status being 0 when a command was killed by a signal other
than SIGINT.  This fixes the signal handler setup so sudo will
terminate with the same signal as the command.  Bug #784.
2017-04-26 20:17:34 -06:00
Todd C. Miller
54a23d2c5d Don't install the rc.d link when installing to a DESTDIR.
DESTDIR is generally only set when installing to a temporary
directory for packaging in which case the link should be
made in a post-install script.
2017-04-26 14:49:05 -06:00
Todd C. Miller
9f1afe23fe Use the standard idiom for popping all entries from a tail queue.
The llvm checker gets confused by TAILQ_REMOVE and generate
use-after-free false positives.
2017-04-20 16:13:14 -06:00
Todd C. Miller
c60259bd63 rewrite errpipe callbacks 2017-04-20 16:12:53 -06:00
Todd C. Miller
c2176c32a7 use pipe2() with O_CLOEXEC instead of pipe() + fcntl() and FD_CLOEXEC 2017-04-20 15:10:57 -06:00
Todd C. Miller
6e75179528 init io_pipe[][] to -1, not 0 2017-04-20 15:09:07 -06:00
Todd C. Miller
a245fedc22 Avoid unused variable when getgrouplist_2() is available.
It would be nicer to just provide getgrouplist_2() (or the equivalent)
and avoid the ugly #ifdefs.
2017-04-19 09:39:55 -06:00
Todd C. Miller
d989f8af30 In sudo_ttyname_scan() if dir is the empty string, set errno to
ENOENT before returning.
2017-04-12 17:06:48 -06:00
Todd C. Miller
c6f9f06c45 Check return value of dispatch_pending_signals() in case we received
SIGINT or SIGQUIT before executing the command.
2017-04-07 08:38:56 -06:00
Todd C. Miller
35e4bd3e9f Replace pipe_nonblock() with pipe2() 2017-03-13 12:11:52 -06:00
Todd C. Miller
867fd16343 Move SIGCHLD handling into handle_sigchld() functions and move the
remaining bits of dispatch_signal() into signal_pipe_cb()
2017-03-09 08:36:40 -07:00
Todd C. Miller
78f3f8bb9d e_termination should be set to the value of WTERMSIG not WEXITSTATUS 2017-03-08 09:17:53 -07:00
Todd C. Miller
af1482f487 Add tcsetpgrp_nobg() which acts like tcsetpgrp() but returns -1
for a background process.  This is safer than blocking SIGTTOU
which would cause tcsetpgrp() to succeed in the background.
2017-03-07 12:29:21 -07:00
Todd C. Miller
2f074d33ab Prevent sudo from receiving SIGTTOU when it tries to restore the
controlling terminal.  There appears to be a race with the shell
(bash) which we may lose.
2017-03-06 13:05:17 -07:00
Todd C. Miller
00b4732c9d Add some casts to quiet gcc warnings on Solaris and remove a
now-useless debug printf.
2017-03-03 11:20:56 -07:00
Todd C. Miller
a788144094 change debug info when suspending sudo 2017-03-03 11:20:25 -07:00
Todd C. Miller
6dba84dca9 Reorganize the command execution code to separate out the pty and
non-pty code paths into their own event loops.  The non-pty exec
code is now contained in exec_nopty.c and the pty exec code is split
between exec_pty.c (parent process) and exec_monitor.c (session leader).
This results in a small bit of duplicated code but improves readability.
Some of the duplicated code will fall out in future changes to the
event subsystem (the signal pipe).
2017-03-03 10:35:11 -07:00
Todd C. Miller
4b1f0c4176 Remove support for the TIOCGSIZE ioctl. Systems that use this
rather than TIOCGWINSZ are too old for sudo to build on anyway.
2017-02-26 16:41:25 -07:00
Todd C. Miller
13fcdb4f5f Set the child pid to -1 after we've waited for it and take care to
avoid killing pid -1.  This makes it a bit more explicit and removes
the need for a separate variable to track the child's status.
Sudo already stops processing signals after it receives SIGCHLD so
it is not vulnerable to CVE-2017-2616.
2017-02-24 15:14:56 -07:00
Todd C. Miller
c86a6a23ad Add a command line option to specify the command timeout, as long
as sudoers does not specify a shorter time limit.
2017-02-16 09:58:18 -07:00
Todd C. Miller
dde2b5eb2c Close execfd in parent processes where it is not needed. 2017-01-22 18:56:13 -08:00
Todd C. Miller
2f0295373a When waiting for the parent to grant us the tty, use nanosleep
instead of spinning to avoid hogging the CPU.
2017-01-12 10:44:26 -07:00
Todd C. Miller
0ef26ff0b7 Use ROOT_UID instead of 0 2017-01-12 10:42:26 -07:00
Todd C. Miller
ae76e1a229 Use getgrouplist_2() on macOS if available. 2016-12-13 10:39:32 -07:00
Todd C. Miller
52d6a5e40d Solaris 10 wordexp() returns 127 on execve() failure like popen()
does.
2016-11-30 11:05:42 -07:00