]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: if /proc/ is mounted, return -EBADF when appropriate for link_fd()
authorMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 03:05:29 +0000 (11:05 +0800)
committerMike Yuan <me@yhndnzj.com>
Tue, 21 May 2024 16:50:44 +0000 (00:50 +0800)
src/basic/fs-util.c

index 13995cf7a74a0a9dd6e5fa03fe5f7a2aa7631187..6df53cb0c4c00310df1c1ef6680c79162e89e5fb 100644 (file)
@@ -1242,7 +1242,7 @@ int xopenat_lock_full(
 }
 
 int link_fd(int fd, int newdirfd, const char *newpath) {
-        int r;
+        int r, k;
 
         assert(fd >= 0);
         assert(newdirfd >= 0 || newdirfd == AT_FDCWD);
@@ -1255,8 +1255,11 @@ int link_fd(int fd, int newdirfd, const char *newpath) {
 
         /* Fall back to symlinking via AT_EMPTY_PATH as fallback (this requires CAP_DAC_READ_SEARCH and a
          * more recent kernel, but does not require /proc/ mounted) */
-        if (proc_mounted() != 0)
+        k = proc_mounted();
+        if (k < 0)
                 return r;
+        if (k > 0)
+                return -EBADF;
 
         return RET_NERRNO(linkat(fd, "", newdirfd, newpath, AT_EMPTY_PATH));
 }