brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: mount /dev/shm with noexec for a little extra security on a server

Security
~/tips/tip-security-dev-shm-noexec

findmnt -no OPTIONS /dev/shm

Stops programs from being run directly out of the shared memory folder.

/dev/shm is a world-writable RAM folder, which makes it a favourite drop spot for attack scripts: write a binary there, mark it executable and run it. A mount option takes the last step away.

See how it is mounted now:

findmnt -no OPTIONS /dev/shm

If noexec is missing, add a line to /etc/fstab and remount:

tmpfs /dev/shm tmpfs defaults,noexec,nosuid,nodev 0 0
sudo mount -o remount /dev/shm

With noexec the kernel refuses to run files from that mount. nosuid ignores setuid bits and nodev ignores device files, both of which have no business there either. Try it with a small script: run directly, it fails with Permission denied.

The same test also shows how far this goes. sh /dev/shm/script.sh still runs, because then the shell from /usr/bin is what executes and it only reads the file. So it blocks dropped binaries and lazy scripts, not a determined attacker. I count it as one cheap layer, not a wall.

Test your apps afterwards. A few programs do execute code from shared memory, and some installers unpack into temp folders and run from there. If something breaks after the change, drop the line again and the default comes back at the next boot.

Further reading: mount(8): filesystem independent mount options

More Security tips tcpdump -nn -r capture.pcap port 53 mkcert -install Strict-Transport-Security: max-age=0 Referrer-Policy: strict-origin-when-cross-origin wp super-admin list All Security tips (79) All topics

Link