mount: Support "nosymfollow" in new mount api
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 1 Jun 2021 09:33:59 +0000 (11:33 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 1 Jun 2021 10:09:27 +0000 (12:09 +0200)
Commit dab741e0e02b ("Add a "nosymfollow" mount option.") added support
for the "nosymfollow" mount option allowing to block following symlinks
when resolving paths. The mount option so far was only available in the
old mount api. Make it available in the new mount api as well. Bonus is
that it can be applied to a whole subtree not just a single mount.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Mattias Nissler <mnissler@chromium.org>
Cc: Aleksa Sarai <cyphar@cyphar.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Ross Zwisler <zwisler@google.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
fs/namespace.c
include/uapi/linux/mount.h

index c3f1a78ba36977054f1acaf79889af664d664588..ab4174a3c802b5c5c61787f50e1765b30cb3bc6a 100644 (file)
@@ -3464,9 +3464,10 @@ out_type:
        return ret;
 }
 
-#define FSMOUNT_VALID_FLAGS \
-       (MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOSUID | MOUNT_ATTR_NODEV | \
-        MOUNT_ATTR_NOEXEC | MOUNT_ATTR__ATIME | MOUNT_ATTR_NODIRATIME)
+#define FSMOUNT_VALID_FLAGS                                                    \
+       (MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOSUID | MOUNT_ATTR_NODEV |            \
+        MOUNT_ATTR_NOEXEC | MOUNT_ATTR__ATIME | MOUNT_ATTR_NODIRATIME |       \
+        MOUNT_ATTR_NOSYMFOLLOW)
 
 #define MOUNT_SETATTR_VALID_FLAGS (FSMOUNT_VALID_FLAGS | MOUNT_ATTR_IDMAP)
 
@@ -3487,6 +3488,8 @@ static unsigned int attr_flags_to_mnt_flags(u64 attr_flags)
                mnt_flags |= MNT_NOEXEC;
        if (attr_flags & MOUNT_ATTR_NODIRATIME)
                mnt_flags |= MNT_NODIRATIME;
+       if (attr_flags & MOUNT_ATTR_NOSYMFOLLOW)
+               mnt_flags |= MNT_NOSYMFOLLOW;
 
        return mnt_flags;
 }
index e6524ead2b7b9ead2cd5fa20435dd0ce2ecbe158..dd7a166fdf9c2c089d5b3672746ca8b58b9853c1 100644 (file)
@@ -120,6 +120,7 @@ enum fsconfig_command {
 #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
 #define MOUNT_ATTR_NODIRATIME  0x00000080 /* Do not update directory access times */
 #define MOUNT_ATTR_IDMAP       0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
+#define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */
 
 /*
  * mount_setattr()