diff options
author | Stefano Brivio <sbrivio@redhat.com> | 2024-05-22 20:18:19 +0200 |
---|---|---|
committer | Stefano Brivio <sbrivio@redhat.com> | 2024-05-23 16:43:26 +0200 |
commit | c9b24134656925e53fea3cde0b33ab143dcd84af (patch) | |
tree | 4f07d74f760664e7a11ad5bd8ba4dac14b398089 /conf.c | |
parent | ba23b05545e1e316235fad7a66f3cfd643c22146 (diff) | |
download | passt-c9b24134656925e53fea3cde0b33ab143dcd84af.tar passt-c9b24134656925e53fea3cde0b33ab143dcd84af.tar.gz passt-c9b24134656925e53fea3cde0b33ab143dcd84af.tar.bz2 passt-c9b24134656925e53fea3cde0b33ab143dcd84af.tar.lz passt-c9b24134656925e53fea3cde0b33ab143dcd84af.tar.xz passt-c9b24134656925e53fea3cde0b33ab143dcd84af.tar.zst passt-c9b24134656925e53fea3cde0b33ab143dcd84af.zip |
conf, passt, tap: Open socket and PID files before switching UID/GID
Otherwise, if the user runs us as root, and gives us paths that are
only accessible by root, we'll fail to open them, which might in turn
encourage users to change permissions or ownerships: definitely a bad
idea in terms of security.
Reported-by: Minxi Hou <mhou@redhat.com>
Reported-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
Diffstat (limited to 'conf.c')
-rw-r--r-- | conf.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -38,6 +38,7 @@ #include "ip.h" #include "passt.h" #include "netlink.h" +#include "tap.h" #include "udp.h" #include "tcp.h" #include "pasta.h" @@ -1093,7 +1094,7 @@ static void conf_ugid(char *runas, uid_t *uid, gid_t *gid) return; /* ...otherwise use nobody:nobody */ - warn("Started as root. Changing to nobody..."); + warn("Started as root, will change to nobody."); { #ifndef GLIBC_NO_STATIC_NSS const struct passwd *pw; @@ -1114,6 +1115,18 @@ static void conf_ugid(char *runas, uid_t *uid, gid_t *gid) } /** + * conf_open_files() - Open files as requested by configuration + * @c: Execution context + */ +static void conf_open_files(struct ctx *c) +{ + if (c->mode == MODE_PASST && c->fd_tap == -1) + c->fd_tap_listen = tap_sock_unix_open(c->sock_path); + + c->pidfile_fd = pidfile_open(c->pid_file); +} + +/** * conf() - Process command-line arguments and set configuration * @c: Execution context * @argc: Argument count @@ -1712,6 +1725,8 @@ void conf(struct ctx *c, int argc, char **argv) else if (optind != argc) die("Extra non-option argument: %s", argv[optind]); + conf_open_files(c); /* Before any possible setuid() / setgid() */ + isolate_user(uid, gid, !netns_only, userns, c->mode); if (c->pasta_conf_ns) |