fuse: refuse kernel-internal files as passthrough backing files
Subsystems (3)
Amir Goldstein
maintainerPATCH 1/1 fuse: refuse kernel-internal files as passthrough backing files
The fuse server can register a regular file on a filesystem that only the kernel mounts, such as a memfd, as a backing file. Such files were never meant to be passthrough backing files, and some come with semantics of their own, such as memfd seals, which passthrough does not respect.
Refuse files on filesystems mounted with SB_KERNMOUNT, as is done for files on pseudo filesystems.
A fuse server that wants to keep the data of its backing files in memory can create them with O_TMPFILE on a tmpfs that it mounts. Such files cannot be sealed.
---
Miklos,
FYI, Christian has already queued a similar patch for banning pseudo fs passthrough files [1].
Note that I intentionally placed the gate outside the S_IFMT switch to future-proof non-regular passthrough file types.
Thanks,
Amir.
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
fs/fuse/backing.c | 3 +++ 1 file changed, 3 insertions(+)
fs/fuse/backing.c +3 -0
@@ -138,6 +138,9 @@ static int fuse_backing_open_file(struct fuse_conn *fc, struct fuse_backing *fb,struct dax_device *daxdev;int err; +if (inode->i_sb->s_flags &SB_KERNMOUNT ) +return -EINVAL ; +switch (inode->i_mode &S_IFMT ) {case S_IFREG :/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
Quoted 12 lines · Amir Goldstein
The fuse server can register a regular file on a filesystem that only the kernel mounts, such as a memfd, as a backing file. Such files were never meant to be passthrough backing files, and some come with semantics of their own, such as memfd seals, which passthrough does not respect.
Refuse files on filesystems mounted with
SB_KERNMOUNT, as is done for files on pseudo filesystems.A fuse server that wants to keep the data of its backing files in memory can create them with
O_TMPFILEon a tmpfs that it mounts. Such files cannot be sealed.
Quoted 5 lines
Reported-by Dominik Maier <[email protected]>Fixes 44350256ab94 ("fuse: implement ioctls to manage backing files")Signed-off-by Amir Goldstein <[email protected]>
Thanks!
Quoted 23 lines
---
Miklos,
FYI, Christian has already queued a similar patch for banning pseudo fs passthrough files [1].
Note that I intentionally placed the gate outside the
S_IFMTswitch to future-proof non-regular passthrough file types.Thanks,
Amir.[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
fs/fuse/backing.c | 3 +++ 1 file changed, 3 insertions(+)fs/fuse/backing.c +0
-0
fs/fuse/backing.c static int fuse_backing_open_file(struct fuse_conn *fc, struct fuse_backing *fb, · line 146
Quoted 9 lines
fs/fuse/backing.c +3
-0@@ -138,6 +138,9 @@ static int fuse_backing_open_file(struct fuse_conn *fc, struct fuse_backing *fb,struct dax_device *daxdev;int err; +if (inode->i_sb->s_flags &SB_KERNMOUNT ) +return -EINVAL ; +switch (inode->i_mode &S_IFMT ) {case S_IFREG :/* TODO: relax CAP_SYS_ADMIN once backing files are visible to lsof */
--
Cheers, Lorenzo
Verified on mainline d06ce6f1eb5e in QEMU: sealed and unsealed memfds now fail FUSE_DEV_IOC_BACKING_OPEN with -EINVAL (blocking the seal bypass), while regular and O_TMPFILE backing files on a user-mounted tmpfs still succeed without warnings.