Skip to contentSkip to conversation

fuse: refuse kernel-internal files as passthrough backing files

PATCH In review Amir Goldstein 3 participants 3 messages Dec 3 – Dec 5

Subsystems (3)
lore
Share & tools
lore

Amir Goldstein

author maintainer
#0 lore raw

PATCH 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.

Fixes 44350256ab94 ("fuse: implement ioctls to manage backing files")

---

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
index 4e4fb810ddaa8..287a4b6e18526 100644
@@ -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 */
Acked-by on v1 1/1
#1 lore raw
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_TMPFILE on a tmpfs that it mounts. Such files cannot be sealed.

Quoted 5 lines
Fixes 44350256ab94 ("fuse: implement ioctls to manage backing files")

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_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 +0 -0
index 4e4fb810ddaa8..287a4b6e18526 100644

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