]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-util: use in_same_namespace() 24877/head
authorChristian Brauner <brauner@kernel.org>
Sat, 1 Oct 2022 10:03:25 +0000 (12:03 +0200)
committerChristian Brauner (Microsoft) <brauner@kernel.org>
Tue, 4 Oct 2022 16:51:30 +0000 (18:51 +0200)
Signed-off-by: Christian Brauner (Microsoft) <brauner@kernel.org>
src/shared/mount-util.c

index d6466341384765ed2c21611d6bb08fe13a9082a2..c504ce8feef737224191a9cbaffc4121b64435d9 100644 (file)
@@ -787,13 +787,13 @@ static int mount_in_namespace(
                 bool is_image) {
 
         _cleanup_close_pair_ int errno_pipe_fd[2] = { -1, -1 };
-        _cleanup_close_ int self_mntns_fd = -1, mntns_fd = -1, root_fd = -1, pidns_fd = -1, chased_src_fd = -1;
+        _cleanup_close_ int mntns_fd = -1, root_fd = -1, pidns_fd = -1, chased_src_fd = -1;
         char mount_slave[] = "/tmp/propagate.XXXXXX", *mount_tmp, *mount_outside, *p;
         bool mount_slave_created = false, mount_slave_mounted = false,
                 mount_tmp_created = false, mount_tmp_mounted = false,
                 mount_outside_created = false, mount_outside_mounted = false;
         _cleanup_free_ char *chased_src_path = NULL;
-        struct stat st, self_mntns_st;
+        struct stat st;
         pid_t child;
         int r;
 
@@ -808,18 +808,11 @@ static int mount_in_namespace(
         if (r < 0)
                 return log_debug_errno(r, "Failed to retrieve FDs of the target process' namespace: %m");
 
-        if (fstat(mntns_fd, &st) < 0)
-                return log_debug_errno(errno, "Failed to fstat mount namespace FD of target process: %m");
-
-        r = namespace_open(0, NULL, &self_mntns_fd, NULL, NULL, NULL);
+        r = in_same_namespace(target, 0, NAMESPACE_MOUNT);
         if (r < 0)
-                return log_debug_errno(r, "Failed to retrieve FDs of systemd's namespace: %m");
-
-        if (fstat(self_mntns_fd, &self_mntns_st) < 0)
-                return log_debug_errno(errno, "Failed to fstat mount namespace FD of systemd: %m");
-
+                return log_debug_errno(r, "Failed to determine if mount namespaces are equal: %m");
         /* We can't add new mounts at runtime if the process wasn't started in a namespace */
-        if (stat_inode_same(&st, &self_mntns_st))
+        if (r > 0)
                 return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace");
 
         /* One day, when bind mounting /proc/self/fd/n works across namespace boundaries we should rework