aboutsummaryrefslogtreecommitdiff
path: root/sys/fs
diff options
context:
space:
mode:
authorDoug Rabson <dfr@FreeBSD.org>2022-11-23 14:51:13 +0000
committerDoug Rabson <dfr@FreeBSD.org>2022-12-19 16:46:13 +0000
commit521fbb722c33663cf00a83bca70ad7cb790687b3 (patch)
treefe2bed0dd21c809d9072450ed503982f2072b783 /sys/fs
parent78d35459a2586da024ac18e8768b44893c7184e7 (diff)
downloadsrc-521fbb722c33663cf00a83bca70ad7cb790687b3.tar.gz
src-521fbb722c33663cf00a83bca70ad7cb790687b3.zip
Add support for mounting single files in nullfs
The main use-case for this is to support mounting config files and secrets into OCI containers. My current workaround copies the files into the container which is messy and risks secrets leaking into container images if the cleanup fails. This adds a VFCF flag to indicate whether the filesystem supports file mounts and allows fspath to be either a directory or a file if the flag is set. Test Plan: $ sudo mkdir -p /mnt $ sudo touch /mnt/foo $ sudo mount -t nullfs /COPYRIGHT /mnt/foo Reviewed by: mjg, kib Tested by: pho
Diffstat (limited to 'sys/fs')
-rw-r--r--sys/fs/nullfs/null_vfsops.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/sys/fs/nullfs/null_vfsops.c b/sys/fs/nullfs/null_vfsops.c
index 216a8badce56..7f78d23ba016 100644
--- a/sys/fs/nullfs/null_vfsops.c
+++ b/sys/fs/nullfs/null_vfsops.c
@@ -156,6 +156,17 @@ nullfs_mount(struct mount *mp)
}
}
+ /*
+ * Lower vnode must be the same type as the covered vnode - we
+ * don't allow mounting directories to files or vice versa.
+ */
+ if ((lowerrootvp->v_type != VDIR && lowerrootvp->v_type != VREG) ||
+ lowerrootvp->v_type != mp->mnt_vnodecovered->v_type) {
+ NULLFSDEBUG("nullfs_mount: target must be same type as fspath");
+ vput(lowerrootvp);
+ return (EINVAL);
+ }
+
xmp = (struct null_mount *) malloc(sizeof(struct null_mount),
M_NULLFSMNT, M_WAITOK | M_ZERO);
@@ -503,4 +514,4 @@ static struct vfsops null_vfsops = {
.vfs_unlink_lowervp = nullfs_unlink_lowervp,
};
-VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK | VFCF_JAIL);
+VFS_SET(null_vfsops, nullfs, VFCF_LOOPBACK | VFCF_JAIL | VFCF_FILEMOUNT);