Sub topic 5
Filesystem hardening: kernel modules, partitions, and mount options
Assume you can use sudo, edit configuration files, and recover a test server from a console or snapshot. Filesystem hardening reduces the damage caused by unwanted software, unsafe device files, and accidental writes. Apply changes gradually because a bad mount entry can prevent boot.
Decide what the server needs
Start with the server's workload. Do not disable a filesystem or module only because a benchmark lists it. A storage server, container host, and web server have different requirements.
CIS recommendations commonly address:
- Unused filesystem kernel modules, such as
cramfs,squashfs, orudf. - Separate partitions for directories that commonly receive files, such as
/tmp,/var,/var/log, and/var/log/audit. - Mount options that limit what files on a filesystem can do.
| Option | Effect | Typical purpose |
|---|---|---|
| `nosuid` | Ignores set-user-ID and set-group-ID bits | Reduces privilege escalation through files |
| `nodev` | Does not interpret device files | Prevents device nodes on data-only filesystems |
| `noexec` | Blocks direct execution from the mount | Limits execution from temporary storage |
These options are useful controls, not complete security boundaries. For example, noexec does not stop an interpreter from reading a script.
Disable an unused kernel module
A kernel module is code that the Linux kernel can load while running. If the server never needs a filesystem, preventing its module from loading reduces attack surface.
For a RHEL-like system, create a modprobe configuration file:
# /etc/modprobe.d/cramfs.conf
install cramfs /bin/false
blacklist cramfs
# Verify the module is not loaded and inspect the load override
lsmod | grep cramfs || true
sudo modprobe -n -v cramfsThe install rule replaces a normal module load with a failed command. The blacklist rule also prevents automatic loading by common discovery mechanisms. Test this on a server that does not use the filesystem. A module may already be built into the kernel, in which case blacklisting cannot remove it.
Use separate filesystems and restrictive mounts
Separate partitions limit how much disk space one directory can consume. They also let you apply different mount options. Before changing /etc/fstab, record the current layout:
findmnt
lsblk -f
df -hTA temporary filesystem can be mounted on /tmp with common restrictions:
# /etc/fstab
tmpfs /tmp tmpfs defaults,rw,nosuid,nodev,noexec,relatime,size=2G 0 0Validate the entry, then apply it:
sudo mount -a
findmnt --target /tmpKeep an administrative console or a second SSH session available. Some applications need to execute helpers from /tmp, and some installers expect device files there. Test application behavior after each change.
Exercise
Why should you inspect an application's behavior before applying noexec to /tmp?
Show answer
Some applications and installers execute helper programs from /tmp; noexec can make those operations fail even though it improves containment.