Linux Mount Options Explained: nosuid, noexec, nodev — Stop Attacks at the Filesystem


Most Linux hardening guides jump straight to firewalls and passwords. But some of the cheapest security wins on a Linux system live in a file most beginners never touch: /etc/fstab. Three mount options — nosuid, noexec and nodev — can stop whole classes of attacks at the filesystem level, before they ever reach your applications.

What Mount Options Are

When Linux mounts a filesystem, it applies a set of rules to that mount point. Those rules are the mount options, and they control what is allowed to happen inside that filesystem. You can see the current options for every mount with:

mount | column -t

Or check a single one:

findmnt /tmp

The options are set in /etc/fstab, one line per filesystem, in the fourth column. Change them, remount, and the new rules apply immediately.

nosuid: Ignore Setuid Bits

The suid bit lets a program run with the privileges of its owner instead of the user who launched it. That is how sudo and passwd work — and it is also how privilege escalation happens. If an attacker can place a setuid-root binary on a writable filesystem and run it, they get root.

nosuid tells the kernel to ignore setuid bits on that filesystem entirely. A setuid binary sitting on a nosuid mount runs as a normal user, no matter what its permissions say. It belongs on every filesystem where users can write files: /tmp, /var/tmp, /home, and any shared or removable mounts. System directories like /usr and /bin keep suid because tools like sudo genuinely need it.

noexec: Nothing Runs From Here

noexec blocks execution of any binary on that filesystem. Scripts, compiled programs, downloaded malware — nothing runs directly from a noexec mount. This is the option that stops the classic attack of dropping a malicious binary into /tmp and executing it, because /tmp is world-writable on almost every Linux system.

Put noexec on /tmp, /var/tmp, /dev/shm and /home. Note the limit: noexec stops direct execution, but an attacker can still run a script through its interpreter — bash /tmp/evil.sh works even on a noexec mount, because bash itself is the program running. noexec is a layer, not a wall. Combine it with the other options and with good permissions.

nodev: No Devices Allowed

Unix devices live in /dev, and a device file gives direct access to hardware. nodev tells the kernel to ignore device files on that filesystem, so even if someone creates a device node there, it does nothing. This matters on writable filesystems: without nodev, an attacker with write access could create a device node pointing at your disk and read raw data straight off it.

nodev belongs on /tmp, /var/tmp, /home, /dev/shm and any user-writable or removable mount. Only /dev itself needs device files.

Putting It Together in fstab

A hardened /etc/fstab entry for /tmp looks like this:

tmpfs /tmp tmpfs defaults,nosuid,noexec,nodev 0 0

And for a separate /home partition:

UUID=xxxx-xxxx /home ext4 defaults,nosuid,nodev 0 2

Note that /home usually does not get noexec, because some users legitimately run programs from their home directory — decide based on your system. After editing fstab, always verify the syntax before rebooting:

sudo findmnt --verify

Then apply the new options without a reboot:

sudo mount -o remount /tmp

Confirm with findmnt /tmp — you should see nosuid,noexec,nodev in the options list.

Test It Yourself

You can verify the protection works in seconds. On a noexec /tmp, try:

echo 'echo pwned' > /tmp/test.sh
chmod +x /tmp/test.sh
/tmp/test.sh

You will get a "Permission denied" error. That is the mount option doing its job. Now try the same on a normal directory and it runs — the difference is one word in fstab.

Remember the golden rule: only test systems you own or have written permission to test. These options are for your own servers and your own lab. Apply them there, verify them with the test above, and you have closed three attack paths with three words.

 

Comments

Popular Posts