Skip to content

Commit

Permalink
Merge pull request #408 from mandelmassa/master
Browse files Browse the repository at this point in the history
Avoid remounting already mounted /run and /tmp directories

Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit authored Aug 6, 2024
2 parents 13b107b + a068521 commit 29bd7a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/finit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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");
}

Expand Down
16 changes: 16 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 29bd7a5

Please sign in to comment.