Does the noexec mount option imply nosuid

executablemountsetuid

Many guides on the internet recommend setting the nosuid and noexec options, for example on the /tmp mount point. But doesn't noexec imply nosuid? What cannot get executed cannot make use of the suid bit, right?

Best Answer

Thanks for the link LJKims, it helps me to answer my own question. I forgot that the suid/sgid bit can also be set for directories.

According to the GNU coreutils documentation files and directories that are created in a suid-directory inherit the owner of the directory (sgid-directories inherit the group obviously). So, if you want to avoid this behaviour, setting both noexec and nosuid on a mount point makes sense.

For completeness: in my tests on a current Debian, the suid bit on directories takes no effect, but only the sgid bit makes files/directories inherit the group of the directory.

# mkdir /test
# chmod 6777 /test
# ls -ld /test
drwsrwsrwx 2 root root 4096 Jun 10 18:50 /test
$ mkdir /test/foo; touch /test/bar
$ ls -l /test
-rw-r--r-- 1 user root    0 Jun 10 18:51 bar
drwxr-sr-x 2 user root 4096 Jun 10 18:51 foo

Edit: For completeness: The nosuid mount option does not affect sgid-directories (on Debian 8 at least).

# mount -o loop,nosuid test.img /test
# mkdir /test/foo
# chmod 2777 /test/foo
$ touch /test/foo/bar; mkdir /test/foo/baz
$ ls -l /test/foo
-rw-r--r-- 1 user root    0 Jun 12 09:46 bar
drwxr-sr-x 2 user root 4096 Jun 12 09:46 baz