Merge pull request #408 from mandelmassa/master

Avoid remounting already mounted /run and /tmp directories

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-08-06 13:13:49 +02:00
committed by GitHub
3 changed files with 19 additions and 2 deletions
+2 -2
View File
@@ -409,7 +409,7 @@ static void fs_finalize(void)
* To override any of this behavior, add entries to /etc/fstab
* for /run (and optionally /run/lock).
*/
if (fisdir("/run") && !fismnt("/run")) {
if (fisdir("/run") && !fismnt("/run") && !fistmpfs("/run")) {
fs_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 */
@@ -418,7 +418,7 @@ static void fs_finalize(void)
}
/* Modern systems use tmpfs for /tmp */
if (!fismnt("/tmp"))
if (!fismnt("/tmp") && !fistmpfs("/tmp"))
fs_mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");
}
+16
View File
@@ -42,6 +42,8 @@
# include <sys/ioctl.h>
#endif
#include <sys/sysinfo.h> /* sysinfo() */
#include <sys/vfs.h> /* statfs */
#include <linux/magic.h>
#ifdef _LIBITE_LITE
# include <libite/lite.h>
#else
@@ -572,6 +574,20 @@ int fismnt(char *dir)
return ismnt("/proc/mounts", dir, NULL);
}
/* Return 1 if dir is a backed by tmpfs or overlayfs */
int fistmpfs(char *dir)
{
struct statfs info = {0};
if (statfs(dir, &info))
return 0;
if (info.f_type == TMPFS_MAGIC || info.f_type == OVERLAYFS_SUPER_MAGIC)
return 1;
return 0;
}
#ifdef HAVE_TERMIOS_H
/*
* Called by initctl, and by finit at boot and shutdown, to
+1
View File
@@ -80,6 +80,7 @@ void de_dotdot (char *file);
int ismnt (char *file, char *dir, char *mode);
int fismnt (char *dir);
int fistmpfs (char *dir);
#ifdef HAVE_TERMIOS_H
int ttinit (void);