aboutgitcodebugslistschat
path: root/tap.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 /tap.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 'tap.c')
-rw-r--r--tap.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/tap.c b/tap.c
index c9f580e..2ea0849 100644
--- a/tap.c
+++ b/tap.c
@@ -1100,7 +1100,7 @@ restart:
*
* Return: socket descriptor on success, won't return on failure
*/
-static int tap_sock_unix_open(char *sock_path)
+int tap_sock_unix_open(char *sock_path)
{
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
struct sockaddr_un addr = {
@@ -1144,7 +1144,7 @@ static int tap_sock_unix_open(char *sock_path)
if (i == UNIX_SOCK_MAX)
die("UNIX socket bind: %s", strerror(errno));
- info("UNIX domain socket bound at %s\n", addr.sun_path);
+ info("UNIX domain socket bound at %s", addr.sun_path);
if (!*sock_path)
memcpy(sock_path, addr.sun_path, UNIX_PATH_MAX);
@@ -1167,7 +1167,7 @@ static void tap_sock_unix_init(struct ctx *c)
ev.data.u64 = ref.u64;
epoll_ctl(c->epollfd, EPOLL_CTL_ADD, c->fd_tap_listen, &ev);
- info("You can now start qemu (>= 7.2, with commit 13c6be96618c):");
+ info("\nYou can now start qemu (>= 7.2, with commit 13c6be96618c):");
info(" kvm ... -device virtio-net-pci,netdev=s -netdev stream,id=s,server=off,addr.type=unix,addr.path=%s",
c->sock_path);
info("or qrap, for earlier qemu versions:");
@@ -1318,7 +1318,6 @@ void tap_sock_init(struct ctx *c)
}
if (c->mode == MODE_PASST) {
- c->fd_tap_listen = tap_sock_unix_open(c->sock_path);
tap_sock_unix_init(c);
/* In passt mode, we don't know the guest's MAC address until it