Description
/dev/shm is the tmpfs used for POSIX shared memory. systemd mounts it at boot with nodev and
nosuid. This control also requires noexec, set through a /dev/shm line in /etc/fstab
that systemd applies at boot.
Rationale
Every user can write to /dev/shm, and its content never reaches the disk. Attackers use it to
store and run tools while leaving few traces. noexec blocks direct execution, nosuid and
nodev stop setuid files and device nodes placed there from being used.
Impact
Programs that map executable code from files in /dev/shm fail. This is rare (some JIT engines
and old database software); check vendor requirements before applying on such systems.
Setting
| Location | /etc/fstab |
| Default | nodev,nosuid (no noexec) |
| Recommended | nodev,nosuid,noexec |
Audit
Run findmnt -kn /dev/shm. Its options must contain nodev, nosuid and noexec.
Automated: every check must pass. Scanners report each check by its id.
mount
/dev/shm is a mount point and its options include nodev, nosuid and noexec.
script: |
o=$(findmnt -kn -o SOURCE,FSTYPE,OPTIONS --mountpoint /dev/shm | tail -n 1)
[ -n "$o" ] || { echo "/dev/shm is not mounted"; exit 1; }
echo "/dev/shm $o"
rc=0
for opt in nodev nosuid noexec; do
case ,${o##* }, in *,$opt,*) ;; *) echo "missing $opt"; rc=1 ;; esac
done
exit $rc
Remediation
- If
/etc/fstabhas a/dev/shmline, addnodev,nosuid,noexecto its options. Otherwise add the line:tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0 - Run
systemctl daemon-reloadandmount -o remount,nodev,nosuid,noexec /dev/shm.
| Restart | none |
| Disruption | low |
Rollback
Remove the /dev/shm line from /etc/fstab (or restore the copy saved in the backup
directory), run systemctl daemon-reload and mount -o remount,exec /dev/shm.
fstab
# CB-UBU-FS-004: mount /dev/shm with nodev, nosuid and noexec, at once and at every boot.
f=/etc/fstab
cb_backup "$f"
if awk '$1 !~ /^#/ && $2 == "/dev/shm"' "$f" | grep -q .; then
# Add the missing options to the existing line, leave every other line untouched.
awk '$1 !~ /^#/ && $2 == "/dev/shm" {
n = split("nodev nosuid noexec", w, " ")
for (i = 1; i <= n; i++) if (index("," $4 ",", "," w[i] ",") == 0) $4 = $4 "," w[i]
}
{ print }' "$f" >"$f.cirsec.tmp" || { rm -f "$f.cirsec.tmp"; exit 1; }
cat "$f.cirsec.tmp" >"$f"
rm -f "$f.cirsec.tmp"
else
printf 'tmpfs\t/dev/shm\ttmpfs\tdefaults,nodev,nosuid,noexec\t0\t0\n' >>"$f"
fi
systemctl daemon-reload
mount -o remount,nodev,nosuid,noexec /dev/shm
Handwritten code reads parameters from CB_<NAME> environment variables. Each release turns these fixes into remediate.sh and an Ansible role per profile: dry run by default, a fix runs only when its check fails.
References
- fstab(5), Ubuntu manual pages Canonical, vendor-doc, accessed 2026-10-19
- systemd-fstab-generator(8), Ubuntu manual pages Canonical, vendor-doc, accessed 2026-10-19
- mount(8), Ubuntu manual pages (filesystem-independent mount options) Canonical, vendor-doc, accessed 2026-10-19
Mappings
| Framework | ID | Relation |
|---|---|---|
| NIST SP 800-53 Rev. 55.1.1 | CM-7 | related |
How this control relates to the other framework's: equivalent, stricter, looser, partial or related.
Threats mitigated
Related controls
- related
CB-UBU-FS-003Mount /tmp as a separate filesystem with nodev, nosuid and noexec
People and lifecycle
| Authors |
|
| Verified | 2026-10-19 by Sn0wAlice on 20.04, Proxmox VM 2520, Ubuntu 20.04 cloud image, kernel 5.4.0-216-generic. Fails on fresh install (no noexec); fix adds an fstab line and remounts; options kept after reboot; second run leaves fstab unchanged. |
| Verified | 2026-10-19 by Sn0wAlice on 22.04, Proxmox VM 2522, Ubuntu 22.04 cloud image, kernel 5.15.0-198-generic. Fails on fresh install (no noexec); fix adds an fstab line and remounts; options kept after reboot; second run leaves fstab unchanged. |
| Verified | 2026-10-19 by Sn0wAlice on 24.04, Proxmox VM 2524, Ubuntu 24.04 cloud image, kernel 6.8.0-147-generic. Fails on fresh install (no noexec); fix adds an fstab line and remounts; options kept after reboot; second run leaves fstab unchanged. |
| Verified | 2026-10-19 by Sn0wAlice on 26.04, Proxmox VM 2526, Ubuntu 26.04 cloud image, kernel 7.0.0-38-generic. Fails on fresh install (no noexec); fix adds an fstab line and remounts; options kept after reboot; second run leaves fstab unchanged. |
| Introduced in | v0.1.0 |
| Created, updated | 2026-10-19, 2026-10-19 |
| Translations | fr |