mirror of
https://github.com/troglobit/finit.git
synced 2026-10-01 05:22:48 +07:00
Prevent user DoS by mounting /run/lock as separate tmpfs
This patch does several things related to /run and system reliability. - Mount /run with MAX 10% of usable RAM - Create and mount /run/lock as a separate tmpfs with max 5 MiB As a spin-off, this patch also fixes permisions on /run/lock to 0777 so regular users can create lock files. Note: none of this code runs if /run is mounted alread in /etc/fstab Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+16
-3
@@ -215,9 +215,22 @@ static void fs_finalize(void)
|
||||
mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620,ptmxmode=0666");
|
||||
}
|
||||
|
||||
/* Modern systems use tmpfs for /run */
|
||||
if (!fismnt("/run"))
|
||||
mount("tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0755");
|
||||
/*
|
||||
* Modern systems use tmpfs for /run. Fallback to /var/run if
|
||||
* /run doesn't exist is handled by the bootmisc plugin. It
|
||||
* also sets up compat symlinks.
|
||||
*
|
||||
* The unconditional mount of /run/lock is for DoS prevention.
|
||||
* To override any of this behavior, add entries to /etc/fstab
|
||||
* for /run (and optionally /run/lock).
|
||||
*/
|
||||
if (fisdir("/run") && !fismnt("/run")) {
|
||||
mount("tmpfs", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0755,size=10%");
|
||||
|
||||
/* This prevents user DoS of /run by filling /run/lock at the expense of another tmpfs, max 5MiB */
|
||||
makedir("/run/lock", 1777);
|
||||
mount("tmpfs", "/run/lock", "tmpfs", MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, "mode=0777,size=5252880");
|
||||
}
|
||||
|
||||
/* Modern systems use tmpfs for /tmp */
|
||||
if (!fismnt("/tmp"))
|
||||
|
||||
Reference in New Issue
Block a user