diff --git a/bind-mount.c b/bind-mount.c index a7a729dd..defc1df4 100644 --- a/bind-mount.c +++ b/bind-mount.c @@ -24,6 +24,11 @@ #include "utils.h" #include "bind-mount.h" +/* MS_NOSYMFOLLOW was added in Linux 5.10 */ +#ifndef MS_NOSYMFOLLOW +#define MS_NOSYMFOLLOW 256 +#endif + static char * skip_token (char *line, bool eat_whitespace) { @@ -93,6 +98,7 @@ decode_mountoptions (const char *options) { MS_NOSUID, "nosuid" }, { MS_NODEV, "nodev" }, { MS_NOEXEC, "noexec" }, + { MS_NOSYMFOLLOW, "nosymfollow" }, { MS_NOATIME, "noatime" }, { MS_NODIRATIME, "nodiratime" }, { MS_RELATIME, "relatime" }, diff --git a/tests/test-run.sh b/tests/test-run.sh index 2d0d307d..6e1167a9 100755 --- a/tests/test-run.sh +++ b/tests/test-run.sh @@ -91,6 +91,12 @@ else fi ok "--symlink doesn't overwrite a conflicting symlink" +# A nosymfollow source must stay nosymfollow across the fixup remount +if unshare -rm sh -c 'mount -t tmpfs -o nosymfollow tmpfs /tmp && : >/tmp/x && ln -s x /tmp/l && '"$BWRAP"' --ro-bind / / cat /tmp/l' 2>/dev/null; then + assert_not_reached "nosymfollow dropped by bind fixup; symlink was followed" +fi +ok "bind mount preserves nosymfollow" + # Test devices $RUN --unshare-pid --dev /dev ls -al /dev/{stdin,stdout,stderr,null,random,urandom,fd,core} >/dev/null ok "all expected devices were created"