From 0988e9bc3987e742c42f121e194967986355e924 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Wed, 24 Aug 2022 15:22:52 +0200 Subject: [PATCH] main: add checks for valid /proc mount since fuse-overlayfs needs a writeable /proc mount, add some checks to validate it. Closes: https://github.com/containers/fuse-overlayfs/issues/137 Signed-off-by: Giuseppe Scrivano --- main.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/main.c b/main.c index b6241da..27dcc95 100644 --- a/main.c +++ b/main.c @@ -37,7 +37,9 @@ #include #include #include +#include #include +#include #include #ifdef HAVE_SYS_SENDFILE_H # include @@ -291,6 +293,34 @@ inode_to_node (struct ovl_data *lo, ino_t n) return lookup_inode (lo, n)->node; } +static void +check_writeable_proc () +{ + struct statvfs svfs; + struct statfs sfs; + + int ret; + + ret = statfs ("/proc", &sfs); + if (ret < 0) + { + fprintf (stderr, "error stating /proc: %m\n"); + return; + } + + if (sfs.f_type != PROC_SUPER_MAGIC) + { + fprintf (stderr, "invalid file system type found on /proc: %m\n"); + return; + } + + if (svfs.f_flag & ST_RDONLY) + { + fprintf (stderr, "/proc seems to be mounted as readonly, it can lead to unexpected failures"); + return; + } +} + static void check_can_mknod (struct ovl_data *lo) { @@ -5617,6 +5647,7 @@ main (int argc, char *argv[]) set_limits (); check_can_mknod (&lo); + check_writeable_proc (); if (lo.debug) {