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 <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano 2022-08-24 15:22:52 +02:00
parent f87e1781a8
commit 0988e9bc39
No known key found for this signature in database
GPG Key ID: 67E38F7A8BA21772

31
main.c
View File

@ -37,7 +37,9 @@
#include <dirent.h> #include <dirent.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <linux/magic.h>
#include <err.h> #include <err.h>
#include <sys/vfs.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#ifdef HAVE_SYS_SENDFILE_H #ifdef HAVE_SYS_SENDFILE_H
# include <sys/sendfile.h> # include <sys/sendfile.h>
@ -291,6 +293,34 @@ inode_to_node (struct ovl_data *lo, ino_t n)
return lookup_inode (lo, n)->node; 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 static void
check_can_mknod (struct ovl_data *lo) check_can_mknod (struct ovl_data *lo)
{ {
@ -5617,6 +5647,7 @@ main (int argc, char *argv[])
set_limits (); set_limits ();
check_can_mknod (&lo); check_can_mknod (&lo);
check_writeable_proc ();
if (lo.debug) if (lo.debug)
{ {