mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Avoid remounting already mounted /run and /tmp directories
Adds the function fistmpfs to determine if a new tmpfs mount should be performed on /run and /tmp. The function supports cases where more complex mount hierarchies are in use, including overlayfs backed mounts. Signed-off-by: Mathias Thore <mathias.thore@atlascopco.com>
This commit is contained in:
1 parent
13b107b7b1
commit
a0685219cf
3 files changed
+19
-2
No files matched your search
+2
-2
@@ -409,7 +409,7 @@ static void fs_finalize(void)
|
|||||||
* To override any of this behavior, add entries to /etc/fstab
|
* To override any of this behavior, add entries to /etc/fstab
|
||||||
* for /run (and optionally /run/lock).
|
* 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%");
|
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 */
|
/* 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 */
|
/* 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");
|
fs_mount("tmpfs", "/tmp", "tmpfs", MS_NOSUID | MS_NODEV, "mode=1777");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
@@ -42,6 +42,8 @@
|
|||||||
# include <sys/ioctl.h>
|
# include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/sysinfo.h> /* sysinfo() */
|
#include <sys/sysinfo.h> /* sysinfo() */
|
||||||
|
#include <sys/vfs.h> /* statfs */
|
||||||
|
#include <linux/magic.h>
|
||||||
#ifdef _LIBITE_LITE
|
#ifdef _LIBITE_LITE
|
||||||
# include <libite/lite.h>
|
# include <libite/lite.h>
|
||||||
#else
|
#else
|
||||||
@@ -572,6 +574,20 @@ int fismnt(char *dir)
|
|||||||
return ismnt("/proc/mounts", dir, NULL);
|
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
|
#ifdef HAVE_TERMIOS_H
|
||||||
/*
|
/*
|
||||||
* Called by initctl, and by finit at boot and shutdown, to
|
* Called by initctl, and by finit at boot and shutdown, to
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ void de_dotdot (char *file);
|
|||||||
|
|
||||||
int ismnt (char *file, char *dir, char *mode);
|
int ismnt (char *file, char *dir, char *mode);
|
||||||
int fismnt (char *dir);
|
int fismnt (char *dir);
|
||||||
|
int fistmpfs (char *dir);
|
||||||
|
|
||||||
#ifdef HAVE_TERMIOS_H
|
#ifdef HAVE_TERMIOS_H
|
||||||
int ttinit (void);
|
int ttinit (void);
|
||||||
|
|||||||
Reference in new issue
Block a user