Commit Graph

153 Commits

Author SHA1 Message Date
Todd C. Miller
304726a215 Move gcc-style __attribute__ macros to config.h.in
Renamed __malloc -> sudo_malloclike, __printflike -> sudo_printflike,
__printf0like -> sudo_printf0like.
Add sudo_noreturn instead of __attribute__((__noreturn__)).
We do not use stdnoreturn.h since it has been deprecated in C23
in favor of the [[noreturn]] attribute.
2022-09-07 07:48:31 -06:00
Todd C. Miller
556dacf1ff Add a way to run a command without updating the cached credentials.
This can also be used to test for whether or not the user's
credentials are currently cached.
2022-08-02 14:28:28 -06:00
Todd C. Miller
cf250354fc Defer chdir(2) until sesh when running with SELinux.
We need to be running with the correct security context or the
chdir(2) may fail.  GitHub issue #160.
2022-08-01 13:40:47 -06:00
Todd C. Miller
3ce19efca9 Add intercept_verify sudoers option to control execve(2) argument checking. 2022-07-29 15:22:27 -06:00
Todd C. Miller
f5ac1317c4 Make sudo pass -Wmissing-prototypes 2022-06-27 12:48:03 -06:00
Todd C. Miller
f16754a1dd Merge branch 'main' into apparmor_support 2022-05-27 08:25:12 -06:00
Todd C. Miller
f053f174bc Add intercept_type sudoers option to set intercept/log_subcmds mechanism. 2022-05-24 13:39:28 -06:00
kernelmethod
bd25b85a66 Add an apparmor_profile sudo setting
Define a new sudo setting, `apparmor_profile`, that can be used to pass
in an AppArmor profile that should be used to confine commands. If
apparmor_profile is specified, sudo will execute the command using the
new `apparmor_execve` function, which confines the command under the
provided profile before exec'ing it.
2022-05-23 13:41:42 -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
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
01733a5214 Add scaffolding for ptrace-based intercept mode. 2022-04-29 12:35:31 -06:00
Todd C. Miller
74ef983f60 Add front-end support for setting resouce limits.
The special value "user" means preserve the invoking user's limit.
The value "default" means don't override the default limit for the
user as assigned by the system (PAM, loging.conf, userdb, etc).
2021-11-08 18:21:11 -07:00
Todd C. Miller
22d624c028 Rename selinux_setcon -> selinux_setexeccon 2021-11-05 12:34:03 -06:00
Todd C. Miller
e97fb5fd0b Separate out the code to compute the context from selinux_setup().
This makes it possible to determine whether we really need to execute
the command via the sesh helper.  What was left of selinux_setup()
is now selinux_relabel_tty() and selinux_audit_role_change().
2021-11-05 12:33:20 -06:00
Todd C. Miller
ba171724f7 Rename log_children -> log_subcmds 2021-08-26 16:36:41 -06:00
Todd C. Miller
42598735d0 Call the approval plugin after the policy plugin accepts a command.
Previously, for intercepted commands we only called the policy plugin.
2021-08-09 15:50:25 -06:00
Todd C. Miller
840bf4b09d Add return values for most of the plugin function wrappers that returned void.
Previously, they would just exit if there was an error.
Now the error is passed back up the stack so we can use them in
sudo_intercept.so.
2021-08-09 15:50:25 -06:00
Todd C. Miller
d7380bb271 Implement the sudo side of the sudo_intercept.so communication. 2021-08-09 15:50:25 -06:00
Todd C. Miller
6287e8ca7d Add support for loading the sudo_intercept.so DSO. 2021-08-09 15:50:25 -06:00
Todd C. Miller
ece5adc662 Add struct sudo_cred to hold the invoking or runas user credentials.
We can use this when we need to pass around credential info instead
of the user_details and command_details structs.
2021-01-06 13:01:09 -07:00
Todd C. Miller
24d812d037 Pass command_info[] to audit plugin on I/O log plugin reject or error.
The audit plugin should cope with a NULL command_info but there's no
reason not to pass the info when we have it.
2020-11-17 13:15:15 -07:00
Todd C. Miller
c4a579cf8a Pass resource limits values to the plugin in user_info[]
Sudo resets the resource limits early in its execution so
the plugin cannot tell what the original limits were itself.
2020-08-31 16:37:01 -06:00
Todd C. Miller
076d0376db We no longer need to include sudo_gettext.h before sudo_compat.h 2020-08-12 09:50:35 -06:00
Todd C. Miller
8bb5aedacf Replace master/slave in code with leader/follower. 2020-06-15 16:21:32 -06:00
Todd C. Miller
4dba87262a Look up runas user by name, not euid, where possible.
Fixes a problem when there are multiple users with the same user-ID
where the PAM session modules could be called with the wrong user name.
Debian bug #734752
2020-05-06 16:38:08 -06:00
Todd C. Miller
76bf9a73bc Fix sudoedit when running with SELinux RBAC mode.
We can't use run_command() to run sesh, that will use the sudo event
loop (and might run it in a pty!).
There's no need to relabel the tty when copying files.
Get the path to sesh from sudo.conf.

Currently, for SELinux RBAC, the editor runs with the target user's
security context. This defeats the purpose of sudoedit.  Fixing
that requires passing file descriptors between the main sudo process
(running with the invoking user's security context) and sesh (runnning
with the target user's security context).
2020-04-21 14:29:23 -06:00
Todd C. Miller
93aa9f9e90 Add cwd_optional to command details and enable it in the sudoers plugin.
If cwd_optional is set to true, a failure to set the cwd will be a
warning, not an error, and the command will still run.
Debian bug #598519
2020-03-31 19:43:48 -06:00
Todd C. Miller
c5afbf00fc Mark main sudo usage() function __noreturn__.
This splits the usage printing out into display_usage().
2020-02-08 12:17:33 -07:00
Todd C. Miller
22105009d8 Define a new plugin type that receives accept and reject messages.
This can be used to implement logging-only plugins.
The plugin functions now take an errstr argument that can be used
to return an error string to be logged on failure or error.
2020-01-30 13:25:34 -07:00
Todd C. Miller
5793023ffd Add a plugin interface to sudo main event loop. 2019-11-15 13:36:01 -07:00
Todd C. Miller
059b55ce72 Refactor code in sudoers that creates I/O log files to share with logsrvd. 2019-10-24 20:04:31 -06:00
Todd C. Miller
e80079eaa8 Set resource limits in the sudo process to unlimited.
We don't want sudo to be limited by the caller's resource limits.
The original resource limits are restore before session setup.
2019-10-21 11:41:48 -06:00
Todd C. Miller
b02851dcf3 Change how the umask is handled with PAM and login.conf.
If the umask is explicitly set in sudoers, use that value regardless
of what is in PAM or login.conf.  If using the default umask from
sudoers, allow PAM or login.conf to override it.  Bug #900
2019-10-18 06:20:27 -06:00
Todd C. Miller
112dff276a Fix restoring the file context of the user's tty with SELinux.
Also fix broken tty labeling when running a command in a pty.
Includes a fix for a typo introduced in the last change set.
2019-09-27 15:32:49 -06:00
Todd C. Miller
d94798e5d0 Enable asserts for Coverity too. 2019-08-30 14:05:03 -06:00
Todd C. Miller
ffaef7939a Add asserts() to avoid static analyzer false positives. 2019-08-30 11:13:35 -06:00
Todd C. Miller
19c548fd57 Add -B option to ring the bell before the password prompt. 2019-05-27 08:49:43 -06:00
Todd C. Miller
1e1ef61902 Add SPDX-License-Identifier to files. 2019-04-29 07:21:51 -06:00
Todd C. Miller
c0a12d9d95 Be sure to include sudo_queue.h where needed instead of relying on other headers. 2019-02-19 08:31:08 -07:00
Todd C. Miller
e2570307e6 Initialize the pty rows/cols based on the values we stored in user_details.
This fixes a minor issue where we would send an extra window size
change event the first time the command was suspended.
2018-10-05 14:04:29 -06:00
Todd C. Miller
6953e7fc79 Move updating of the window size to the monitor process.
This will allow us to close the slave in the main sudo process in
the future so only the command and monitor have it open.
2018-08-20 10:04:14 -06:00
Todd C. Miller
48fba3c2cc update my email to Todd.Miller@sudo.ws 2017-12-03 17:53:40 -07: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
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
35e4bd3e9f Replace pipe_nonblock() with pipe2() 2017-03-13 12:11:52 -06: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
efe957544f Add the argument vector allocated for -s and -i mode to the garbage
collector list.  Avoids an ASAN warning on exit when the -s or -i
flags are used.
2016-11-10 10:11:18 -07:00
Todd C. Miller
3e4c7eed31 Move the ignoring of I/O log plugin errors into the I/O log plugin
itself.
2016-08-17 14:38:00 -06:00
Todd C. Miller
ed18d0d5f8 Make the behavior when we cannot write to a log or audit file
configurable.  File log failures are ignored by default for consistency
with syslog.  Audit errors are ignored by default to allow the admin
to fix the issue.  I/O log file errors are still fatal by default
since if I/O logging is activated it is usually to have an audit trail.
Bug #751
2016-08-17 07:22:51 -06:00