aboutgitcodebugslistschat
path: root/passt.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2024-05-22 20:18:19 +0200
committerStefano Brivio <sbrivio@redhat.com>2024-05-23 16:43:26 +0200
commitc9b24134656925e53fea3cde0b33ab143dcd84af (patch)
tree4f07d74f760664e7a11ad5bd8ba4dac14b398089 /passt.c
parentba23b05545e1e316235fad7a66f3cfd643c22146 (diff)
downloadpasst-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 'passt.c')
-rw-r--r--passt.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/passt.c b/passt.c
index e2446fc..a8c4cd3 100644
--- a/passt.c
+++ b/passt.c
@@ -199,9 +199,9 @@ void exit_handler(int signal)
*/
int main(int argc, char **argv)
{
- int nfds, i, devnull_fd = -1, pidfile_fd;
struct epoll_event events[EPOLL_EVENTS];
char *log_name, argv0[PATH_MAX], *name;
+ int nfds, i, devnull_fd = -1;
struct ctx c = { 0 };
struct rlimit limit;
struct timespec now;
@@ -211,7 +211,7 @@ int main(int argc, char **argv)
isolate_initial();
- c.pasta_netns_fd = c.fd_tap = -1;
+ c.pasta_netns_fd = c.fd_tap = c.pidfile_fd = -1;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
@@ -299,8 +299,6 @@ int main(int argc, char **argv)
}
}
- pidfile_fd = pidfile_open(c.pid_file);
-
if (isolate_prefork(&c))
die("Failed to sandbox process, exiting");
@@ -308,9 +306,9 @@ int main(int argc, char **argv)
__openlog(log_name, 0, LOG_DAEMON);
if (!c.foreground)
- __daemon(pidfile_fd, devnull_fd);
+ __daemon(c.pidfile_fd, devnull_fd);
else
- pidfile_write(pidfile_fd, getpid());
+ pidfile_write(c.pidfile_fd, getpid());
if (pasta_child_pid)
kill(pasta_child_pid, SIGUSR1);