]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: lock down access to notify socket a bit
authorLennart Poettering <lennart@poettering.net>
Fri, 5 Jan 2024 15:41:24 +0000 (16:41 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 6 Jan 2024 02:21:00 +0000 (11:21 +0900)
On Linux only the "w" access bit is necessary to connect to an AF_UNIX
socket, hence let's only set that and nothing else, to limit exposure.

Just paranoia.

src/nspawn/nspawn.c

index 53e49c4b36c6f9230d591b25e515d6dbb1298b62..839b90cc5dde95bdd72799452fbeb1fc87331b52 100644 (file)
@@ -3593,9 +3593,11 @@ static int setup_notify_child(void) {
         (void) mkdir_parents(NSPAWN_NOTIFY_SOCKET_PATH, 0755);
         (void) sockaddr_un_unlink(&sa.un);
 
-        r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
-        if (r < 0)
-                return log_error_errno(errno, "bind(" NSPAWN_NOTIFY_SOCKET_PATH ") failed: %m");
+        WITH_UMASK(0577) { /* only set "w" bit, which is all that's necessary for connecting from the container */
+                r = bind(fd, &sa.sa, SOCKADDR_UN_LEN(sa.un));
+                if (r < 0)
+                        return log_error_errno(errno, "bind(" NSPAWN_NOTIFY_SOCKET_PATH ") failed: %m");
+        }
 
         r = userns_lchown(NSPAWN_NOTIFY_SOCKET_PATH, 0, 0);
         if (r < 0)