Commit Graph

1055 Commits

Author SHA1 Message Date
Todd C. Miller
d5d170252a In pty_cleanup() we need to call sudo_term_restore() even if no I/O
plugins are present as long as /dev/tty exists.  Fixes the use_pty
case with no I/O plugins.
2018-02-19 11:00:12 -07:00
Todd C. Miller
42fe0409f6 Add sudo_ev_dispatch(), a wrapper for ev_loop() with no flags.
Similar the dispatch function in libevent.
2018-02-19 11:00:10 -07:00
Todd C. Miller
a885b952fb Remove use of AC_HEADER_TIME, only obsolete platforms actually
need this.  Also stop removing sys/time.h unless the source file
uses struct timeval.
2018-01-17 09:52:15 -07:00
Todd C. Miller
ff5ac3ef0e Add tsdump, a simple utility to dump a timestamp file. To build,
run "make tsdump" in the plugins/sudoers directory (it is not built
by default).  In order to map the tty device number to a name,
sudo_ttyname_dev() has been moved into libsudo_util.
2018-01-11 10:49:20 -07:00
Todd C. Miller
cd0b700543 No need for a loop around the recv() now that we don't have to worry
about EINTR.  CID 180697
2017-12-12 21:44:23 -07:00
Todd C. Miller
5106bfc139 Allow the plugin to determine whether or not an empty timeout is
allowed.  For sudoers, an error will be returned for an empty timeout.
2017-12-11 09:20:41 -07:00
Todd C. Miller
bbc43b5e30 Change some _() into U_() since they are used for warn/fatal.
We always want to issue warnings in the user's locale.
2017-12-11 08:07:01 -07:00
Todd C. Miller
d322caf7ac Print usage and return an error when an empty argument is given for
all command line arguments other than -p and -E.  Bug #817
2017-12-10 07:53:09 -07:00
Todd C. Miller
48fba3c2cc update my email to Todd.Miller@sudo.ws 2017-12-03 17:53:40 -07:00
Todd C. Miller
a2eff11509 Track window size changes that happen while sudo is suspended 2017-12-02 21:30:11 -07:00
Todd C. Miller
b561d0d7dd When the command completes, make the monitor the foreground process
group before informing the main sudo process of the command's exit
status.  This will prevent processes started by the command (which
runs in a different process group) from receiving SIGHUP since the
kernel sends SIGHUP to the foreground process group associated with
the terminal session.  The monitor has a SIGHUP handler installed
so the signal is effectively ignored.
2017-12-01 13:43:06 -07:00
Todd C. Miller
4168668f53 Add debug printfs around group list retrieval. 2017-12-01 12:58:37 -07:00
Todd C. Miller
116c5d7eff Move call to sudo_ev_loopcontinue() into schedule_signal() itself.
We always want to prioritize signal forwarding.
2017-11-30 10:02:15 -07:00
Todd C. Miller
b9adb3dd51 Don't loop over read/write, recv/send or tcgetpgrp/tcsetpgrp trying
to handle EINTR.  We now use SA_RESTART with signals so this is not
needed and is potentially dangerous if it is possible to receive
SIGTTIN or SIGTTOU (which it currently is not).
2017-11-30 09:53:21 -07:00
Todd C. Miller
486ced7c11 Sprinkle some extra debugging printfs 2017-11-29 13:13:33 -07:00
Todd C. Miller
54acf4f991 Handle receipt of SIGTTIN/SIGTTOU when reading/writing from/to the tty.
We can't use a signal event for these since that would restart the
system call after the signal was handled and the callback would not
get a chance to run.  Fixes running a command in the background that
write to the tty when the TOSTOP terminal flag is set.
2017-11-29 12:06:12 -07:00
Todd C. Miller
5ccc7ab879 We don't need to be the foreground process to be able to write to
the terminal in most cases.  If the background process tries to
modify the terminal flags it will receive SIGTTOU which is relayed
to the sudo front-end.  This currently mishandles terminals with
the TOSTOP local flag set.
2017-11-29 12:06:12 -07:00
Todd C. Miller
3b88cdfcd8 Fix stair-stepped output when the output of a sudo command is piped
to another command and use_pty is set.
2017-09-26 14:21:11 -06:00
Todd C. Miller
8949992040 Set ec->cmnd_pid to the correct value when receiving the command's
process ID from the monitor.
2017-09-07 13:22:10 -06:00
Todd C. Miller
84af812b8c If /dev/tty is not available and no I/O logging plugins are configured,
fall back on exec_nopty() even if the policy plugin requested a pty.
We never allocate a pty when sudo is not run from a terminal anyway.
2017-09-07 11:32:30 -06:00
Todd C. Miller
2c2476f07f Do not set utmp_user if we did not actually allocate a pty. 2017-09-07 11:00:19 -06:00
Todd C. Miller
d85056d95f sudo_terminated() should not return true when SIGCHLD is pending.
Bug #801
2017-09-06 16:08:23 -06:00
Todd C. Miller
4b5aeefebc Set SIGCHLD handler to SIG_DFL before forking the askpass command
and restore after.  Otherwise, SIGCHLD will end up in the list of
pending signals and sudo_execute() will not execute the command.
2017-09-06 15:59:37 -06:00
Todd C. Miller
c3d098254d Don't forward SIGINFO to the child when it is send by the kernel
(not another user process).  This is consistent with the handling
of other keyboard-generated signals such as SIGINT, SIGQUIT and
SIGTSTP.  Bug #796
2017-08-29 08:58:14 -06:00
Todd C. Miller
c18dde2350 Allow the user to specify a list of environment variables to preserve.
This adds an option paramter to the --preserve-env option, a
comma-separated list of variable names.
2017-08-03 07:32:24 -06:00
Todd C. Miller
0849e2cac4 No need to call sudo_ev_del() before sudo_ev_free(); sudo_ev_free()
will delete the event from its base before freeing it.
2017-07-27 14:12:57 -06:00
Todd C. Miller
1cfaf6c344 Terminate the command if an I/O log function returns 0 or -1. This
was mistakenly removed by 25b7fd056614 in Sudo 1.8.18 with the
removal of the ignore_iolog_errors variable.
2017-07-27 14:10:44 -06:00
Todd C. Miller
7f8765d327 If we free the default base in sudo_ev_base_free(), reset the default
base to NULL.
2017-07-14 10:09:58 -06:00
Todd C. Miller
d2a0bfbb12 Add the ability to set a default event base, to be used by plugins
which don't have access to the event base.
2017-07-13 13:59:31 -06:00
Todd C. Miller
8898ec1f9c Pass window size change events to the plugin. 2017-07-12 05:47:28 -06:00
Todd C. Miller
e70a953fb4 Remove pointless subshells in targets that simply change the directory
and execute a command.  The command is already run in a shell so
there is no need to execute a subshell in this case.
2017-07-12 05:45:46 -06:00
Todd C. Miller
a7759b6261 Store the debug instance ID for I/O plugins too.
Now iolog_open() is consistent with policy_open().
2017-07-10 16:28:10 -06:00
Todd C. Miller
6d4d4594b7 Use _PATH_DEV consistently 2017-06-29 18:10:53 -06:00
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