Skip to contentSkip to conversation

fs: don't use pseudo filesystem files as storage

RFC PATCH In review Christian Brauner 9 participants 110 messages Nov 16 – Nov 17

Subsystems (40)
lore
Share & tools
lore

Christian Brauner

author maintainer
#0 lore raw

v3 cover fs: don't use pseudo filesystem files as storage

Loop happily takes any regular file with ->read_iter() as a backing file and any file that also has ->write_iter() as a writable one. A few examples:

* /proc/kcore attaches read-only as a loop device the size of the kernel's virtual address space (64 PiB with 5-level paging)
* sysfs attributes attach read-write as 4096 byte loop devices
* using /sys/kernel/mm/transparent_hugepage/enabled for the loop device and writing a block to the loop device changes the THP setting

It's not just silly. It's abusable (is that a word?). Loop calls ->read_iter() and ->write_iter() of the backing file directly from its kworker which runs with kernel credentials.

But pseudo files enforce part of their access rules at read and write against the caller. So dozens of sysfs ->show() and ->store() methods call capable().

But setting up a loop device requires no capabilities. It only requires access to the device nodes. So whoever has a loop device skips all of the capable() checks.

A couple of fun examples:

On v7.4-rc1 uid 0 without any capabilities can't kill a process of uid 1000 and can't poison its memory either:

    $ grep CapEff /proc/self/status
    CapEff: 0000000000000000
    $ kill -9 327
    bash: kill: (327) - Operation not permitted
    $ echo 0x220689000 > /sys/devices/system/memory/hard_offline_page
    bash: echo: write error: Operation not permitted

But put hard_offline_page behind a loop device, write a block containing 0x220689000 to the loop device and the loop worker happily does it:

Memory failure: 0x220689: recovery action for dirty LRU page: Recovered
MCE: Killing victim:327 due to hardware memory corruption fault at 7f468e972000

That hard_offline_page is a write-only file doesn't stop loop from using it as a writable backing file either.

Other fun examples:

(1) soft-block radios via /sys/class/rfkill/rfkill*/soft

    (CAP_NET_ADMIN)

(2) change the reboot mode via /sys/kernel/reboot/mode (CAP_SYS_BOOT)

(3) reconfigure md arrays via /sys/block/md*/md/. md_attr_store() requires CAP_SYS_ADMIN for every md attribute.

(4) reconfigure scsi disks via /sys/class/scsi_disk/*/allow_restart and friends (CAP_SYS_ADMIN)

(5) read dmi-sysfs attributes (CAP_SYS_ADMIN)

And an unprivileged container that was handed a loop device can change gro_flush_timeout of its own network devices. That usually requires CAP_NET_ADMIN in the initial user namespace (via sysfs and via netlink).

I've reproduced that all on v7.4-rc1.

Aaaand zloop, the nvme target's file backend, the scsi target's fileio backend, fuse passthrough and the usb mass storage gadget have the same problem. erofs takes pseudo files as images for file-backed mounts as well. It reads them with the mounter's credentials though so that's just silly and not abusable. Same for acct(2) which happily writes its records to cgroup2 or binfmt_misc files.

Fwiw, device mapper doesn't need anything. It only takes block devices. md's deprecated bitmap file is fine as well. It maps the file with bmap() which no pseudo filesystem implements.

So this series adds SB_I_PSEUDO to state that the regular files of a filesystem are kernel interfaces and not storage and makes all eight refuse such files.

I didn't want to sprinkle SB_I_PSEUDO over all pseudo filesystems one by one. Instead there's now a common initialization point for all of them via fc_init_pseudo().

init_pseudo() uses it for the internal pseudo filesystems and all mountable pseudo filesystems call it from their ->init_fs_context().

kernfs does it once in kernfs_get_tree(). It raises SB_I_PSEUDO, SB_I_NOEXEC and SB_I_NODEV. Pseudo filesystems never hold executables and generally never hold device nodes. Some of them raised SB_I_NOEXEC and SB_I_NODEV already, most didn't.

I went through every single one of them. None of them needs to execute anything. The files that can be mmap()ed map data and the tracing ring buffer refuses VM_EXEC anyway.

SB_I_NODEV is cleared again by devpts, binderfs, selinuxfs and securityfs. The first two did that already. selinuxfs needs it because Android init opens /sys/fs/selinux/null by path as /dev/null doesn't exist yet at that point. securityfs needs it for AppArmor's .null device node. On exec AppArmor puts it in place of file descriptors the new profile isn't allowed to use and those can be reopened via /proc/<pid>/fd/<nr>. Note that systemd mounts most of these filesystems with noexec and nodev already.

file_check_backing() looks at d_real_data_inode(). overlayfs happily stacks on top of sysfs, cgroup2, debugfs, tracefs, configfs and securityfs and reads of such overlayfs files are served by the pseudo file. Only procfs and binfmt_misc are refused as they set s_stack_depth to FILESYSTEM_MAX_STACK_DEPTH and efivarfs as it has its own ->d_hash() and ->d_compare().

Whether all pseudo filesystems should refuse stacking is a separate discussion. overlayfs reads the lower file with the mounter's credentials so a root-mounted overlayfs on top of a sysfs directory hands capability gated reads to every reader. With SB_I_PSEUDO overlayfs could easily refuse them.

The first three patches are independent fixes. Loop never checked whether its backing file is open for reading. It relied on vfs_iter_read() refusing such files. Direct I/O never went through vfs_iter_read() and since v6.15 buffered I/O doesn't either. So whoever has a loop device can read files they could only open for writing. And the nvme target's file backend and the scsi target's fileio backend call ->read_iter() and ->write_iter() without checking that they exist.

---
Changes in v3:
- Rebase onto vfs-7.5.lookup which has "fs: let d_real() fail" v2:
https://patch.msgid.link/[email protected]
- file_check_backing(): use d_real_data_inode() and fail with its error.
For an O_PATH file on overlayfs the data might not have been looked up
yet and when that lookup failed ovl_d_real() warned and the check
passed. (Chris, sashiko, bpf-ci)
- ovl: refuse data-only layers on pseudo filesystems. (Amir)
- fuse: also check the backing file that fuse_passthrough_open() opens
for io. (Amir)
- securityfs: clear SB_I_NODEV again. AppArmor's .null device node can
be opened by path and via /proc/<pid>/fd/<nr>. (Chris)
- selftests: add fuse passthrough tests and tests for overlayfs
data-only layers on pseudo filesystems.
- Collect tags.
- Link to v2: https://patch.msgid.link/[email protected]

Changes in v2:
- Add file_check_backing() and use it in all consumers. It replaces file_is_pseudo() and most of the open-coded file type, open mode and
method checks.
- nvmet, fileio and zloop refuse everything that isn't a regular file
or, for nvmet and fileio, a block device.
- fileio: check the protection file as well. (sashiko)
- acct: refuse files on all pseudo filesystems. (Alexander)
- selftests: add nvmet (Bui), fileio, zloop, link, FIFO and character
device tests.
- Collect tags. They are dropped on the patches that changed.
- Link to v1: https://patch.msgid.link/[email protected]

---
Christian Brauner (44):
loop: refuse backing files that aren't open for reading
nvmet: check that the file backend supports ->{read,write}_iter
target: fileio: check that the backing file supports ->{read,write}_iter
fs: add SB_I_PSEUDO
kernfs: use fc_init_pseudo()
proc: use fc_init_pseudo()
binfmt_misc: use fc_init_pseudo()
mqueue: use fc_init_pseudo()
bpf: use fc_init_pseudo() for bpffs
nullfs: use fc_init_pseudo()
failfs: use fc_init_pseudo()
rust_binderfs: use fc_init_pseudo()
devpts: use fc_init_pseudo()
debugfs: use fc_init_pseudo()
tracefs: use fc_init_pseudo()
configfs: use fc_init_pseudo()
securityfs: use fc_init_pseudo()
selinux: use fc_init_pseudo() for selinuxfs
smack: use fc_init_pseudo() for smackfs
apparmor: use fc_init_pseudo() for apparmorfs
nfsd: use fc_init_pseudo()
sunrpc: use fc_init_pseudo() for rpc_pipefs
fuse: use fc_init_pseudo() for fusectl
efivarfs: use fc_init_pseudo()
pstore: use fc_init_pseudo()
xenfs: use fc_init_pseudo()
openpromfs: use fc_init_pseudo()
ocfs2: use fc_init_pseudo() for dlmfs
s390/hypfs: use fc_init_pseudo()
powerpc/spufs: use fc_init_pseudo()
usb: gadget: f_fs: use fc_init_pseudo()
usb: gadget: gadgetfs: use fc_init_pseudo()
ovl: refuse data-only layers on pseudo filesystems selftests/ovl: test data-only layers on pseudo filesystems
fs: add file_check_backing()
loop: refuse files on pseudo filesystems as backing files
zloop: refuse zone files on pseudo filesystems
nvmet: refuse files on pseudo filesystems as namespace backing files
target: fileio: refuse files on pseudo filesystems as backing files
fuse: refuse files on pseudo filesystems as passthrough backing files
usb: gadget: f_mass_storage: refuse files on pseudo filesystems
erofs: refuse files on pseudo filesystems as backing files
acct: refuse files on pseudo filesystems selftests/filesystems: add backing file tests for pseudo files

 arch/powerpc/platforms/cell/spufs/inode.c          |   2 +
 arch/s390/hypfs/inode.c                            |   2 +
 drivers/android/binder/rust_binderfs.c             |   3 +-
 drivers/block/loop.c                               |  14 +-
 drivers/block/zloop.c                              |   5 +-
 drivers/nvme/target/io-cmd-file.c                  |   4 +
 drivers/target/target_core_file.c                  |  14 +
 drivers/usb/gadget/function/f_fs.c                 |   2 +
 drivers/usb/gadget/function/storage_common.c       |  11 +-
 drivers/usb/gadget/legacy/inode.c                  |   2 +
 drivers/xen/xenfs/super.c                          |   2 +
 fs/binfmt_misc.c                                   |   5 +-
 fs/configfs/mount.c                                |   2 +
 fs/debugfs/inode.c                                 |   2 +
 fs/devpts/inode.c                                  |   2 +
 fs/efivarfs/super.c                                |   2 +
 fs/erofs/super.c                                   |   5 +-
 fs/failfs.c                                        |   3 +-
 fs/fuse/backing.c                                  |   4 +
 fs/fuse/control.c                                  |   2 +
 fs/fuse/passthrough.c                              |   7 +
 fs/kernfs/mount.c                                  |   4 +-
 fs/libfs.c                                         |   2 +-
 fs/nfsd/nfsctl.c                                   |   2 +
 fs/nullfs.c                                        |   3 +-
 fs/ocfs2/dlmfs/dlmfs.c                             |   2 +
 fs/openpromfs/inode.c                              |   2 +
 fs/overlayfs/super.c                               |   8 +
 fs/proc/root.c                                     |   4 +-
 fs/pstore/inode.c                                  |   2 +
 fs/read_write.c                                    |  53 ++
 fs/tracefs/inode.c                                 |   2 +
 include/linux/fs.h                                 |   2 +
 include/linux/fs/super_types.h                     |   1 +
 include/linux/pseudo_fs.h                          |  12 +
 ipc/mqueue.c                                       |   3 +-
 kernel/acct.c                                      |   6 +-
 kernel/bpf/inode.c                                 |   4 +-
 net/sunrpc/rpc_pipe.c                              |   2 +
 security/apparmor/apparmorfs.c                     |   2 +
 security/inode.c                                   |   4 +
 security/selinux/selinuxfs.c                       |   5 +
 security/smack/smackfs.c                           |   2 +
 tools/testing/selftests/filesystems/.gitignore     |   1 +
 tools/testing/selftests/filesystems/Makefile       |   2 +-
 tools/testing/selftests/filesystems/config         |  16 +
 .../selftests/filesystems/overlayfs/.gitignore     |   1 +
 .../selftests/filesystems/overlayfs/Makefile       |   1 +
 .../filesystems/overlayfs/pseudo_datadir.c         | 131 +++
 .../selftests/filesystems/pseudo_backing_test.c    | 936 +++++++++++++++++++++
 50 files changed, 1271 insertions(+), 39 deletions(-)

---
base-commit: 68cb948e620cf297cee090d6effd04dfef6429de
change-id: 20261109-work-loop-pseudo-890844168ef1

author maintainer
#1 lore raw

RFC PATCH v3 1/44 loop: refuse backing files that aren't open for reading

loop_configure() takes any file as long as it implements ->read_iter(). Loop itself never checked whether the file was actually opened for reading. Buffered I/O went through vfs_iter_read() which refuses files without FMODE_READ. Direct I/O has called ->read_iter() of the backing file directly ever since loop grew support for it.

Since commit f2fed441c69b ("loop: stop using vfs_iter_{read,write} for buffered I/O") buffered I/O calls ->read_iter() directly as well. That commit was about O_DIRECT handling and the FMODE_READ check went away as a side effect.

So whoever can set up a loop device can read a file it was only allowed to open for writing. Open the file O_WRONLY, configure a loop device with it and read the contents through the loop device.

Refuse backing files that aren't open for reading. Loop always reads from its backing file so a write-only backing file never made sense in the first place.

Fixes bc07c10a3603 ("block: loop: support DIO & AIO")
Fixes f2fed441c69b ("loop: stop using vfs_iter_{read,write} for buffered I/O")
---
 drivers/block/loop.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -0
index a3325ceab484a..c96e35c3ef423 100644
@@ -528,6 +528,9 @@ static void loop_assign_backing_file(struct loop_device *lo, struct file *file)
 
 static int loop_check_backing_file(struct file *file)
 {
+	if (!(file->f_mode & FMODE_READ))
+		return -EBADF;
+
 	if (!file->f_op->read_iter)
 		return -EINVAL;
 
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH RFC v3 01/44] loop: refuse backing files that aren't open for reading

Sashiko has reviewed this patch and found no issues.
Quoted 19 lines

loop_configure() takes any file as long as it implements ->read_iter(). Loop itself never checked whether the file was actually opened for reading. Buffered I/O went through vfs_iter_read() which refuses files without FMODE_READ. Direct I/O has called ->read_iter() of the backing file directly ever since loop grew support for it.

Since commit f2fed441c69b ("loop: stop using vfs_iter_{read,write} for buffered I/O") buffered I/O calls ->read_iter() directly as well. That commit was about O_DIRECT handling and the FMODE_READ check went away as a side effect.

So whoever can set up a loop device can read a file it was only allowed to open for writing. Open the file O_WRONLY, configure a loop device with it and read the contents through the loop device.

Refuse backing files that aren't open for reading. Loop always reads from its backing file so a write-only backing file never made sense in the first place.

Quoted 8 lines
Fixes bc07c10a3603 ("block: loop: support DIO & AIO")
Fixes f2fed441c69b ("loop: stop using vfs_iter_{read,write} for buffered I/O")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
author maintainer
#3 lore raw

RFC PATCH v3 2/44 nvmet: check that the file backend supports ->{read,write}_iter

In reply to Christian Brauner

The file backend calls ->read_iter() and ->write_iter() of the backing file directly but never checks that they exist. Everything that isn't a block device ends up in the file backend. So a namespace pointing to a file without them calls a NULL pointer on its first I/O. Only buffered_io=1 gets that far as the O_DIRECT open fails for such files.

Refuse them when the namespace is enabled the same way zloop does since commit 0c10f8a1a7ae ("zloop: check that the zone backing file support ->{read,write}_iter").

Fixes d5eff33ee6f8 ("nvmet: add simple file backed ns support")
---
 drivers/nvme/target/io-cmd-file.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/nvme/target/io-cmd-file.c +5 -0
index 695963dd932ee..dfa8aa46188c8 100644
@@ -47,6 +47,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
 		return ret;
 	}
 
+	if (!ns->file->f_op->read_iter || !ns->file->f_op->write_iter) {
+		ret = -EINVAL;
+		goto err;
+	}
+
 	nvmet_file_ns_revalidate(ns);
 
 	/*
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH RFC v3 02/44] nvmet: check that the file backend supports ->{read,write}_iter

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

The file backend calls ->read_iter() and ->write_iter() of the backing file directly but never checks that they exist. Everything that isn't a block device ends up in the file backend. So a namespace pointing to a file without them calls a NULL pointer on its first I/O. Only buffered_io=1 gets that far as the O_DIRECT open fails for such files.

Refuse them when the namespace is enabled the same way zloop does since commit 0c10f8a1a7ae ("zloop: check that the zone backing file support ->{read,write}_iter").

Quoted 5 lines
Fixes d5eff33ee6f8 ("nvmet: add simple file backed ns support")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Reviewed-by on v3 2/44
#5 lore raw

Re: [PATCH RFC v3 02/44] nvmet: check that the file backend supports ->{read,write}_iter

In reply to Christian Brauner
Quoted 15 lines · Christian Brauner

The file backend calls ->read_iter() and ->write_iter() of the backing
file directly but never checks that they exist. Everything that isn't a
block device ends up in the file backend. So a namespace pointing to a
file without them calls a NULL pointer on its first I/O. Only buffered_io=1 gets that far as the O_DIRECT open fails for such files.

Refuse them when the namespace is enabled the same way zloop does since
commit 0c10f8a1a7ae ("zloop: check that the zone backing file support ->{read,write}_iter").

Quoted 4 lines
Fixes d5eff33ee6f8 ("nvmet: add simple file backed ns support")
Quoted 23 lines

---
 drivers/nvme/target/io-cmd-file.c | 5 +++++

 1 file changed, 5 insertions(+)
drivers/nvme/target/io-cmd-file.c +0 -0
index 695963dd932ee..dfa8aa46188c8 100644
@@ -47,6 +47,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
  		return ret;
  	}

drivers/nvme/target/io-cmd-file.c +1 -0
+	if (!ns->file->f_op->read_iter || !ns->file->f_op-
Quoted 1 line

write_iter) {

drivers/nvme/target/io-cmd-file.c +4 -0
+		ret = -EINVAL;
+		goto err;
+	}
+

  nvmet_file_ns_revalidate(ns);

  /*

author maintainer
#6 lore raw

RFC PATCH v3 3/44 target: fileio: check that the backing file supports ->{read,write}_iter

In reply to Christian Brauner

With fd_async_io=1 the fileio backend calls ->read_iter() and ->write_iter() of the backing file directly. The synchronous path goes through vfs_iter_read() and vfs_iter_write() which check for them but the aio path doesn't. So a backing file without them calls a NULL pointer on its first I/O.

Refuse such files when configuring the device. On the synchronous path every read or write that needed the missing method failed with EINVAL anyway.

Fixes 769031c92c8b ("scsi: target: target/file: Add support of direct and async I/O")
---
 drivers/target/target_core_file.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/target/target_core_file.c +8 -0
index ab9824a4852f1..a5391e57e9aa5 100644
@@ -144,6 +144,14 @@ static int fd_configure_device(struct se_device *dev)
 		goto fail;
 	}
 	fd_dev->fd_file = file;
+
+	if (!file->f_op->read_iter || !file->f_op->write_iter) {
+		pr_err("FILEIO: %s lacks ->read_iter or ->write_iter\n",
+		       fd_dev->fd_dev_name);
+		ret = -EINVAL;
+		goto fail;
+	}
+
 	/*
 	 * If using a block backend with this struct file, we extract
 	 * fd_dev->fd_[block,dev]_size from struct block_device.
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH RFC v3 03/44] target: fileio: check that the backing file supports ->{read,write}_iter

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

With fd_async_io=1 the fileio backend calls ->read_iter() and ->write_iter() of the backing file directly. The synchronous path goes through vfs_iter_read() and vfs_iter_write() which check for them but the aio path doesn't. So a backing file without them calls a NULL pointer on its first I/O.

Refuse such files when configuring the device. On the synchronous path every read or write that needed the missing method failed with EINVAL anyway.

Quoted 5 lines
Fixes 769031c92c8b ("scsi: target: target/file: Add support of direct and async I/O")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Reviewed-by on v3 3/44
#8 lore raw

Re: [PATCH RFC v3 03/44] target: fileio: check that the backing file supports ->{read,write}_iter

In reply to Christian Brauner
Quoted 12 lines · Christian Brauner

With fd_async_io=1 the fileio backend calls ->read_iter() and ->write_iter() of the backing file directly. The synchronous path goes
through vfs_iter_read() and vfs_iter_write() which check for them but the aio path doesn't. So a backing file without them calls a NULL pointer on its first I/O.

Refuse such files when configuring the device. On the synchronous path
every read or write that needed the missing method failed with EINVAL anyway.

Quoted 5 lines
Fixes 769031c92c8b ("scsi: target: target/file: Add support of

direct and async I/O")

Quoted 28 lines

---
 drivers/target/target_core_file.c | 8 ++++++++

 1 file changed, 8 insertions(+)
drivers/target/target_core_file.c +8 -0
index ab9824a4852f1..a5391e57e9aa5 100644
@@ -144,6 +144,14 @@ static int fd_configure_device(struct se_device
 *dev)
  		goto fail;
  	}
  	fd_dev->fd_file = file;
+
+	if (!file->f_op->read_iter || !file->f_op->write_iter) {
+		pr_err("FILEIO: %s lacks ->read_iter or -
 >write_iter\n",
+		       fd_dev->fd_dev_name);
+		ret = -EINVAL;
+		goto fail;
+	}
+
  	/*

  * If using a block backend with this struct file, we extract
  * fd_dev->fd_[block,dev]_size from struct block_device.

author maintainer
#9 lore raw

RFC PATCH v3 4/44 fs: add SB_I_PSEUDO

In reply to Christian Brauner

Currently, there's no way to tell whether the files of a filesystem store data or whether they are kernel interfaces. Files on pseudo filesystems such as procfs or sysfs generate their contents when they're read and writes to them are commands to the kernel.

But a few places in the kernel take an arbitrary file and use it as
storage: loop, zloop, the nvme target's file backend, the scsi target's fileio backend, fuse passthrough, the usb mass storage gadget and erofs file-backed mounts. At most they check the file type and whether the file implements ->read_iter() and ->write_iter(). That's not enough. kernfs provides both for every sysfs attribute for example.

Add SB_I_PSEUDO so a filesystem can state that its regular files are kernel interfaces and must not be used as storage.

Pseudo filesystems also never hold executables and most of them don't hold device nodes either. But currently each of them decides on its own whether to raise SB_I_NOEXEC and SB_I_NODEV. Some do, most don't. Add fc_init_pseudo() as the common initialization point for all pseudo filesystems that raises all three flags and switch init_pseudo() over to it. The few pseudo filesystems that do hold device nodes clear SB_I_NODEV again when they fill in their superblock. The following patches convert the mountable pseudo filesystems.

Nothing checks SB_I_PSEUDO yet so no functional changes.

---
 fs/libfs.c                     |  2 +-
 include/linux/fs/super_types.h |  1 +
 include/linux/pseudo_fs.h      | 12 ++++++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)
fs/libfs.c +1 -1
index 96a6e9b1535fb..8c8789489fdf9 100644
@@ -735,7 +735,7 @@ struct pseudo_fs_context *init_pseudo(struct fs_context *fc,
 		fc->fs_private = ctx;
 		fc->ops = &pseudo_fs_context_ops;
 		fc->sb_flags |= SB_NOUSER;
-		fc->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
+		fc_init_pseudo(fc);
 		fc->global = true;
 	}
 	return ctx;
include/linux/fs/super_types.h +1 -0
index 72f4288e16c52..472200bdf081a 100644
@@ -359,5 +359,6 @@ struct super_block {
 #define SB_I_NOIDMAP	0x00002000	/* No idmapped mounts on this superblock */
 #define SB_I_ALLOW_HSM	0x00004000	/* Allow HSM events on this superblock */
 #define SB_I_NO_DATA_INTEGRITY	0x00008000 /* fs cannot guarantee data persistence on sync */
+#define SB_I_PSEUDO	0x00010000	/* regular files are kernel interfaces, not storage */
 
 #endif /* _LINUX_FS_SUPER_TYPES_H */
include/linux/pseudo_fs.h +12 -0
index a651e60d94107..e8fb99600d564 100644
@@ -2,6 +2,7 @@
 #define __LINUX_PSEUDO_FS__
 
 #include <linux/fs_context.h>
+#include <linux/fs/super_types.h>
 
 struct pseudo_fs_context {
 	const struct super_operations *ops;
@@ -15,4 +16,15 @@ struct pseudo_fs_context {
 struct pseudo_fs_context *init_pseudo(struct fs_context *fc,
 				      unsigned long magic);
 
+/*
+ * Common initialization for all pseudo filesystems, mountable or not. Their
+ * regular files are kernel interfaces. They don't store data and pseudo
+ * filesystems never hold executables. The few that hold device nodes clear
+ * SB_I_NODEV again when they fill in their superblock.
+ */
+static inline void fc_init_pseudo(struct fs_context *fc)
+{
+	fc->s_iflags |= SB_I_PSEUDO | SB_I_NOEXEC | SB_I_NODEV;
+}
+
 #endif
Signature · 1 line
2.53.0
#10 lore raw

Re: [PATCH RFC v3 04/44] fs: add SB_I_PSEUDO

Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

Currently, there's no way to tell whether the files of a filesystem store data or whether they are kernel interfaces. Files on pseudo filesystems such as procfs or sysfs generate their contents when they're read and writes to them are commands to the kernel.

But a few places in the kernel take an arbitrary file and use it as
storage: loop, zloop, the nvme target's file backend, the scsi target's fileio backend, fuse passthrough, the usb mass storage gadget and erofs file-backed mounts. At most they check the file type and whether the file implements ->read_iter() and ->write_iter(). That's not enough. kernfs provides both for every sysfs attribute for example.

Add SB_I_PSEUDO so a filesystem can state that its regular files are kernel interfaces and must not be used as storage.

Quoted 6 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
author maintainer
#11 lore raw

RFC PATCH v3 5/44 kernfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize all kernfs based filesystems as pseudo filesystems in kernfs_get_tree() instead of raising SB_I_NOEXEC and SB_I_NODEV by hand in kernfs_fill_super(). This adds SB_I_PSEUDO for sysfs, cgroupfs and resctrl.

---
 fs/kernfs/mount.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/kernfs/mount.c +2 -2
index a0be784bfb064..6b60d212b003d 100644
@@ -8,6 +8,7 @@
  */
 
 #include <linux/fs.h>
+#include <linux/pseudo_fs.h>
 #include <linux/mount.h>
 #include <linux/init.h>
 #include <linux/magic.h>
@@ -298,8 +299,6 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k
 	struct dentry *root;
 
 	info->sb = sb;
-	/* Userspace would break if executables or devices appear on sysfs */
-	sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
 	sb->s_blocksize = PAGE_SIZE;
 	sb->s_blocksize_bits = PAGE_SHIFT;
 	sb->s_magic = kfc->magic;
@@ -388,6 +387,7 @@ int kernfs_get_tree(struct fs_context *fc)
 	info->ns = kfc->ns_tag;
 	INIT_LIST_HEAD(&info->node);
 
+	fc_init_pseudo(fc);
 	fc->s_fs_info = info;
 	sb = sget_fc(fc, kernfs_test_super, kernfs_set_super);
 	if (IS_ERR(sb))
Signature · 1 line
2.53.0
#12 lore raw

Re: [PATCH RFC v3 05/44] kernfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Initialize all kernfs based filesystems as pseudo filesystems in kernfs_get_tree() instead of raising SB_I_NOEXEC and SB_I_NODEV by hand in kernfs_fill_super(). This adds SB_I_PSEUDO for sysfs, cgroupfs and resctrl.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
author maintainer
#13 lore raw

RFC PATCH v3 6/44 proc: use fc_init_pseudo()

In reply to Christian Brauner

Initialize procfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

---
 fs/proc/root.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/proc/root.c +2 -2
index 7fbbe92bf73a7..ca0e75081934f 100644
@@ -17,6 +17,7 @@
 #include <linux/bitops.h>
 #include <linux/user_namespace.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/mount.h>
 #include <linux/pid_namespace.h>
 #include <linux/fs_parser.h>
@@ -265,8 +266,6 @@ static int proc_fill_super(struct super_block *s, struct fs_context *fc)
 	if (ret)
 		return ret;
 
-	/* User space would break if executables or devices appear on proc */
-	s->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
 	s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC;
 	s->s_blocksize = 1024;
 	s->s_blocksize_bits = 10;
@@ -350,6 +349,7 @@ static int proc_init_fs_context(struct fs_context *fc)
 	put_user_ns(fc->user_ns);
 	fc->user_ns = get_user_ns(ctx->pid_ns->user_ns);
 	fc->fs_private = ctx;
+	fc_init_pseudo(fc);
 	fc->ops = &proc_fs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#14 lore raw

Re: [PATCH RFC v3 06/44] proc: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

Initialize procfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
author maintainer
#15 lore raw

RFC PATCH v3 7/44 binfmt_misc: use fc_init_pseudo()

In reply to Christian Brauner

Initialize binfmt_misc as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

---
 fs/binfmt_misc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/binfmt_misc.c +3 -2
index d945b4f6e1581..7dc233becd98d 100644
@@ -22,6 +22,7 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/init.h>
 #include <linux/kstrtox.h>
 #include <linux/limits.h>
@@ -1575,8 +1576,7 @@ static int bm_fill_super(struct super_block *sb, struct fs_context *fc)
 	if (user_ns != current_user_ns())
 		return -EINVAL;
 
-	/* Never exec off this instance and never let anything stack on it. */
-	sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
+	/* Never let anything stack on this instance. */
 	sb->s_stack_depth = FILESYSTEM_MAX_STACK_DEPTH;
 
 	/*
@@ -1660,6 +1660,7 @@ static void bm_kill_sb(struct super_block *sb)
 
 static int bm_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &bm_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#16 lore raw

Re: [PATCH RFC v3 07/44] binfmt_misc: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize binfmt_misc as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
author maintainer
#17 lore raw

RFC PATCH v3 8/44 mqueue: use fc_init_pseudo()

In reply to Christian Brauner

Initialize mqueue as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

---
 ipc/mqueue.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ipc/mqueue.c +2 -1
index 322c3dd98c447..8bbe32d0881f2 100644
@@ -18,6 +18,7 @@
 #include <linux/file.h>
 #include <linux/mount.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/namei.h>
 #include <linux/sysctl.h>
 #include <linux/poll.h>
@@ -405,7 +406,6 @@ static int mqueue_fill_super(struct super_block *sb, struct fs_context *fc)
 	struct inode *inode;
 	struct ipc_namespace *ns = sb->s_fs_info;
 
-	sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
 	sb->s_blocksize = PAGE_SIZE;
 	sb->s_blocksize_bits = PAGE_SHIFT;
 	sb->s_magic = MQUEUE_MAGIC;
@@ -457,6 +457,7 @@ static int mqueue_init_fs_context(struct fs_context *fc)
 	put_user_ns(fc->user_ns);
 	fc->user_ns = get_user_ns(ctx->ipc_ns->user_ns);
 	fc->fs_private = ctx;
+	fc_init_pseudo(fc);
 	fc->ops = &mqueue_fs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#18 lore raw

Re: [PATCH RFC v3 08/44] mqueue: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize mqueue as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
author maintainer
#19 lore raw

RFC PATCH v3 9/44 bpf: use fc_init_pseudo() for bpffs

In reply to Christian Brauner

Initialize bpffs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

---
 kernel/bpf/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/bpf/inode.c +2 -2
index c6f328e4752e1..57cf3775c0766 100644
@@ -15,6 +15,7 @@
 #include <linux/namei.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/kdev_t.h>
 #include <linux/filter.h>
@@ -1197,8 +1198,6 @@ static int bpf_fill_super(struct super_block *sb, struct fs_context *fc)
 	sb->s_magic = BPF_FS_MAGIC;
 	sb->s_op = &bpf_super_ops;
 	sb->s_xattr = bpf_fs_xattr_handlers;
-	sb->s_iflags |= SB_I_NOEXEC;
-	sb->s_iflags |= SB_I_NODEV;
 	sb->s_time_gran = 1;
 
 	inode = bpf_get_inode(sb, NULL, S_IFDIR | 0777);
@@ -1261,6 +1260,7 @@ static int bpf_init_fs_context(struct fs_context *fc)
 	opts->delegate_attachs = 0;
 
 	fc->s_fs_info = opts;
+	fc_init_pseudo(fc);
 	fc->ops = &bpf_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#20 lore raw

Re: [PATCH RFC v3 09/44] bpf: use fc_init_pseudo() for bpffs

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize bpffs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Acked-by on v3 9/44
#21 lore raw

Re: [PATCH RFC v3 09/44] bpf: use fc_init_pseudo() for bpffs

In reply to Christian Brauner
Quoted 4 lines · Christian Brauner

Initialize bpffs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Quoted 8 lines
---
 kernel/bpf/inode.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 34 lines
kernel/bpf/inode.c +2 -3
index c6f328e4752e1..57cf3775c0766 100644
@@ -15,6 +15,7 @@
 #include <linux/namei.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/kdev_t.h>
 #include <linux/filter.h>
@@ -1197,8 +1198,6 @@ static int bpf_fill_super(struct super_block *sb, struct fs_context *fc)
        sb->s_magic = BPF_FS_MAGIC;
        sb->s_op = &bpf_super_ops;
        sb->s_xattr = bpf_fs_xattr_handlers;
-       sb->s_iflags |= SB_I_NOEXEC;
-       sb->s_iflags |= SB_I_NODEV;
        sb->s_time_gran = 1;
 
        inode = bpf_get_inode(sb, NULL, S_IFDIR | 0777);
@@ -1261,6 +1260,7 @@ static int bpf_init_fs_context(struct fs_context *fc)
        opts->delegate_attachs = 0;
 
        fc->s_fs_info = opts;
+       fc_init_pseudo(fc);
        fc->ops = &bpf_context_ops;
        return 0;
 }
 
--

2.53.0

author maintainer
#22 lore raw

RFC PATCH v3 10/44 nullfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize nullfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

---
 fs/nullfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/nullfs.c +2 -1
index 319c2f5c5a671..2fe24cb97160e 100644
@@ -2,6 +2,7 @@
 /* Copyright (c) 2026 Christian Brauner <[email protected]> */
 #include <linux/fs/super_types.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/magic.h>
 #include <linux/splice.h>
 #include <linux/uio.h>
@@ -174,7 +175,7 @@ static int nullfs_init_fs_context(struct fs_context *fc)
 {
 	fc->ops		= &nullfs_fs_context_ops;
 	fc->sb_flags	|= SB_NOUSER;
-	fc->s_iflags	|= SB_I_NOEXEC | SB_I_NODEV;
+	fc_init_pseudo(fc);
 	return 0;
 }
 
Signature · 1 line
2.53.0
#23 lore raw

Re: [PATCH RFC v3 10/44] nullfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

Initialize nullfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
author maintainer
#24 lore raw

RFC PATCH v3 11/44 failfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize failfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

---
 fs/failfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/failfs.c +2 -1
index 437cdc981c2de..f03334f361c0e 100644
@@ -3,6 +3,7 @@
 #include <linux/fs.h>
 #include <linux/fs/super_types.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_struct.h>
 #include <linux/magic.h>
 #include <linux/mount.h>
@@ -132,7 +133,7 @@ static int failfs_init_fs_context(struct fs_context *fc)
 	fc->ops		= &failfs_context_ops;
 	fc->global	= true;
 	fc->sb_flags	|= SB_NOUSER;
-	fc->s_iflags	|= SB_I_NOEXEC | SB_I_NODEV;
+	fc_init_pseudo(fc);
 	return 0;
 }
 
Signature · 1 line
2.53.0
#25 lore raw

Re: [PATCH RFC v3 11/44] failfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize failfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Reviewed-by on v3 11/44
#26 lore raw

Re: [PATCH RFC v3 11/44] failfs: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 6 lines · Christian Brauner

Initialize failfs as a pseudo filesystem instead of raising SB_I_NOEXEC and SB_I_NODEV by hand. This adds SB_I_PSEUDO.

Quoted 27 lines

---
 fs/failfs.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
fs/failfs.c +2 -1
index 437cdc981c2de..f03334f361c0e 100644
@@ -3,6 +3,7 @@
  #include <linux/fs.h>
  #include <linux/fs/super_types.h>
  #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
  #include <linux/fs_struct.h>
  #include <linux/magic.h>
  #include <linux/mount.h>
@@ -132,7 +133,7 @@ static int failfs_init_fs_context(struct
 fs_context *fc)
  	fc->ops		= &failfs_context_ops;
  	fc->global	= true;
  	fc->sb_flags	|= SB_NOUSER;
-	fc->s_iflags	|= SB_I_NOEXEC | SB_I_NODEV;
+	fc_init_pseudo(fc);
  	return 0;
  }

author maintainer
#27 lore raw

RFC PATCH v3 12/44 rust_binderfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize binderfs as a pseudo filesystem instead of raising SB_I_NOEXEC by hand. This adds SB_I_PSEUDO. binderfs_fill_super() keeps clearing SB_I_NODEV for the binder device nodes.

---
 drivers/android/binder/rust_binderfs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/android/binder/rust_binderfs.c +2 -1
index 5f020226720db..04468c5b5c116 100644
@@ -3,6 +3,7 @@
 #include <linux/compiler_types.h>
 #include <linux/errno.h>
 #include <linux/fs.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fsnotify.h>
 #include <linux/gfp.h>
 #include <linux/idr.h>
@@ -667,7 +668,6 @@ static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
 	 * necessary and safe.
 	 */
 	sb->s_iflags &= ~SB_I_NODEV;
-	sb->s_iflags |= SB_I_NOEXEC;
 	sb->s_magic = RUST_BINDERFS_SUPER_MAGIC;
 	sb->s_op = &binderfs_super_ops;
 	sb->s_time_gran = 1;
@@ -759,6 +759,7 @@ static int binderfs_init_fs_context(struct fs_context *fc)
 	ctx->stats_mode = binderfs_stats_mode_unset;
 
 	fc->fs_private = ctx;
+	fc_init_pseudo(fc);
 	fc->ops = &binderfs_fs_context_ops;
 
 	return 0;
Signature · 1 line
2.53.0
#28 lore raw

Re: [PATCH RFC v3 12/44] rust_binderfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

Initialize binderfs as a pseudo filesystem instead of raising SB_I_NOEXEC by hand. This adds SB_I_PSEUDO. binderfs_fill_super() keeps clearing SB_I_NODEV for the binder device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Reviewed-by on v3 12/44
#30 lore raw

Re: [PATCH RFC v3 12/44] rust_binderfs: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 6 lines · Christian Brauner

Initialize binderfs as a pseudo filesystem instead of raising SB_I_NOEXEC
by hand. This adds SB_I_PSEUDO. binderfs_fill_super() keeps clearing SB_I_NODEV for the binder device nodes.

Quoted 35 lines

---
 drivers/android/binder/rust_binderfs.c | 3 ++-

 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/android/binder/rust_binderfs.c +1 -1
index 5f020226720db..04468c5b5c116 100644
@@ -3,6 +3,7 @@
  #include <linux/compiler_types.h>
  #include <linux/errno.h>
  #include <linux/fs.h>
+#include <linux/pseudo_fs.h>
  #include <linux/fsnotify.h>
  #include <linux/gfp.h>
  #include <linux/idr.h>
@@ -667,7 +668,6 @@ static int binderfs_fill_super(struct super_block
 *sb, struct fs_context *fc)
  	 * necessary and safe.
  	 */
  	sb->s_iflags &= ~SB_I_NODEV;
-	sb->s_iflags |= SB_I_NOEXEC;
  	sb->s_magic = RUST_BINDERFS_SUPER_MAGIC;
  	sb->s_op = &binderfs_super_ops;

  sb->s_time_gran = 1;

drivers/android/binder/rust_binderfs.c +0 -0
@@ -759,6 +759,7 @@ static int binderfs_init_fs_context(struct
 fs_context *fc)
  	ctx->stats_mode = binderfs_stats_mode_unset;


  fc->fs_private = ctx;

drivers/android/binder/rust_binderfs.c +1 -0
+	fc_init_pseudo(fc);

  fc->ops = &binderfs_fs_context_ops;

  return 0;

author maintainer
#31 lore raw

RFC PATCH v3 13/44 devpts: use fc_init_pseudo()

In reply to Christian Brauner

Initialize devpts as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. devpts never holds executables. devpts_fill_super() keeps clearing SB_I_NODEV for the pty device nodes.

---
 fs/devpts/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/devpts/inode.c +2 -0
index bd1e8eb26edb7..47ef12241d92d 100644
@@ -13,6 +13,7 @@
 #include <linux/init.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/sched.h>
 #include <linux/namei.h>
@@ -438,6 +439,7 @@ static int devpts_init_fs_context(struct fs_context *fc)
 		fsi->mount_opts.reserve = true;
 
 	fc->s_fs_info = fsi;
+	fc_init_pseudo(fc);
 	fc->ops = &devpts_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#32 lore raw

Re: [PATCH RFC v3 13/44] devpts: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize devpts as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. devpts never holds executables. devpts_fill_super() keeps clearing SB_I_NODEV for the pty device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
author maintainer
#33 lore raw

RFC PATCH v3 14/44 debugfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize debugfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. debugfs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. The debugfs files that can be mapped, kcov, relay channels and powernv's memtrace, map data.

---
 fs/debugfs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/debugfs/inode.c +2 -0
index b4915551ad315..f163f0bc5703a 100644
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>
@@ -317,6 +318,7 @@ static int debugfs_init_fs_context(struct fs_context *fc)
 	fsi->mode = DEBUGFS_DEFAULT_MODE;
 
 	fc->s_fs_info = fsi;
+	fc_init_pseudo(fc);
 	fc->ops = &debugfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#34 lore raw

Re: [PATCH RFC v3 14/44] debugfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Initialize debugfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. debugfs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. The debugfs files that can be mapped, kcov, relay channels and powernv's memtrace, map data.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
author maintainer
#35 lore raw

RFC PATCH v3 15/44 tracefs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize tracefs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. tracefs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. The only tracefs files that can be mapped are the ring buffers and __rb_map_vma() refuses VM_EXEC already.

---
 fs/tracefs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/tracefs/inode.c +2 -0
index 5020365ca7048..e04febd868eb4 100644
@@ -12,6 +12,7 @@
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/kobject.h>
 #include <linux/namei.h>
@@ -510,6 +511,7 @@ static int tracefs_init_fs_context(struct fs_context *fc)
 	fsi->mode = TRACEFS_DEFAULT_MODE;
 
 	fc->s_fs_info = fsi;
+	fc_init_pseudo(fc);
 	fc->ops = &tracefs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#36 lore raw

Re: [PATCH RFC v3 15/44] tracefs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Initialize tracefs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. tracefs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. The only tracefs files that can be mapped are the ring buffers and __rb_map_vma() refuses VM_EXEC already.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
author maintainer
#37 lore raw

RFC PATCH v3 16/44 configfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize configfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. configfs never holds executables or device nodes.

---
 fs/configfs/mount.c | 2 ++
 1 file changed, 2 insertions(+)
fs/configfs/mount.c +2 -0
index d8cac1cbf3bd5..60ba24e7ae2b9 100644
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/mount.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>
 #include <linux/slab.h>
@@ -106,6 +107,7 @@ static const struct fs_context_operations configfs_context_ops = {
 
 static int configfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &configfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#38 lore raw

Re: [PATCH RFC v3 16/44] configfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

Initialize configfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. configfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
author maintainer
#39 lore raw

RFC PATCH v3 17/44 securityfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize securityfs as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. securityfs never holds executables.

But securityfs needs device nodes. AppArmor puts a .null device node into securityfs. On exec it replaces file descriptors the new profile isn't allowed to use with that node and opens it via dentry_open() which doesn't care about SB_I_NODEV. Such a file descriptor can still be reopened through /proc/<pid>/fd/<nr> though and that's what opening /dev/stderr does. The node itself can also be opened by path as /sys/kernel/security/apparmor/.null. Both go through may_open_dev() which refuses device nodes with SB_I_NODEV raised. So clear SB_I_NODEV again in securityfs_fill_super().

---
 security/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
security/inode.c +4 -0
index 0804023676741..edaebf0f1972d 100644
@@ -14,6 +14,7 @@
 #include <linux/kobject.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/mount.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>
@@ -49,6 +50,8 @@ static int securityfs_fill_super(struct super_block *sb, struct fs_context *fc)
 		return error;
 
 	sb->s_op = &securityfs_super_operations;
+	/* Userspace may open AppArmor's .null device node by path. */
+	sb->s_iflags &= ~SB_I_NODEV;
 
 	return 0;
 }
@@ -64,6 +67,7 @@ static const struct fs_context_operations securityfs_context_ops = {
 
 static int securityfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &securityfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#40 lore raw

Re: [PATCH RFC v3 17/44] securityfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

Initialize securityfs as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. securityfs never holds executables.

But securityfs needs device nodes. AppArmor puts a .null device node into securityfs. On exec it replaces file descriptors the new profile isn't allowed to use with that node and opens it via dentry_open() which doesn't care about SB_I_NODEV. Such a file descriptor can still be reopened through /proc/<pid>/fd/<nr> though and that's what opening /dev/stderr does. The node itself can also be opened by path as /sys/kernel/security/apparmor/.null. Both go through may_open_dev() which refuses device nodes with SB_I_NODEV raised. So clear SB_I_NODEV again in securityfs_fill_super().

Quoted 3 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
maintainer Acked-by on v3 17/44
#41 lore raw

Re: [PATCH RFC v3 17/44] securityfs: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 34 lines · On Nov 16, 2026 [email protected] wrote:

Initialize securityfs as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. securityfs never holds executables.

But securityfs needs device nodes. AppArmor puts a .null device node into securityfs. On exec it replaces file descriptors the new profile isn't allowed to use with that node and opens it via dentry_open() which doesn't care about SB_I_NODEV. Such a file descriptor can still be reopened through /proc/<pid>/fd/<nr> though and that's what opening /dev/stderr does. The node itself can also be opened by path as /sys/kernel/security/apparmor/.null. Both go through may_open_dev() which refuses device nodes with SB_I_NODEV raised. So clear SB_I_NODEV again in securityfs_fill_super().

---
 security/inode.c | 4 ++++
 1 file changed, 4 insertions(+)
security/inode.c +1 -0
index 0804023676741..edaebf0f1972d 100644
@@ -14,6 +14,7 @@
 #include <linux/kobject.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/mount.h>
 #include <linux/pagemap.h>
 #include <linux/init.h>

security/inode.c static int securityfs_fill_super(struct super_block *sb, struct fs_context *fc) · line 54

Quoted 5 lines
security/inode.c +2 -0
@@ -49,6 +50,8 @@ static int securityfs_fill_super(struct super_block *sb, struct fs_context *fc)
 		return error;
 
 	sb->s_op = &securityfs_super_operations;
+	/* Userspace may open AppArmor's .null device node by path. */
+	sb->s_iflags &= ~SB_I_NODEV;

AppArmor itself does a dentry_open() on its null device to effectively block inheritence of open files if not permitted by policy. SELinux basically does the same thing, in fact AppArmor's aa_inherit_files() is based on SELinux's flush_unauthorized_files() according to the comments.

Anyway, I'd suggest changing your comment to something like the following, but it's not critical.

/* Allow for LSM specific null device nodes */

Quoted 13 lines
security/inode.c +1 -0
 	return 0;
 }
@@ -64,6 +67,7 @@ static const struct fs_context_operations securityfs_context_ops = {
 
 static int securityfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &securityfs_context_ops;
 	return 0;
 }
Signature · 2 lines
-- 
2.53.0

--
paul-moore.com

author maintainer
#42 lore raw

RFC PATCH v3 18/44 selinux: use fc_init_pseudo() for selinuxfs

In reply to Christian Brauner

Initialize selinuxfs as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. selinuxfs never holds executables. SB_I_NOEXEC also refuses PROT_EXEC mappings but the status and policy files are only ever mapped for reading.

But selinuxfs needs device nodes. The kernel replaces file descriptors with /sys/fs/selinux/null on exec via dentry_open() which doesn't care about SB_I_NODEV. Android init however opens /sys/fs/selinux/null by path as /dev/null doesn't exist yet at that point. So clear SB_I_NODEV again in sel_fill_super().

---
 security/selinux/selinuxfs.c | 5 +++++
 1 file changed, 5 insertions(+)
security/selinux/selinuxfs.c +5 -0
index 310e19efff1d0..d7ae853b6d685 100644
@@ -18,6 +18,7 @@
 #include <linux/vmalloc.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/hex.h>
 #include <linux/mount.h>
 #include <linux/mutex.h>
@@ -1852,6 +1853,9 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc)
 		/* last one */ {"", NULL, 0}
 	};
 
+	/* Android init opens the null device below by path. */
+	sb->s_iflags &= ~SB_I_NODEV;
+
 	ret = selinux_fs_info_create(sb);
 	if (ret)
 		goto err;
@@ -1955,6 +1959,7 @@ static const struct fs_context_operations sel_context_ops = {
 
 static int sel_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &sel_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#43 lore raw

Re: [PATCH RFC v3 18/44] selinux: use fc_init_pseudo() for selinuxfs

Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Initialize selinuxfs as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. selinuxfs never holds executables. SB_I_NOEXEC also refuses PROT_EXEC mappings but the status and policy files are only ever mapped for reading.

But selinuxfs needs device nodes. The kernel replaces file descriptors with /sys/fs/selinux/null on exec via dentry_open() which doesn't care about SB_I_NODEV. Android init however opens /sys/fs/selinux/null by path as /dev/null doesn't exist yet at that point. So clear SB_I_NODEV again in sel_fill_super().

Quoted 3 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
maintainer Acked-by on v3 18/44
#44 lore raw

Re: [PATCH RFC v3 18/44] selinux: use fc_init_pseudo() for selinuxfs

In reply to Christian Brauner
Quoted 33 lines · On Nov 16, 2026 [email protected] wrote:

Initialize selinuxfs as a pseudo filesystem. This raises SB_I_PSEUDO and SB_I_NOEXEC. selinuxfs never holds executables. SB_I_NOEXEC also refuses PROT_EXEC mappings but the status and policy files are only ever mapped for reading.

But selinuxfs needs device nodes. The kernel replaces file descriptors with /sys/fs/selinux/null on exec via dentry_open() which doesn't care about SB_I_NODEV. Android init however opens /sys/fs/selinux/null by path as /dev/null doesn't exist yet at that point. So clear SB_I_NODEV again in sel_fill_super().

---
 security/selinux/selinuxfs.c | 5 +++++
 1 file changed, 5 insertions(+)
security/selinux/selinuxfs.c +1 -0
index 310e19efff1d0..d7ae853b6d685 100644
@@ -18,6 +18,7 @@
 #include <linux/vmalloc.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/hex.h>
 #include <linux/mount.h>
 #include <linux/mutex.h>

security/selinux/selinuxfs.c static int sel_fill_super(struct super_block *sb, struct fs_context *fc) · line 1857

Quoted 5 lines
security/selinux/selinuxfs.c +2 -0
@@ -1852,6 +1853,9 @@ static int sel_fill_super(struct super_block *sb, struct fs_context *fc)
 		/* last one */ {"", NULL, 0}
 	};
 
+	/* Android init opens the null device below by path. */
+	sb->s_iflags &= ~SB_I_NODEV;

See my comment in patch 17/44, this is also used internally in the flush_unauthorized_files() function. Once again I would prefer the comment to be changed to the following:

/* allow for the /sys/fs/selinux/null device node */

Quoted 14 lines
security/selinux/selinuxfs.c +1 -0
 	ret = selinux_fs_info_create(sb);
 	if (ret)
 		goto err;
@@ -1955,6 +1959,7 @@ static const struct fs_context_operations sel_context_ops = {
 
 static int sel_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &sel_context_ops;
 	return 0;
 }
Signature · 2 lines
-- 
2.53.0

--
paul-moore.com

author maintainer
#45 lore raw

RFC PATCH v3 19/44 smack: use fc_init_pseudo() for smackfs

In reply to Christian Brauner

Initialize smackfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. smackfs never holds executables or device nodes.

---
 security/smack/smackfs.c | 2 ++
 1 file changed, 2 insertions(+)
security/smack/smackfs.c +2 -0
index a72bc7fabea99..4a56bbeaeca37 100644
@@ -25,6 +25,7 @@
 #include <linux/magic.h>
 #include <linux/mount.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include "smack.h"
 
 #define BEBITS	(sizeof(__be32) * 8)
@@ -2880,6 +2881,7 @@ static const struct fs_context_operations smk_context_ops = {
  */
 static int smk_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &smk_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#46 lore raw

Re: [PATCH RFC v3 19/44] smack: use fc_init_pseudo() for smackfs

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

Initialize smackfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. smackfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
author maintainer
#47 lore raw

RFC PATCH v3 20/44 apparmor: use fc_init_pseudo() for apparmorfs

In reply to Christian Brauner

Initialize apparmorfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. apparmorfs never holds executables or device nodes.

---
 security/apparmor/apparmorfs.c | 2 ++
 1 file changed, 2 insertions(+)
security/apparmor/apparmorfs.c +2 -0
index a993664672173..351ea3a7120e3 100644
@@ -21,6 +21,7 @@
 #include <linux/rcupdate.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/poll.h>
 #include <linux/zstd.h>
 #include <linux/string.h>
@@ -263,6 +264,7 @@ static const struct fs_context_operations apparmorfs_context_ops = {
 
 static int apparmorfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &apparmorfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#48 lore raw

Re: [PATCH RFC v3 20/44] apparmor: use fc_init_pseudo() for apparmorfs

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize apparmorfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. apparmorfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
author maintainer
#49 lore raw

RFC PATCH v3 21/44 nfsd: use fc_init_pseudo()

In reply to Christian Brauner

Initialize the nfsd filesystem as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. It never holds executables or device nodes.

---
 fs/nfsd/nfsctl.c | 2 ++
 1 file changed, 2 insertions(+)
fs/nfsd/nfsctl.c +2 -0
index f32311f2d7cf9..ce2666deddbd9 100644
@@ -9,6 +9,7 @@
 #include <linux/namei.h>
 #include <linux/ctype.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 
 #include <linux/sunrpc/cache.h>
 #include <linux/sunrpc/svcsock.h>
@@ -1375,6 +1376,7 @@ static int nfsd_init_fs_context(struct fs_context *fc)
 {
 	put_user_ns(fc->user_ns);
 	fc->user_ns = get_user_ns(fc->net_ns->user_ns);
+	fc_init_pseudo(fc);
 	fc->ops = &nfsd_fs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#50 lore raw

Re: [PATCH RFC v3 21/44] nfsd: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize the nfsd filesystem as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. It never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Reviewed-by on v3 21/44
#51 lore raw

Re: [PATCH RFC v3 21/44] nfsd: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 6 lines · Christian Brauner

Initialize the nfsd filesystem as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. It never holds executables or device nodes.

Quoted 26 lines

---
 fs/nfsd/nfsctl.c | 2 ++

 1 file changed, 2 insertions(+)
fs/nfsd/nfsctl.c +1 -0
index f32311f2d7cf9..ce2666deddbd9 100644
@@ -9,6 +9,7 @@
  #include <linux/namei.h>
  #include <linux/ctype.h>
  #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>


 #include <linux/sunrpc/cache.h>
 #include <linux/sunrpc/svcsock.h>

fs/nfsd/nfsctl.c +1 -0
@@ -1375,6 +1376,7 @@ static int nfsd_init_fs_context(struct
 fs_context *fc)
  {
  	put_user_ns(fc->user_ns);
  	fc->user_ns = get_user_ns(fc->net_ns->user_ns);
+	fc_init_pseudo(fc);
  	fc->ops = &nfsd_fs_context_ops;
  	return 0;

 }

author maintainer
#52 lore raw

RFC PATCH v3 22/44 sunrpc: use fc_init_pseudo() for rpc_pipefs

In reply to Christian Brauner

Initialize rpc_pipefs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. rpc_pipefs never holds executables or device nodes.

---
 net/sunrpc/rpc_pipe.c | 2 ++
 1 file changed, 2 insertions(+)
net/sunrpc/rpc_pipe.c +2 -0
index 9d349cfbc4831..37277a6d24156 100644
@@ -15,6 +15,7 @@
 #include <linux/pagemap.h>
 #include <linux/mount.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/namei.h>
 #include <linux/fsnotify.h>
 #include <linux/kernel.h>
@@ -1181,6 +1182,7 @@ static int rpc_init_fs_context(struct fs_context *fc)
 {
 	put_user_ns(fc->user_ns);
 	fc->user_ns = get_user_ns(fc->net_ns->user_ns);
+	fc_init_pseudo(fc);
 	fc->ops = &rpc_fs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#53 lore raw

Re: [PATCH RFC v3 22/44] sunrpc: use fc_init_pseudo() for rpc_pipefs

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize rpc_pipefs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. rpc_pipefs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
author maintainer
#54 lore raw

RFC PATCH v3 23/44 fuse: use fc_init_pseudo() for fusectl

In reply to Christian Brauner

Initialize fusectl as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. fusectl never holds executables or device nodes.

---
 fs/fuse/control.c | 2 ++
 1 file changed, 2 insertions(+)
fs/fuse/control.c +2 -0
index 21ffde596d611..4497362e7df06 100644
@@ -10,6 +10,7 @@
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/namei.h>
 
 #define FUSE_CTL_SUPER_MAGIC 0x65735543
@@ -334,6 +335,7 @@ static const struct fs_context_operations fuse_ctl_context_ops = {
 
 static int fuse_ctl_init_fs_context(struct fs_context *fsc)
 {
+	fc_init_pseudo(fsc);
 	fsc->ops = &fuse_ctl_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#55 lore raw

Re: [PATCH RFC v3 23/44] fuse: use fc_init_pseudo() for fusectl

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize fusectl as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. fusectl never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
author maintainer
#56 lore raw

RFC PATCH v3 24/44 efivarfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize efivarfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. efivarfs never holds executables or device nodes.

---
 fs/efivarfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
fs/efivarfs/super.c +2 -0
index 12746ced6dc63..e598d42c5f42c 100644
@@ -8,6 +8,7 @@
 #include <linux/efi.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/module.h>
 #include <linux/pagemap.h>
@@ -554,6 +555,7 @@ static int efivarfs_init_fs_context(struct fs_context *fc)
 	}
 
 	fc->s_fs_info = sfi;
+	fc_init_pseudo(fc);
 	fc->ops = &efivarfs_context_ops;
 
 	return 0;
Signature · 1 line
2.53.0
#57 lore raw

Re: [PATCH RFC v3 24/44] efivarfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize efivarfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. efivarfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
author maintainer
#58 lore raw

RFC PATCH v3 25/44 pstore: use fc_init_pseudo()

In reply to Christian Brauner

Initialize pstore as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. pstore never holds executables or device nodes.

---
 fs/pstore/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/pstore/inode.c +2 -0
index cf499ba727026..4658561cf90b7 100644
@@ -18,6 +18,7 @@
 #include <linux/ramfs.h>
 #include <linux/fs_parser.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/sched.h>
 #include <linux/magic.h>
 #include <linux/pstore.h>
@@ -491,6 +492,7 @@ static int pstore_init_fs_context(struct fs_context *fc)
 	ctx->kmsg_bytes = kmsg_bytes;
 
 	fc->fs_private = ctx;
+	fc_init_pseudo(fc);
 	fc->ops = &pstore_context_ops;
 
 	return 0;
Signature · 1 line
2.53.0
#59 lore raw

Re: [PATCH RFC v3 25/44] pstore: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize pstore as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. pstore never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
author maintainer
#60 lore raw

RFC PATCH v3 26/44 xenfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize xenfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. xenfs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. xenfs maps the xenstore page and guest memory through privcmd, both data.

---
 drivers/xen/xenfs/super.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/xen/xenfs/super.c +2 -0
index 37ea7c5c03469..aba7d038ed735 100644
@@ -15,6 +15,7 @@
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/magic.h>
 
 #include <xen/xen.h>
@@ -80,6 +81,7 @@ static const struct fs_context_operations xenfs_context_ops = {
 
 static int xenfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &xenfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#61 lore raw

Re: [PATCH RFC v3 26/44] xenfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

Initialize xenfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. xenfs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. xenfs maps the xenstore page and guest memory through privcmd, both data.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
Reviewed-by on v3 26/44
#62 lore raw

Re: [PATCH RFC v3 26/44] xenfs: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 8 lines · Christian Brauner

Initialize xenfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. xenfs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. xenfs maps the xenstore page and guest memory through privcmd, both data.

Quoted 26 lines

---
 drivers/xen/xenfs/super.c | 2 ++

 1 file changed, 2 insertions(+)
drivers/xen/xenfs/super.c +1 -0
index 37ea7c5c03469..aba7d038ed735 100644
@@ -15,6 +15,7 @@
  #include <linux/module.h>
  #include <linux/fs.h>
  #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
  #include <linux/magic.h>


 #include <xen/xen.h>

drivers/xen/xenfs/super.c +0 -0
@@ -80,6 +81,7 @@ static const struct fs_context_operations
 xenfs_context_ops = {


 static int xenfs_init_fs_context(struct fs_context *fc) {

drivers/xen/xenfs/super.c +1 -0
+	fc_init_pseudo(fc);

  fc->ops = &xenfs_context_ops;
  return 0;
 }

author maintainer
#63 lore raw

RFC PATCH v3 27/44 openpromfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize openpromfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. openpromfs never holds executables or device nodes.

---
 fs/openpromfs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
fs/openpromfs/inode.c +2 -0
index fb8d84bdedfb2..6cd02d456bac9 100644
@@ -10,6 +10,7 @@
 #include <linux/string.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
@@ -419,6 +420,7 @@ static const struct fs_context_operations openpromfs_context_ops = {
 
 static int openpromfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &openpromfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#64 lore raw

Re: [PATCH RFC v3 27/44] openpromfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

Initialize openpromfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. openpromfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
Reviewed-by on v3 27/44
#65 lore raw

Re: [PATCH RFC v3 27/44] openpromfs: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 7 lines · Christian Brauner

Initialize openpromfs as a pseudo filesystem. This raises SB_I_PSEUDO and
also SB_I_NOEXEC and SB_I_NODEV. openpromfs never holds executables or
device nodes.

Quoted 25 lines

---
 fs/openpromfs/inode.c | 2 ++

 1 file changed, 2 insertions(+)
fs/openpromfs/inode.c +1 -0
index fb8d84bdedfb2..6cd02d456bac9 100644
@@ -10,6 +10,7 @@
  #include <linux/string.h>
  #include <linux/fs.h>
  #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
  #include <linux/init.h>
  #include <linux/slab.h>
  #include <linux/seq_file.h>
@@ -419,6 +420,7 @@ static const struct fs_context_operations
 openpromfs_context_ops = {


 static int openpromfs_init_fs_context(struct fs_context *fc) {

fs/openpromfs/inode.c +1 -0
+	fc_init_pseudo(fc);

  fc->ops = &openpromfs_context_ops;
  return 0;
 }

author maintainer
#66 lore raw

RFC PATCH v3 28/44 ocfs2: use fc_init_pseudo() for dlmfs

In reply to Christian Brauner

Initialize dlmfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. dlmfs never holds executables or device nodes.

---
 fs/ocfs2/dlmfs/dlmfs.c | 2 ++
 1 file changed, 2 insertions(+)
fs/ocfs2/dlmfs/dlmfs.c +2 -0
index d3bfcada3e3bf..1789ec96dc130 100644
@@ -21,6 +21,7 @@
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/pagemap.h>
 #include <linux/types.h>
 #include <linux/slab.h>
@@ -563,6 +564,7 @@ static const struct fs_context_operations dlmfs_context_ops = {
 
 static int dlmfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &dlmfs_context_ops;
 
 	return 0;
Signature · 1 line
2.53.0
#67 lore raw

Re: [PATCH RFC v3 28/44] ocfs2: use fc_init_pseudo() for dlmfs

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

Initialize dlmfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. dlmfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Reviewed-by on v3 28/44
#68 lore raw

Re: [PATCH RFC v3 28/44] ocfs2: use fc_init_pseudo() for dlmfs

In reply to Christian Brauner
Quoted 6 lines · Christian Brauner

Initialize dlmfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. dlmfs never holds executables or device nodes.

Quoted 26 lines

---
 fs/ocfs2/dlmfs/dlmfs.c | 2 ++

 1 file changed, 2 insertions(+)
fs/ocfs2/dlmfs/dlmfs.c +1 -0
index d3bfcada3e3bf..1789ec96dc130 100644
@@ -21,6 +21,7 @@
  #include <linux/module.h>
  #include <linux/fs.h>
  #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
  #include <linux/pagemap.h>
  #include <linux/types.h>
  #include <linux/slab.h>
@@ -563,6 +564,7 @@ static const struct fs_context_operations
 dlmfs_context_ops = {


 static int dlmfs_init_fs_context(struct fs_context *fc) {

fs/ocfs2/dlmfs/dlmfs.c +1 -0
+	fc_init_pseudo(fc);

  fc->ops = &dlmfs_context_ops;

  return 0;

author maintainer
#69 lore raw

RFC PATCH v3 29/44 s390/hypfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize hypfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. hypfs never holds executables or device nodes.

---
 arch/s390/hypfs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
arch/s390/hypfs/inode.c +2 -0
index 559b011e68800..8662169de477a 100644
@@ -12,6 +12,7 @@
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/namei.h>
 #include <linux/vfs.h>
@@ -301,6 +302,7 @@ static int hypfs_init_fs_context(struct fs_context *fc)
 	sbi->gid = current_gid();
 
 	fc->s_fs_info = sbi;
+	fc_init_pseudo(fc);
 	fc->ops = &hypfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#70 lore raw

Re: [PATCH RFC v3 29/44] s390/hypfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 5 lines

Initialize hypfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. hypfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Reviewed-by on v3 29/44
#71 lore raw

Re: [PATCH RFC v3 29/44] s390/hypfs: use fc_init_pseudo()

In reply to Christian Brauner
Quoted 4 lines · Christian Brauner

Initialize hypfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. hypfs never holds executables or device nodes.

Quoted 26 lines

---
 arch/s390/hypfs/inode.c | 2 ++

 1 file changed, 2 insertions(+)
arch/s390/hypfs/inode.c +1 -0
index 559b011e68800..8662169de477a 100644
@@ -12,6 +12,7 @@
  #include <linux/errno.h>
  #include <linux/fs.h>
  #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
  #include <linux/fs_parser.h>
  #include <linux/namei.h>
  #include <linux/vfs.h>
@@ -301,6 +302,7 @@ static int hypfs_init_fs_context(struct
 fs_context *fc)
  	sbi->gid = current_gid();


  fc->s_fs_info = sbi;

arch/s390/hypfs/inode.c +1 -0
+	fc_init_pseudo(fc);

  fc->ops = &hypfs_context_ops;
  return 0;
 }

author maintainer
#72 lore raw

RFC PATCH v3 30/44 powerpc/spufs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize spufs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. spufs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. The spufs files that can be mapped expose local store and problem state areas of the SPU, nothing the PPU executes.

---
 arch/powerpc/platforms/cell/spufs/inode.c | 2 ++
 1 file changed, 2 insertions(+)
arch/powerpc/platforms/cell/spufs/inode.c +2 -0
index f066d9c7344d3..54b45932aecd2 100644
@@ -11,6 +11,7 @@
 #include <linux/file.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/fs_parser.h>
 #include <linux/fsnotify.h>
 #include <linux/backing-dev.h>
@@ -741,6 +742,7 @@ static int spufs_init_fs_context(struct fs_context *fc)
 
 	fc->fs_private = ctx;
 	fc->s_fs_info = sbi;
+	fc_init_pseudo(fc);
 	fc->ops = &spufs_context_ops;
 	return 0;
 
Signature · 1 line
2.53.0
#73 lore raw

Re: [PATCH RFC v3 30/44] powerpc/spufs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

Initialize spufs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. spufs never holds executables or device nodes.

SB_I_NOEXEC also refuses PROT_EXEC mappings. The spufs files that can be mapped expose local store and problem state areas of the SPU, nothing the PPU executes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
author maintainer
#74 lore raw

RFC PATCH v3 31/44 usb: gadget: f_fs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize functionfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. functionfs never holds executables or device nodes.

---
 drivers/usb/gadget/function/f_fs.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/gadget/function/f_fs.c +2 -0
index c64a268e98a43..a6b3788399a56 100644
@@ -15,6 +15,7 @@
 /* #define VERBOSE_DEBUG */
 
 #include <linux/blkdev.h>
+#include <linux/pseudo_fs.h>
 #include <linux/dma-buf.h>
 #include <linux/dma-fence.h>
 #include <linux/dma-resv.h>
@@ -2166,6 +2167,7 @@ static int ffs_fs_init_fs_context(struct fs_context *fc)
 	ctx->no_disconnect = false;
 
 	fc->fs_private = ctx;
+	fc_init_pseudo(fc);
 	fc->ops = &ffs_fs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#75 lore raw

Re: [PATCH RFC v3 31/44] usb: gadget: f_fs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

Initialize functionfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. functionfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
author maintainer
#76 lore raw

RFC PATCH v3 32/44 usb: gadget: gadgetfs: use fc_init_pseudo()

In reply to Christian Brauner

Initialize gadgetfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. gadgetfs never holds executables or device nodes.

---
 drivers/usb/gadget/legacy/inode.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/usb/gadget/legacy/inode.c +2 -0
index 7f6d8460152f9..8490e5d0351e1 100644
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/fs_context.h>
+#include <linux/pseudo_fs.h>
 #include <linux/pagemap.h>
 #include <linux/uts.h>
 #include <linux/wait.h>
@@ -2223,6 +2224,7 @@ static const struct fs_context_operations gadgetfs_context_ops = {
 
 static int gadgetfs_init_fs_context(struct fs_context *fc)
 {
+	fc_init_pseudo(fc);
 	fc->ops = &gadgetfs_context_ops;
 	return 0;
 }
Signature · 1 line
2.53.0
#77 lore raw

Re: [PATCH RFC v3 32/44] usb: gadget: gadgetfs: use fc_init_pseudo()

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

Initialize gadgetfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. gadgetfs never holds executables or device nodes.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
author maintainer
#78 lore raw

RFC PATCH v3 33/44 ovl: refuse data-only layers on pseudo filesystems

In reply to Christian Brauner

The data of a metacopy file can live in a data-only layer. overlayfs doesn't look that data up when it looks up the file. It only remembers the absolute redirect and looks up the data lazily the first time someone needs it. So until then nothing can tell which filesystem holds the data of such a file.

But a data-only layer has no business being a pseudo filesystem in the first place. All it does is hold the data of metacopy files and the regular files of a pseudo filesystem are kernel interfaces, not storage. So let's refuse data-only layers on superblocks with SB_I_PSEUDO at mount time.

Data-only layers can be added via the "::" separator in "lowerdir=" and via "datadir+" by path or by file descriptor. All of them end up at the end of ctx->lower. So a single check in ovl_get_lowerstack() covers all of them.

Note that regular lower layers on pseudo filesystems are left alone. Stacking overlayfs on top of sysfs keeps working.

---
 fs/overlayfs/super.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/overlayfs/super.c +8 -0
index 39d4d57dec230..719c2569dfeaf 100644
@@ -1237,6 +1237,14 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
 	for (i = 0; i < ctx->nr; i++) {
 		l = &ctx->lower[i];
 
+		/* Pseudo filesystems don't hold data for metacopy files. */
+		if (i >= ctx->nr - ctx->nr_data &&
+		    (l->path.dentry->d_sb->s_iflags & SB_I_PSEUDO)) {
+			pr_err("filesystem on %s not supported as data-only layer\n",
+			       l->name);
+			return ERR_PTR(-EINVAL);
+		}
+
 		err = ovl_lower_dir(l->name, &l->path, ofs, &sb->s_stack_depth);
 		if (err)
 			return ERR_PTR(err);
Signature · 1 line
2.53.0
#79 lore raw

Re: [PATCH RFC v3 33/44] ovl: refuse data-only layers on pseudo filesystems

Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

The data of a metacopy file can live in a data-only layer. overlayfs doesn't look that data up when it looks up the file. It only remembers the absolute redirect and looks up the data lazily the first time someone needs it. So until then nothing can tell which filesystem holds the data of such a file.

But a data-only layer has no business being a pseudo filesystem in the first place. All it does is hold the data of metacopy files and the regular files of a pseudo filesystem are kernel interfaces, not storage. So let's refuse data-only layers on superblocks with SB_I_PSEUDO at mount time.

Data-only layers can be added via the "::" separator in "lowerdir=" and via "datadir+" by path or by file descriptor. All of them end up at the end of ctx->lower. So a single check in ovl_get_lowerstack() covers all of them.

Quoted 6 lines

Note that regular lower layers on pseudo filesystems are left alone. Stacking overlayfs on top of sysfs keeps working.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=33
maintainer
#80 lore raw

Re: [PATCH RFC v3 33/44] ovl: refuse data-only layers on pseudo filesystems

In reply to Christian Brauner
Quoted 34 lines · Christian Brauner

The data of a metacopy file can live in a data-only layer. overlayfs doesn't look that data up when it looks up the file. It only remembers the absolute redirect and looks up the data lazily the first time someone needs it. So until then nothing can tell which filesystem holds the data of such a file.

But a data-only layer has no business being a pseudo filesystem in the first place. All it does is hold the data of metacopy files and the regular files of a pseudo filesystem are kernel interfaces, not storage. So let's refuse data-only layers on superblocks with SB_I_PSEUDO at mount time.

Data-only layers can be added via the "::" separator in "lowerdir=" and via "datadir+" by path or by file descriptor. All of them end up at the end of ctx->lower. So a single check in ovl_get_lowerstack() covers all of them.

Note that regular lower layers on pseudo filesystems are left alone. Stacking overlayfs on top of sysfs keeps working.

---
 fs/overlayfs/super.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/overlayfs/super.c +0 -0
index 39d4d57dec230..719c2569dfeaf 100644
@@ -1237,6 +1237,14 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
        for (i = 0; i < ctx->nr; i++) {

fs/overlayfs/super.c static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, · line 1247

Quoted 10 lines
fs/overlayfs/super.c +8 -0
                l = &ctx->lower[i];
 
+               /* Pseudo filesystems don't hold data for metacopy files. */
+               if (i >= ctx->nr - ctx->nr_data &&
+                   (l->path.dentry->d_sb->s_iflags & SB_I_PSEUDO)) {
+                       pr_err("filesystem on %s not supported as data-only layer\n",
+                              l->name);
+                       return ERR_PTR(-EINVAL);
+               }
+

How about we make this just a tad more restrictive:

                /* Pseudo filesystems don't belong in composefs setup */
                if (ctx->nr_data &&
                    (l->path.dentry->d_sb->s_iflags & SB_I_PSEUDO)) {
                        pr_err("filesystem on %s not supported along
with data-only layers\n",
                               l->name);
                        return ERR_PTR(-EINVAL);
                }

I could send this as followup patch, but since this version is simpler there is no real reason to have the intermediate "only ban datadir" step.

Only the commit message needs a little more flexing to justify this.

Thanks,
Amir.

author maintainer
#81 lore raw

Re: [PATCH RFC v3 33/44] ovl: refuse data-only layers on pseudo filesystems

Quoted 57 lines · Amir Goldstein
Quoted 34 lines · Christian Brauner

The data of a metacopy file can live in a data-only layer. overlayfs doesn't look that data up when it looks up the file. It only remembers the absolute redirect and looks up the data lazily the first time someone needs it. So until then nothing can tell which filesystem holds the data of such a file.

But a data-only layer has no business being a pseudo filesystem in the first place. All it does is hold the data of metacopy files and the regular files of a pseudo filesystem are kernel interfaces, not storage. So let's refuse data-only layers on superblocks with SB_I_PSEUDO at mount time.

Data-only layers can be added via the "::" separator in "lowerdir=" and via "datadir+" by path or by file descriptor. All of them end up at the end of ctx->lower. So a single check in ovl_get_lowerstack() covers all of them.

Note that regular lower layers on pseudo filesystems are left alone. Stacking overlayfs on top of sysfs keeps working.

---
 fs/overlayfs/super.c | 8 ++++++++
 1 file changed, 8 insertions(+)
fs/overlayfs/super.c +0 -0
index 39d4d57dec230..719c2569dfeaf 100644
@@ -1237,6 +1237,14 @@ static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb,
        for (i = 0; i < ctx->nr; i++) {

fs/overlayfs/super.c static struct ovl_entry *ovl_get_lowerstack(struct super_block *sb, · line 1247

Quoted 10 lines
fs/overlayfs/super.c +8 -0
                l = &ctx->lower[i];
 
+               /* Pseudo filesystems don't hold data for metacopy files. */
+               if (i >= ctx->nr - ctx->nr_data &&
+                   (l->path.dentry->d_sb->s_iflags & SB_I_PSEUDO)) {
+                       pr_err("filesystem on %s not supported as data-only layer\n",
+                              l->name);
+                       return ERR_PTR(-EINVAL);
+               }
+

How about we make this just a tad more restrictive:

                /* Pseudo filesystems don't belong in composefs setup */
                if (ctx->nr_data &&
                    (l->path.dentry->d_sb->s_iflags & SB_I_PSEUDO)) {
                        pr_err("filesystem on %s not supported along
with data-only layers\n",
                               l->name);
                        return ERR_PTR(-EINVAL);
                }
Quoted 4 lines

I could send this as followup patch, but since this version is simpler there is no real reason to have the intermediate "only ban datadir" step.

Only the commit message needs a little more flexing to justify this.

Just sent me the diff on top of the series and I can fold it with the commit message you want and slap your Co-developed-by and SoB on it, please?

author maintainer
#82 lore raw

RFC PATCH v3 34/44 selftests/ovl: test data-only layers on pseudo filesystems

In reply to Christian Brauner

Add tests that overlayfs refuses data-only layers on pseudo filesystems:

- sysfs and procfs via the "::" separator in "lowerdir="
- sysfs and procfs via "datadir+" by path
- sysfs and procfs via "datadir+" by file descriptor
- tmpfs as data-only layer
- sysfs as regular lower layer

The last two must keep mounting.

---
 .../selftests/filesystems/overlayfs/.gitignore     |   1 +
 .../selftests/filesystems/overlayfs/Makefile       |   1 +
 .../filesystems/overlayfs/pseudo_datadir.c         | 131 +++++++++++++++++++++
 3 files changed, 133 insertions(+)
tools/testing/selftests/filesystems/overlayfs/.gitignore +1 -0
index b343cc430051d..e1410fee2269d 100644
@@ -3,3 +3,4 @@ dev_in_maps
 set_layers_via_fds
 idmapped_mounts
 automount_in_layer
+pseudo_datadir
tools/testing/selftests/filesystems/overlayfs/Makefile +1 -0
index 382a59bda5e70..ace75f5627e0f 100644
@@ -10,6 +10,7 @@ TEST_GEN_PROGS := dev_in_maps
 TEST_GEN_PROGS += set_layers_via_fds
 TEST_GEN_PROGS += idmapped_mounts
 TEST_GEN_PROGS += automount_in_layer
+TEST_GEN_PROGS += pseudo_datadir
 
 include ../../lib.mk
 
tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.53.0
#83 lore raw

Re: [PATCH RFC v3 34/44] selftests/ovl: test data-only layers on pseudo filesystems

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] selftests/ovl: missing prerequisite skips in setup_tmp() and tests - [Low] selftests/ovl: duplicated…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] selftests/ovl: missing prerequisite skips in setup_tmp() and tests
- [Low] selftests/ovl: duplicated setup_tmp() and datadir test cases --

commit 9dfbd53c60eeeb8dceed3a46417fda9ee76bb58b
Author: Christian Brauner <[email protected]>

selftests/ovl: test data-only layers on pseudo filesystems

This commit adds an overlayfs selftest verifying that data-only layers on pseudo filesystems (sysfs and procfs) are rejected while tmpfs data-only layers and sysfs lower layers remain allowed.

Quoted 6 lines
tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c new file +0 -0
new file mode 100644
index 0000000000000..3b59fd3e9f5c2
@@ -0,0 +1,131 @@

[ ... ]

tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c line 28

Quoted 13 lines
tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c new file +13 -0
+static int setup_tmp(void)
+{
+	if (unshare(CLONE_NEWNS))
+		return -errno;
+	if (sys_mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL))
+		return -errno;
+	if (sys_mount("tmpfs", "/tmp", "tmpfs", 0, NULL))
+		return -errno;
+	if (mkdir("/tmp/lower", 0755) || mkdir("/tmp/data", 0755) ||
+	    mkdir("/tmp/merged", 0755))
+		return -errno;
+	return 0;
+}

[Severity: Low]
Should these tests invoke SKIP() with a reason string when root privileges or kernel overlayfs support are unavailable?

Running this test without root privileges causes setup_tmp() to fail with -EPERM on unshare(CLONE_NEWNS), and running on a kernel without CONFIG_OVERLAY_FS causes mount_lowerdir() and fsmount_layers() to return -ENODEV, failing all four tests in make run_tests instead of skipping them.

[ ... ]

Quoted 20 lines
tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c new file +20 -0
+TEST(datadir_sysfs)
+{
+	ASSERT_EQ(setup_tmp(), 0);
+
+	EXPECT_EQ(mount_lowerdir("/tmp/lower::/sys/kernel"), -EINVAL);
+	EXPECT_EQ(fsmount_layers("/tmp/lower", "/sys/kernel", false), -EINVAL);
+	EXPECT_EQ(fsmount_layers("/tmp/lower", "/sys/kernel", true), -EINVAL);
+}
+
+TEST(datadir_procfs)
+{
+	ASSERT_EQ(setup_tmp(), 0);
+
+	EXPECT_EQ(mount_lowerdir("/tmp/lower::/proc"), -EINVAL);
+	EXPECT_EQ(fsmount_layers("/tmp/lower", "/proc", false), -EINVAL);
+	EXPECT_EQ(fsmount_layers("/tmp/lower", "/proc", true), -EINVAL);
+}
+
+TEST(datadir_tmpfs)
+{

tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c line 123

Quoted 10 lines
tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c new file +10 -0
+	ASSERT_EQ(setup_tmp(), 0);
+
+	EXPECT_EQ(mount_lowerdir("/tmp/lower::/tmp/data"), 0);
+	EXPECT_EQ(fsmount_layers("/tmp/lower", "/tmp/data", false), 0);
+	EXPECT_EQ(fsmount_layers("/tmp/lower", "/tmp/data", true), 0);
+}
+
+TEST(lowerdir_sysfs)
+{
+	ASSERT_EQ(setup_tmp(), 0);

[Severity: Low]
This isn't a bug, but could setup_tmp() move into a FIXTURE_SETUP() block, and could the three datadir_* tests be parameterized with FIXTURE_VARIANT() over the path and expected return code to avoid duplicating the setup and mount sequence? Also, since set_layers_via_fds.c already tests lowerdir+ and datadir+ layer configuration, should these cases live there instead of in a new standalone binary?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=34
maintainer Reviewed-by on v3 34/44
#84 lore raw

Re: [PATCH RFC v3 34/44] selftests/ovl: test data-only layers on pseudo filesystems

In reply to Christian Brauner
Quoted 9 lines · Christian Brauner

Add tests that overlayfs refuses data-only layers on pseudo filesystems:

- sysfs and procfs via the "::" separator in "lowerdir="
- sysfs and procfs via "datadir+" by path
- sysfs and procfs via "datadir+" by file descriptor
- tmpfs as data-only layer
- sysfs as regular lower layer

Quoted 3 lines

The last two must keep mounting.

Quoted 168 lines
---
 .../selftests/filesystems/overlayfs/.gitignore     |   1 +
 .../selftests/filesystems/overlayfs/Makefile       |   1 +
 .../filesystems/overlayfs/pseudo_datadir.c         | 131 +++++++++++++++++++++
 3 files changed, 133 insertions(+)
tools/testing/selftests/filesystems/overlayfs/.gitignore +1 -0
index b343cc430051d..e1410fee2269d 100644
@@ -3,3 +3,4 @@ dev_in_maps
 set_layers_via_fds
 idmapped_mounts
 automount_in_layer
+pseudo_datadir
tools/testing/selftests/filesystems/overlayfs/Makefile +1 -0
index 382a59bda5e70..ace75f5627e0f 100644
@@ -10,6 +10,7 @@ TEST_GEN_PROGS := dev_in_maps
 TEST_GEN_PROGS += set_layers_via_fds
 TEST_GEN_PROGS += idmapped_mounts
 TEST_GEN_PROGS += automount_in_layer
+TEST_GEN_PROGS += pseudo_datadir
 
 include ../../lib.mk
 
tools/testing/selftests/filesystems/overlayfs/pseudo_datadir.c new file +131 -1
new file mode 100644
index 0000000000000..3b59fd3e9f5c2
@@ -0,0 +1,131 @@
+// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
+
+#include <errno.h>
+#include <fcntl.h>
+#include <sched.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "kselftest_harness.h"
+#include "../wrappers.h"
+
+static int setup_tmp(void)
+{
+       if (unshare(CLONE_NEWNS))
+               return -errno;
+       if (sys_mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL))
+               return -errno;
+       if (sys_mount("tmpfs", "/tmp", "tmpfs", 0, NULL))
+               return -errno;
+       if (mkdir("/tmp/lower", 0755) || mkdir("/tmp/data", 0755) ||
+           mkdir("/tmp/merged", 0755))
+               return -errno;
+       return 0;
+}
+
+/* Mount an overlayfs with the legacy "lowerdir=" option. */
+static int mount_lowerdir(const char *lowerdir)
+{
+       char opts[256];
+
+       snprintf(opts, sizeof(opts), "lowerdir=%s", lowerdir);
+       if (sys_mount("overlay", "/tmp/merged", "overlay", MS_RDONLY, opts))
+               return -errno;
+       if (umount2("/tmp/merged", 0))
+               return -errno;
+       return 0;
+}
+
+static int set_layer(int fd_context, const char *key, const char *path,
+                    bool by_fd)
+{
+       int fd, ret = 0;
+
+       if (!by_fd) {
+               if (sys_fsconfig(fd_context, FSCONFIG_SET_STRING, key, path, 0))
+                       return -errno;
+               return 0;
+       }
+
+       fd = open(path, O_DIRECTORY | O_CLOEXEC);
+       if (fd < 0)
+               return -errno;
+       if (sys_fsconfig(fd_context, FSCONFIG_SET_FD, key, NULL, fd))
+               ret = -errno;
+       close(fd);
+       return ret;
+}
+
+/* Create an overlayfs with "lowerdir+" and "datadir+" through fsconfig. */
+static int fsmount_layers(const char *lower, const char *data, bool by_fd)
+{
+       int fd_context, fd_mnt, ret;
+
+       fd_context = sys_fsopen("overlay", FSOPEN_CLOEXEC);
+       if (fd_context < 0)
+               return -errno;
+
+       ret = set_layer(fd_context, "lowerdir+", lower, by_fd);
+       if (ret)
+               goto out;
+       ret = set_layer(fd_context, "datadir+", data, by_fd);
+       if (ret)
+               goto out;
+
+       if (sys_fsconfig(fd_context, FSCONFIG_CMD_CREATE, NULL, NULL, 0)) {
+               ret = -errno;
+               goto out;
+       }
+
+       fd_mnt = sys_fsmount(fd_context, FSMOUNT_CLOEXEC, 0);
+       if (fd_mnt < 0)
+               ret = -errno;
+       else
+               close(fd_mnt);
+out:
+       close(fd_context);
+       return ret;
+}
+
+TEST(datadir_sysfs)
+{
+       ASSERT_EQ(setup_tmp(), 0);
+
+       EXPECT_EQ(mount_lowerdir("/tmp/lower::/sys/kernel"), -EINVAL);
+       EXPECT_EQ(fsmount_layers("/tmp/lower", "/sys/kernel", false), -EINVAL);
+       EXPECT_EQ(fsmount_layers("/tmp/lower", "/sys/kernel", true), -EINVAL);
+}
+
+TEST(datadir_procfs)
+{
+       ASSERT_EQ(setup_tmp(), 0);
+
+       EXPECT_EQ(mount_lowerdir("/tmp/lower::/proc"), -EINVAL);
+       EXPECT_EQ(fsmount_layers("/tmp/lower", "/proc", false), -EINVAL);
+       EXPECT_EQ(fsmount_layers("/tmp/lower", "/proc", true), -EINVAL);
+}
+
+TEST(datadir_tmpfs)
+{
+       ASSERT_EQ(setup_tmp(), 0);
+
+       EXPECT_EQ(mount_lowerdir("/tmp/lower::/tmp/data"), 0);
+       EXPECT_EQ(fsmount_layers("/tmp/lower", "/tmp/data", false), 0);
+       EXPECT_EQ(fsmount_layers("/tmp/lower", "/tmp/data", true), 0);
+}
+
+TEST(lowerdir_sysfs)
+{
+       ASSERT_EQ(setup_tmp(), 0);
+
+       EXPECT_EQ(mount_lowerdir("/sys/kernel:/tmp/lower"), 0);
+       EXPECT_EQ(mount_lowerdir("/sys/kernel::/tmp/data"), 0);
+       EXPECT_EQ(fsmount_layers("/sys/kernel", "/tmp/data", false), 0);
+       EXPECT_EQ(fsmount_layers("/sys/kernel", "/tmp/data", true), 0);
+}
+
+TEST_HARNESS_MAIN
 
--

2.53.0

author maintainer
#85 lore raw

RFC PATCH v3 35/44 fs: add file_check_backing()

In reply to Christian Brauner

Loop, zloop, the nvme target, the scsi target, fuse passthrough, the usb mass storage gadget, erofs and acct all take a file from userspace and use it as storage. Currently, each of them has its own idea of what to check before using a file like that:

- loop and the gadget check for a regular file or a block device, the nvme target, the scsi target and zloop take any file type
- loop checks the open mode, the gadget checks FMODE_CAN_READ, the nvme target, the scsi target and zloop only check for ->read_iter() and ->write_iter()
- apart from acct which refuses procfs and sysfs files none of them cares whether the file is a kernel interface

Add a helper that does all of it in one place. It only accepts regular files and, if the caller passes S_IFBLK, block devices. It refuses files on pseudo filesystems. And it checks that the file is open for what the caller is going to do with it and implements ->read_iter() for reading and ->write_iter() for writing.

O_PATH files are refused unless the caller passes FMODE_PATH. That is for callers that only need the path of the file. fuse passthrough is one of them and has accepted O_PATH file descriptors since commit efad7153bf93 ("fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN").

Block devices are fine even though bdevfs is a pseudo filesystem. A block device that userspace hands in is a device node on devtmpfs or some other filesystem. Files on bdevfs only come from bdev_file_open_by_*() and never end up here.

The pseudo filesystem check looks at the inode that actually provides the data via d_real_data_inode(). overlayfs accepts sysfs, cgroup2, debugfs, tracefs, configfs and securityfs as lower layers and reads of such an overlayfs file are served by the file on the pseudo filesystem. Checking the overlayfs inode would miss that.

For an O_PATH file nothing might have looked up the data yet. overlayfs only looks up the data of a metacopy file in a data-only layer when the file is opened. d_real_data_inode() does the lookup then and if that fails we return the error.

Note that the file type is taken from the inode of the file and not from the host of ->f_mapping like loop and the gadget do it. A driver can point ->f_mapping somewhere else in ->open(). It makes no difference for block devices as both inodes are block devices.

No functional changes. Nothing calls the helper yet.

---
 fs/read_write.c    | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |  2 ++
 2 files changed, 55 insertions(+)
fs/read_write.c +53 -0
index 6767283108991..9f1e7bfcbd4f1 100644
@@ -866,6 +866,59 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter,
 	return ret;
 }
 
+/**
+ * file_check_backing - check that the kernel can use a file as storage
+ * @file: file that userspace handed in
+ * @mode: FMODE_READ and/or FMODE_WRITE the kernel will do I/O with, or
+ *        FMODE_PATH if only the path of @file is used
+ * @type: S_IFBLK if a block device is fine as well, 0 otherwise
+ *
+ * Call this where a file from userspace is taken as a backing file. Only
+ * regular files and, if @type is S_IFBLK, block devices are storage. Files
+ * on pseudo filesystems are kernel interfaces and are refused. The file
+ * must be open for @mode and implement ->read_iter() for reading and
+ * ->write_iter() for writing. O_PATH files are only fine with FMODE_PATH.
+ *
+ * Return: 0 on success, -EBADF if @file isn't open for @mode, -EINVAL if it
+ * can't be used as storage, or the error from looking up the data of @file
+ * on a stacking filesystem.
+ */
+int file_check_backing(const struct file *file, fmode_t mode, umode_t type)
+{
+	fmode_t io = mode & (FMODE_READ | FMODE_WRITE);
+	/* Drivers may point ->f_mapping at something else. */
+	umode_t fmt = file_inode(file)->i_mode & S_IFMT;
+	struct inode *real_inode;
+
+	/* O_PATH files are only fine for callers that just use the path. */
+	if ((file->f_mode & FMODE_PATH) && !(mode & FMODE_PATH))
+		return -EBADF;
+
+	if ((file->f_mode & io) != io)
+		return -EBADF;
+
+	if (fmt != S_IFREG && !(type == S_IFBLK && fmt == S_IFBLK))
+		return -EINVAL;
+
+	/* Look through stacking filesystems at the inode with the data. */
+	real_inode = d_real_data_inode(file->f_path.dentry);
+	if (IS_ERR(real_inode))
+		return PTR_ERR(real_inode);
+	if (real_inode->i_sb->s_iflags & SB_I_PSEUDO)
+		return -EINVAL;
+
+	if ((mode & FMODE_READ) &&
+	    (!(file->f_mode & FMODE_CAN_READ) || !file->f_op->read_iter))
+		return -EINVAL;
+
+	if ((mode & FMODE_WRITE) &&
+	    (!(file->f_mode & FMODE_CAN_WRITE) || !file->f_op->write_iter))
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(file_check_backing);
+
 ssize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb,
 			   struct iov_iter *iter)
 {
include/linux/fs.h +2 -0
index 99caef43ff3c4..b1c7ebafbadbe 100644
@@ -2553,6 +2553,8 @@ static inline const struct inode *file_user_inode(const struct file *f)
 	return file_inode(f);
 }
 
+int file_check_backing(const struct file *file, fmode_t mode, umode_t type);
+
 static inline struct file *file_clone_open(struct file *file)
 {
 	return dentry_open(&file->f_path, file->f_flags, file->f_cred);
Signature · 1 line
2.53.0
#86 lore raw

Re: [PATCH RFC v3 35/44] fs: add file_check_backing()

Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

Loop, zloop, the nvme target, the scsi target, fuse passthrough, the usb mass storage gadget, erofs and acct all take a file from userspace and use it as storage. Currently, each of them has its own idea of what to check before using a file like that:

- loop and the gadget check for a regular file or a block device, the nvme target, the scsi target and zloop take any file type
- loop checks the open mode, the gadget checks FMODE_CAN_READ, the nvme target, the scsi target and zloop only check for ->read_iter() and ->write_iter()
- apart from acct which refuses procfs and sysfs files none of them cares whether the file is a kernel interface

Quoted 8 lines

Add a helper that does all of it in one place. It only accepts regular files and, if the caller passes S_IFBLK, block devices. It refuses files [ ... ]
block devices as both inodes are block devices.

No functional changes. Nothing calls the helper yet.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=35
reviewer Reviewed-by on v3 35/44
#87 lore raw

Re: [PATCH RFC v3 35/44] fs: add file_check_backing()

In reply to Christian Brauner
Quoted 40 lines · Christian Brauner

Loop, zloop, the nvme target, the scsi target, fuse passthrough, the usb mass storage gadget, erofs and acct all take a file from userspace and use it as storage. Currently, each of them has its own idea of what to check before using a file like that:

- loop and the gadget check for a regular file or a block device, the nvme target, the scsi target and zloop take any file type
- loop checks the open mode, the gadget checks FMODE_CAN_READ, the nvme target, the scsi target and zloop only check for ->read_iter() and ->write_iter()
- apart from acct which refuses procfs and sysfs files none of them cares whether the file is a kernel interface

Add a helper that does all of it in one place. It only accepts regular files and, if the caller passes S_IFBLK, block devices. It refuses files on pseudo filesystems. And it checks that the file is open for what the caller is going to do with it and implements ->read_iter() for reading and ->write_iter() for writing.

O_PATH files are refused unless the caller passes FMODE_PATH. That is for callers that only need the path of the file. fuse passthrough is one of them and has accepted O_PATH file descriptors since commit efad7153bf93 ("fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN").

Block devices are fine even though bdevfs is a pseudo filesystem. A block device that userspace hands in is a device node on devtmpfs or some other filesystem. Files on bdevfs only come from bdev_file_open_by_*() and never end up here.

The pseudo filesystem check looks at the inode that actually provides the data via d_real_data_inode(). overlayfs accepts sysfs, cgroup2, debugfs, tracefs, configfs and securityfs as lower layers and reads of such an overlayfs file are served by the file on the pseudo filesystem. Checking the overlayfs inode would miss that.

For an O_PATH file nothing might have looked up the data yet. overlayfs only looks up the data of a metacopy file in a data-only layer when the file is opened. d_real_data_inode() does the lookup then and if that fails we return the error.

Quoted 8 lines

Note that the file type is taken from the inode of the file and not from the host of ->f_mapping like loop and the gadget do it. A driver can point ->f_mapping somewhere else in ->open(). It makes no difference for block devices as both inodes are block devices.

No functional changes. Nothing calls the helper yet.

Looks good to me. Feel free to add:

Honza

Quoted 86 lines
---
 fs/read_write.c    | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |  2 ++
 2 files changed, 55 insertions(+)
fs/read_write.c +53 -0
index 6767283108991..9f1e7bfcbd4f1 100644
@@ -866,6 +866,59 @@ static ssize_t do_loop_readv_writev(struct file *filp, struct iov_iter *iter,
 	return ret;
 }
 
+/**
+ * file_check_backing - check that the kernel can use a file as storage
+ * @file: file that userspace handed in
+ * @mode: FMODE_READ and/or FMODE_WRITE the kernel will do I/O with, or
+ *        FMODE_PATH if only the path of @file is used
+ * @type: S_IFBLK if a block device is fine as well, 0 otherwise
+ *
+ * Call this where a file from userspace is taken as a backing file. Only
+ * regular files and, if @type is S_IFBLK, block devices are storage. Files
+ * on pseudo filesystems are kernel interfaces and are refused. The file
+ * must be open for @mode and implement ->read_iter() for reading and
+ * ->write_iter() for writing. O_PATH files are only fine with FMODE_PATH.
+ *
+ * Return: 0 on success, -EBADF if @file isn't open for @mode, -EINVAL if it
+ * can't be used as storage, or the error from looking up the data of @file
+ * on a stacking filesystem.
+ */
+int file_check_backing(const struct file *file, fmode_t mode, umode_t type)
+{
+	fmode_t io = mode & (FMODE_READ | FMODE_WRITE);
+	/* Drivers may point ->f_mapping at something else. */
+	umode_t fmt = file_inode(file)->i_mode & S_IFMT;
+	struct inode *real_inode;
+
+	/* O_PATH files are only fine for callers that just use the path. */
+	if ((file->f_mode & FMODE_PATH) && !(mode & FMODE_PATH))
+		return -EBADF;
+
+	if ((file->f_mode & io) != io)
+		return -EBADF;
+
+	if (fmt != S_IFREG && !(type == S_IFBLK && fmt == S_IFBLK))
+		return -EINVAL;
+
+	/* Look through stacking filesystems at the inode with the data. */
+	real_inode = d_real_data_inode(file->f_path.dentry);
+	if (IS_ERR(real_inode))
+		return PTR_ERR(real_inode);
+	if (real_inode->i_sb->s_iflags & SB_I_PSEUDO)
+		return -EINVAL;
+
+	if ((mode & FMODE_READ) &&
+	    (!(file->f_mode & FMODE_CAN_READ) || !file->f_op->read_iter))
+		return -EINVAL;
+
+	if ((mode & FMODE_WRITE) &&
+	    (!(file->f_mode & FMODE_CAN_WRITE) || !file->f_op->write_iter))
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(file_check_backing);
+
 ssize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb,
 			   struct iov_iter *iter)
 {
include/linux/fs.h +2 -0
index 99caef43ff3c4..b1c7ebafbadbe 100644
@@ -2553,6 +2553,8 @@ static inline const struct inode *file_user_inode(const struct file *f)
 	return file_inode(f);
 }
 
+int file_check_backing(const struct file *file, fmode_t mode, umode_t type);
+
 static inline struct file *file_clone_open(struct file *file)
 {
 	return dentry_open(&file->f_path, file->f_flags, file->f_cred);
Signature · 2 lines
-- 
2.53.0
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
Reviewed-by on v3 35/44
#88 lore raw

Re: [PATCH RFC v3 35/44] fs: add file_check_backing()

In reply to Christian Brauner
Quoted 52 lines · Christian Brauner

Loop, zloop, the nvme target, the scsi target, fuse passthrough, the usb
mass storage gadget, erofs and acct all take a file from userspace and
use it as storage. Currently, each of them has its own idea of what to
check before using a file like that:

- loop and the gadget check for a regular file or a block device, the nvme target, the scsi target and zloop take any file type
- loop checks the open mode, the gadget checks FMODE_CAN_READ, the nvme
  target, the scsi target and zloop only check for ->read_iter() and ->write_iter()
- apart from acct which refuses procfs and sysfs files none of them cares whether the file is a kernel interface

Add a helper that does all of it in one place. It only accepts regular
files and, if the caller passes S_IFBLK, block devices. It refuses files
on pseudo filesystems. And it checks that the file is open for what the
caller is going to do with it and implements ->read_iter() for reading
and ->write_iter() for writing.

O_PATH files are refused unless the caller passes FMODE_PATH. That is for callers that only need the path of the file. fuse passthrough is one of them and has accepted O_PATH file descriptors since commit efad7153bf93 ("fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN").

Block devices are fine even though bdevfs is a pseudo filesystem. A block device that userspace hands in is a device node on devtmpfs or some other filesystem. Files on bdevfs only come from bdev_file_open_by_*() and never end up here.

The pseudo filesystem check looks at the inode that actually provides the data via d_real_data_inode(). overlayfs accepts sysfs, cgroup2, debugfs, tracefs, configfs and securityfs as lower layers and reads of
such an overlayfs file are served by the file on the pseudo filesystem.
Checking the overlayfs inode would miss that.

For an O_PATH file nothing might have looked up the data yet. overlayfs
only looks up the data of a metacopy file in a data-only layer when the
file is opened. d_real_data_inode() does the lookup then and if that fails we return the error.

Quoted 9 lines

Note that the file type is taken from the inode of the file and not from
the host of ->f_mapping like loop and the gadget do it. A driver can point ->f_mapping somewhere else in ->open(). It makes no difference for
block devices as both inodes are block devices.

No functional changes. Nothing calls the helper yet.

Quoted 102 lines

---
 fs/read_write.c    | 53
+++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/fs.h |  2 ++

 2 files changed, 55 insertions(+)
fs/read_write.c +0 -0
index 6767283108991..9f1e7bfcbd4f1 100644
@@ -866,6 +866,59 @@ static ssize_t do_loop_readv_writev(struct file
 *filp, struct iov_iter *iter,
  	return ret;
  }


+/**
+ * file_check_backing - check that the kernel can use a file as storage
+ * @file: file that userspace handed in
+ * @mode: FMODE_READ and/or FMODE_WRITE the kernel will do I/O with, or
+ *        FMODE_PATH if only the path of @file is used
+ * @type: S_IFBLK if a block device is fine as well, 0 otherwise
+ *
+ * Call this where a file from userspace is taken as a backing file. Only
+ * regular files and, if @type is S_IFBLK, block devices are storage. Files
+ * on pseudo filesystems are kernel interfaces and are refused. The file
+ * must be open for @mode and implement ->read_iter() for reading and
+ * ->write_iter() for writing. O_PATH files are only fine with FMODE_PATH.
+ *
+ * Return: 0 on success, -EBADF if @file isn't open for @mode, - EINVAL if it
+ * can't be used as storage, or the error from looking up the data of @file
+ * on a stacking filesystem.
+ */
+int file_check_backing(const struct file *file, fmode_t mode, umode_t type)

fs/read_write.c +7 -0
+{
+	fmode_t io = mode & (FMODE_READ | FMODE_WRITE);
+	/* Drivers may point ->f_mapping at something else. */
+	umode_t fmt = file_inode(file)->i_mode & S_IFMT;
+	struct inode *real_inode;
+
+	/* O_PATH files are only fine for callers that just use the

path. */

fs/read_write.c +10 -0
+	if ((file->f_mode & FMODE_PATH) && !(mode & FMODE_PATH))
+		return -EBADF;
+
+	if ((file->f_mode & io) != io)
+		return -EBADF;
+
+	if (fmt != S_IFREG && !(type == S_IFBLK && fmt == S_IFBLK))
+		return -EINVAL;
+
+	/* Look through stacking filesystems at the inode with the

data. */

fs/read_write.c +8 -0
+	real_inode = d_real_data_inode(file->f_path.dentry);
+	if (IS_ERR(real_inode))
+		return PTR_ERR(real_inode);
+	if (real_inode->i_sb->s_iflags & SB_I_PSEUDO)
+		return -EINVAL;
+
+	if ((mode & FMODE_READ) &&
+	    (!(file->f_mode & FMODE_CAN_READ) || !file->f_op-
Quoted 1 line

read_iter))

fs/read_write.c +4 -0
+		return -EINVAL;
+
+	if ((mode & FMODE_WRITE) &&
+	    (!(file->f_mode & FMODE_CAN_WRITE) || !file->f_op-
Quoted 1 line

write_iter))

fs/read_write.c +6 -0
+		return -EINVAL;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(file_check_backing);
+

 ssize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb, struct iov_iter *iter)
 {

include/linux/fs.h +0 -0
index 99caef43ff3c4..b1c7ebafbadbe 100644
@@ -2553,6 +2553,8 @@ static inline const struct inode
 *file_user_inode(const struct file *f)
  	return file_inode(f);
  }


+int file_check_backing(const struct file *file, fmode_t mode, umode_t type);
+
 static inline struct file *file_clone_open(struct file *file) {
  return dentry_open(&file->f_path, file->f_flags, file-

Quoted 1 line

f_cred);

author maintainer
#89 lore raw

RFC PATCH v3 36/44 loop: refuse files on pseudo filesystems as backing files

In reply to Christian Brauner

Currently loop accepts any regular file that implements ->read_iter() as a backing file and any that also implements ->write_iter() as a writable one. That includes files on procfs, sysfs and other pseudo filesystems. For example, /proc/kcore attaches read-only as a loop device the size of the kernel's virtual address space, 64 PiB with 5-level paging. sysfs attributes attach read-write as 4096 byte loop devices. Writing a block to the loop device of /sys/kernel/mm/transparent_hugepage/enabled changes the THP setting.

That's not just nonsensical, it can be abused. Loop calls ->read_iter() and ->write_iter() of the backing file directly from its worker which runs with kernel credentials. But pseudo files enforce part of their access rules at read and write time against current. Dozens of sysfs ->show() and ->store() methods call capable(). Behind a loop device all of these checks are done against the loop worker instead of the task that opened the file. And setting up a loop device requires no capabilities, only access to the device nodes. So on v7.4-rc1:

- uid 0 without any capabilities can't write to /sys/kernel/reboot/mode as mode_store() requires CAP_SYS_BOOT. Writing "warm" through a loop device works.

- uid 0 without any capabilities can't read the files in /sys/firmware/dmi/entries/*/ as dmi_sysfs_attr_show() requires CAP_SYS_ADMIN. Reading them through a loop device works.

- An unprivileged container that was handed a loop device can't change gro_flush_timeout of its own network devices as gro_flush_timeout_store() requires CAP_NET_ADMIN in the initial user namespace. Writing it through a loop device works.

The same goes for hard_offline_page, the md and sd attributes, rfkill and others.

Refuse files on pseudo filesystems as loop backing files by switching to file_check_backing(). Note that it looks through overlayfs so stacking overlayfs on top of sysfs doesn't get around this.

The helper also does the file type, open mode and method checks that loop did itself so far. The check for a regular file or a block device now happens before the loop device is locked and it looks at the inode of the file instead of the host of ->f_mapping. For regular files and block devices both have the same type.

---
 drivers/block/loop.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
drivers/block/loop.c +4 -13
index c96e35c3ef423..776bd063f900c 100644
@@ -492,7 +492,6 @@ static inline int is_loop_device(struct file *file)
 
 static int loop_validate_file(struct file *file, struct block_device *bdev)
 {
-	struct inode	*inode = file->f_mapping->host;
 	struct file	*f = file;
 
 	/* Avoid recursion */
@@ -510,8 +509,6 @@ static int loop_validate_file(struct file *file, struct block_device *bdev)
 		rmb();
 		f = l->lo_backing_file;
 	}
-	if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))
-		return -EINVAL;
 	return 0;
 }
 
@@ -528,16 +525,10 @@ static void loop_assign_backing_file(struct loop_device *lo, struct file *file)
 
 static int loop_check_backing_file(struct file *file)
 {
-	if (!(file->f_mode & FMODE_READ))
-		return -EBADF;
-
-	if (!file->f_op->read_iter)
-		return -EINVAL;
-
-	if ((file->f_mode & FMODE_WRITE) && !file->f_op->write_iter)
-		return -EINVAL;
-
-	return 0;
+	/* A backing file that isn't open for writing gives a read-only device. */
+	return file_check_backing(file,
+				  FMODE_READ | (file->f_mode & FMODE_WRITE),
+				  S_IFBLK);
 }
 
 /* loop sysfs attributes */
Signature · 1 line
2.53.0
#90 lore raw

Re: [PATCH RFC v3 36/44] loop: refuse files on pseudo filesystems as backing files

Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

Currently loop accepts any regular file that implements ->read_iter() as a backing file and any that also implements ->write_iter() as a writable one. That includes files on procfs, sysfs and other pseudo filesystems. For example, /proc/kcore attaches read-only as a loop device the size of the kernel's virtual address space, 64 PiB with 5-level paging. sysfs attributes attach read-write as 4096 byte loop devices. Writing a block to the loop device of /sys/kernel/mm/transparent_hugepage/enabled changes the THP setting.

That's not just nonsensical, it can be abused. Loop calls ->read_iter() and ->write_iter() of the backing file directly from its worker which runs with kernel credentials. But pseudo files enforce part of their access rules at read and write time against current. Dozens of sysfs ->show() and ->store() methods call capable(). Behind a loop device all of these checks are done against the loop worker instead of the task

Quoted 6 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=36
author maintainer
#91 lore raw

RFC PATCH v3 37/44 zloop: refuse zone files on pseudo filesystems

In reply to Christian Brauner

zloop opens its zone files by name below the base directory but a bind mount can put any file there, including a procfs or sysfs file. Refuse files on pseudo filesystems as zone files just like loop does by switching to file_check_backing().

Note that the helper only accepts regular files. So far zloop took anything with ->read_iter() and ->write_iter() as a zone file. That includes character devices, FIFOs and block devices if someone put them where zloop expects a zone file. Zone files are created by zloop itself and zloop truncates them to size and to reset and finish zones which only works for regular files. So refuse everything else.

---
 drivers/block/zloop.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/block/zloop.c +2 -3
index 65634a39b0bfc..6f79b9ddbbe00 100644
@@ -1132,10 +1132,9 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts,
 		return PTR_ERR(zone->file);
 	}
 
-	if (!zone->file->f_op->read_iter || !zone->file->f_op->write_iter) {
-		ret = -EINVAL;
+	ret = file_check_backing(zone->file, FMODE_READ | FMODE_WRITE, 0);
+	if (ret)
 		goto out_fput;
-	}
 
 	if (zlo->block_size) {
 		ret = zloop_get_block_size(zlo, zone);
Signature · 1 line
2.53.0
#92 lore raw

Re: [PATCH RFC v3 37/44] zloop: refuse zone files on pseudo filesystems

Sashiko has reviewed this patch and found no issues.
Quoted 12 lines

zloop opens its zone files by name below the base directory but a bind mount can put any file there, including a procfs or sysfs file. Refuse files on pseudo filesystems as zone files just like loop does by switching to file_check_backing().

Note that the helper only accepts regular files. So far zloop took anything with ->read_iter() and ->write_iter() as a zone file. That includes character devices, FIFOs and block devices if someone put them where zloop expects a zone file. Zone files are created by zloop itself and zloop truncates them to size and to reset and finish zones which only works for regular files. So refuse everything else.

Quoted 4 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=37
author maintainer
#93 lore raw

RFC PATCH v3 38/44 nvmet: refuse files on pseudo filesystems as namespace backing files

In reply to Christian Brauner

The file backend takes any file that can be opened for reading and writing. With buffered_io=1 that includes files on procfs or sysfs which then get read and written by a kernel worker on behalf of the host. Refuse files on pseudo filesystems just like loop does by switching to file_check_backing().

Note that the helper only accepts regular files and block devices. A block device ends up in the file backend when buffered_io is set. But so far the file backend also took anything else with ->read_iter() and ->write_iter() such as character devices and FIFOs. The size of the namespace is the size of the inode which is zero for all of them. So such a namespace was unusable anyway. Refuse them.

---
 drivers/nvme/target/io-cmd-file.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/nvme/target/io-cmd-file.c +2 -3
index dfa8aa46188c8..2249ad3bb46d8 100644
@@ -47,10 +47,9 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
 		return ret;
 	}
 
-	if (!ns->file->f_op->read_iter || !ns->file->f_op->write_iter) {
-		ret = -EINVAL;
+	ret = file_check_backing(ns->file, FMODE_READ | FMODE_WRITE, S_IFBLK);
+	if (ret)
 		goto err;
-	}
 
 	nvmet_file_ns_revalidate(ns);
 
Signature · 1 line
2.53.0
#94 lore raw

Re: [PATCH RFC v3 38/44] nvmet: refuse files on pseudo filesystems as namespace backing files

Sashiko has reviewed this patch and found no issues.
Quoted 13 lines

The file backend takes any file that can be opened for reading and writing. With buffered_io=1 that includes files on procfs or sysfs which then get read and written by a kernel worker on behalf of the host. Refuse files on pseudo filesystems just like loop does by switching to file_check_backing().

Note that the helper only accepts regular files and block devices. A block device ends up in the file backend when buffered_io is set. But so far the file backend also took anything else with ->read_iter() and ->write_iter() such as character devices and FIFOs. The size of the namespace is the size of the inode which is zero for all of them. So such a namespace was unusable anyway. Refuse them.

Quoted 3 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=38
#95 lore raw

Re: [PATCH RFC v3 38/44] nvmet: refuse files on pseudo filesystems as namespace backing files

In reply to Christian Brauner
TL;DR: The series may not build: file_check_backing() in fs/read_write.c calls d_real_data_inode(), which seems undefined anywhere in the tree, so a prerequisite patch may be missing.
Quoted 1 line

nvmet: refuse files on pseudo filesystems as namespace backing files

TL;DR: The series may not build: file_check_backing() in fs/read_write.c calls d_real_data_inode(), which seems undefined anywhere in the tree, so a prerequisite patch may be missing.

drivers/nvme/target/io-cmd-file.c int nvmet_file_ns_enable(struct nvmet_ns *ns) · line 53

Quoted 13 lines
drivers/nvme/target/io-cmd-file.c +2 -3
@@ -47,10 +47,9 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
 		return ret;
 	}
 
-	if (!ns->file->f_op->read_iter || !ns->file->f_op->write_iter) {
-		ret = -EINVAL;
+	ret = file_check_backing(ns->file, FMODE_READ | FMODE_WRITE, S_IFBLK);
+	if (ret)
 		goto err;
-	}

Can this be built? nvmet_file_ns_enable() now depends on file_check_backing() from f66083ed0be9, which does:

fs/read_write.c:file_check_backing() {
    ...
	/* Look through stacking filesystems at the inode with the data. */
	real_inode = d_real_data_inode(file->f_path.dentry);
	if (IS_ERR(real_inode))
    ...
}

d_real_data_inode() is not defined or declared anywhere in the tree, and no commit up to the end of the series adds it. Only d_real_inode() exists in include/linux/dcache.h, so fs/read_write.c looks like it fails with an implicit function declaration.

If d_real_inode() was intended, it does d_inode(d_real(...)) without any ERR_PTR handling, so the IS_ERR() check would never trigger the error path the f66083ed0be9 commit message describes.

Is a prerequisite patch adding d_real_data_inode() missing from the series?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/43858134663

author maintainer
#96 lore raw

Re: [PATCH RFC v3 38/44] nvmet: refuse files on pseudo filesystems as namespace backing files

Quoted 1 line · On Mon, Nov 16, 2026 at 12:00:14PM +0000, [email protected] wrote:

Is a prerequisite patch adding d_real_data_inode() missing from the series?

No. d_real_data_inode() comes from "fs: let d_real() fail" which is in the base-commit of this series (vfs-7.5.lookup). This was applied to bpf-next instead.

author maintainer
#97 lore raw

RFC PATCH v3 39/44 target: fileio: refuse files on pseudo filesystems as backing files

In reply to Christian Brauner

fd_dev_name can name any file including files on procfs or sysfs. The initiator then gets to read and write kernel interfaces through the LUN with kernel credentials. Refuse files on pseudo filesystems just like loop does by switching to file_check_backing().

Do the same for the protection file. With DIF protection enabled the fileio backend keeps the protection information in a second file. It is named like the backing file with ".protection" appended and fd_init_prot() opens it by path. Whatever that path leads to was taken without any checks.

Note that the helper only accepts regular files and block devices as backing file and only regular files as protection file. So far the backing file could be anything with ->read_iter() and ->write_iter() including character devices and FIFOs.

---
 drivers/target/target_core_file.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/target/target_core_file.c +8 -2
index a5391e57e9aa5..c747cc4a647ff 100644
@@ -145,8 +145,8 @@ static int fd_configure_device(struct se_device *dev)
 	}
 	fd_dev->fd_file = file;
 
-	if (!file->f_op->read_iter || !file->f_op->write_iter) {
-		pr_err("FILEIO: %s lacks ->read_iter or ->write_iter\n",
+	if (file_check_backing(file, FMODE_READ | FMODE_WRITE, S_IFBLK)) {
+		pr_err("FILEIO: %s can't be used as a backing file\n",
 		       fd_dev->fd_dev_name);
 		ret = -EINVAL;
 		goto fail;
@@ -861,6 +861,12 @@ static int fd_init_prot(struct se_device *dev)
 		ret = PTR_ERR(prot_file);
 		return ret;
 	}
+
+	if (file_check_backing(prot_file, FMODE_READ | FMODE_WRITE, 0)) {
+		pr_err("FILEIO: %s can't be used as a protection file\n", buf);
+		filp_close(prot_file, NULL);
+		return -EINVAL;
+	}
 	fd_dev->fd_prot_file = prot_file;
 
 	return 0;
Signature · 1 line
2.53.0
#98 lore raw

Re: [PATCH RFC v3 39/44] target: fileio: refuse files on pseudo filesystems as backing files

Sashiko has reviewed this patch and found no issues.
Quoted 16 lines

fd_dev_name can name any file including files on procfs or sysfs. The initiator then gets to read and write kernel interfaces through the LUN with kernel credentials. Refuse files on pseudo filesystems just like loop does by switching to file_check_backing().

Do the same for the protection file. With DIF protection enabled the fileio backend keeps the protection information in a second file. It is named like the backing file with ".protection" appended and fd_init_prot() opens it by path. Whatever that path leads to was taken without any checks.

Note that the helper only accepts regular files and block devices as backing file and only regular files as protection file. So far the backing file could be anything with ->read_iter() and ->write_iter() including character devices and FIFOs.

Quoted 5 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=39
author maintainer
#99 lore raw

RFC PATCH v3 40/44 fuse: refuse files on pseudo filesystems as passthrough backing files

In reply to Christian Brauner

The fuse server can register any regular file as a backing file. procfs and binfmt_misc files are already refused by the stacking depth check as both set s_stack_depth to FILESYSTEM_MAX_STACK_DEPTH. sysfs and the other pseudo filesystems aren't. Reads and writes of the fuse file would then be done on the pseudo file with the fuse server's credentials. Refuse files on pseudo filesystems just like loop does.

Note that the backing file is only registered here and opened again for every fuse file that uses it. Only its path is used and O_PATH file descriptors are allowed since commit efad7153bf93 ("fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN"). So pass FMODE_PATH to file_check_backing() to keep them working.

The file that reads and writes are actually done on is opened in fuse_passthrough_open() with the flags of the fuse file. So check that file as well and pass the mode the fuse file was opened with. It has the same path as the registered file so files on pseudo filesystems are already refused. But this also makes sure that the backing file implements ->read_iter() if the fuse file is opened for reading and ->write_iter() if it is opened for writing. Like the other failures to set up passthrough this fails the open with EIO.

---
 fs/fuse/backing.c     | 4 ++++
 fs/fuse/passthrough.c | 7 +++++++
 2 files changed, 11 insertions(+)
fs/fuse/backing.c +4 -0
index 8c21a8a74efb9..7527f3ecb90dc 100644
@@ -147,6 +147,10 @@ static int fuse_backing_open_file(struct fuse_conn *fc, struct fuse_backing *fb,
 		if (inode->i_sb->s_stack_depth >= fc->max_stack_depth)
 			return -ELOOP;
 
+		err = file_check_backing(file, FMODE_PATH, 0);
+		if (err)
+			return err;
+
 		fb->type = FUSE_BACKING_PATH;
 		fb->path = file->f_path;
 		path_get(&fb->path);
fs/fuse/passthrough.c +7 -0
index 0ed964c479d96..fc8979ac96a21 100644
@@ -183,6 +183,7 @@ int fuse_passthrough_open(struct file *file, struct fuse_backing *fb)
 {
 	struct fuse_file *ff = file->private_data;
 	struct file *backing_file;
+	int err;
 
 	if (fb->type == FUSE_BACKING_EXTMAP) {
 		if (fuse_backing_is_dax(fb) != !!IS_DAX(file_inode(file)))
@@ -201,6 +202,12 @@ int fuse_passthrough_open(struct file *file, struct fuse_backing *fb)
 	if (IS_ERR(backing_file))
 		return fuse_EIO("failed to open backing file (%ld)", PTR_ERR(backing_file));
 
+	err = file_check_backing(backing_file, file->f_mode & (FMODE_READ | FMODE_WRITE), 0);
+	if (err) {
+		fput(backing_file);
+		return fuse_EIO("invalid backing file (%d)", err);
+	}
+
 	ff->passthrough = backing_file;
 	ff->cred = get_cred(fb->cred);
 
Signature · 1 line
2.53.0
#100 lore raw

Re: [PATCH RFC v3 40/44] fuse: refuse files on pseudo filesystems as passthrough backing files

Sashiko has reviewed this patch and found no issues.
Quoted 22 lines

The fuse server can register any regular file as a backing file. procfs and binfmt_misc files are already refused by the stacking depth check as both set s_stack_depth to FILESYSTEM_MAX_STACK_DEPTH. sysfs and the other pseudo filesystems aren't. Reads and writes of the fuse file would then be done on the pseudo file with the fuse server's credentials. Refuse files on pseudo filesystems just like loop does.

Note that the backing file is only registered here and opened again for every fuse file that uses it. Only its path is used and O_PATH file descriptors are allowed since commit efad7153bf93 ("fuse: allow O_PATH fd for FUSE_DEV_IOC_BACKING_OPEN"). So pass FMODE_PATH to file_check_backing() to keep them working.

The file that reads and writes are actually done on is opened in fuse_passthrough_open() with the flags of the fuse file. So check that file as well and pass the mode the fuse file was opened with. It has the same path as the registered file so files on pseudo filesystems are already refused. But this also makes sure that the backing file implements ->read_iter() if the fuse file is opened for reading and ->write_iter() if it is opened for writing. Like the other failures to set up passthrough this fails the open with EIO.

Quoted 4 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=40
author maintainer
#101 lore raw

RFC PATCH v3 41/44 usb: gadget: f_mass_storage: refuse files on pseudo filesystems

In reply to Christian Brauner

fsg_lun_open() takes any regular file as the backing file of a LUN. The file-storage kthread then reads and writes it with kernel_read() and kernel_write() on behalf of the USB host. With a procfs or sysfs file behind a LUN the host gets to read and write kernel interfaces with kernel credentials. Refuse files on pseudo filesystems just like loop does by switching to file_check_backing().

The helper also does the file type and readability checks. So the messages for an unsuitable backing file become one. It looks at the inode of the file instead of the host of ->f_mapping. For regular files and block devices both have the same type. It also wants ->read_iter() where FMODE_CAN_READ was enough so far. But kernel_read() never worked without ->read_iter() anyway.

---
 drivers/usb/gadget/function/storage_common.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/usb/gadget/function/storage_common.c +3 -8
index 75831f2c7abeb..af0c37a9fe029 100644
@@ -205,23 +205,18 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
 	if (!(filp->f_mode & FMODE_WRITE))
 		ro = 1;
 
-	inode = filp->f_mapping->host;
-	if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
-		LINFO(curlun, "invalid file type: %s\n", filename);
-		goto out;
-	}
-
 	/*
 	 * If we can't read the file, it's no good.
 	 * If we can't write the file, use it read-only.
 	 */
-	if (!(filp->f_mode & FMODE_CAN_READ)) {
-		LINFO(curlun, "file not readable: %s\n", filename);
+	if (file_check_backing(filp, FMODE_READ, S_IFBLK)) {
+		LINFO(curlun, "invalid backing file: %s\n", filename);
 		goto out;
 	}
 	if (!(filp->f_mode & FMODE_CAN_WRITE))
 		ro = 1;
 
+	inode = filp->f_mapping->host;
 	size = i_size_read(inode);
 	if (size < 0) {
 		LINFO(curlun, "unable to find file size: %s\n", filename);
Signature · 1 line
2.53.0
#102 lore raw

Re: [PATCH RFC v3 41/44] usb: gadget: f_mass_storage: refuse files on pseudo filesystems

Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

fsg_lun_open() takes any regular file as the backing file of a LUN. The file-storage kthread then reads and writes it with kernel_read() and kernel_write() on behalf of the USB host. With a procfs or sysfs file behind a LUN the host gets to read and write kernel interfaces with kernel credentials. Refuse files on pseudo filesystems just like loop does by switching to file_check_backing().

The helper also does the file type and readability checks. So the messages for an unsuitable backing file become one. It looks at the inode of the file instead of the host of ->f_mapping. For regular files and block devices both have the same type. It also wants ->read_iter() where FMODE_CAN_READ was enough so far. But kernel_read() never worked without ->read_iter() anyway.

Quoted 3 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=41
author maintainer
#103 lore raw

RFC PATCH v3 42/44 erofs: refuse files on pseudo filesystems as backing files

In reply to Christian Brauner

File-backed mounts take any regular file as the image and the same goes for the extra devices of such a mount. erofs reads them with the credentials of the mounter so this doesn't hand out anything the mounter couldn't read anyway. But files on pseudo filesystems aren't images. Refuse them just like loop does.

file_check_backing() also checks that the file is open for reading. So a source file descriptor that erofs can't read from fails the mount right away instead of on the first read.

---
 fs/erofs/super.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
fs/erofs/super.c +4 -1
index ce05557bd9983..517a289b9395c 100644
@@ -158,7 +158,7 @@ static int erofs_init_device(struct erofs_buf *buf, struct super_block *sb,
 		if (!erofs_is_fileio_mode(sbi)) {
 			dif->dax_dev = fs_dax_get_by_bdev(file_bdev(file),
 					&dif->dax_part_off, NULL, NULL);
-		} else if (!S_ISREG(file_inode(file)->i_mode)) {
+		} else if (file_check_backing(file, FMODE_READ, 0)) {
 			fput(file);
 			return -EINVAL;
 		}
@@ -835,6 +835,9 @@ static int erofs_file_get_tree(struct fs_context *fc)
 {
 	struct erofs_sb_info *sbi = fc->s_fs_info;
 
+	if (file_check_backing(sbi->dif0.file, FMODE_READ, 0))
+		return invalfc(fc, "source can't be used as a backing file");
+
 	if (!test_opt(&sbi->opt, SUPERBLOCK_SHARE))
 		return get_tree_nodev(fc, erofs_fc_fill_super);
 
Signature · 1 line
2.53.0
#104 lore raw

Re: [PATCH RFC v3 42/44] erofs: refuse files on pseudo filesystems as backing files

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

File-backed mounts take any regular file as the image and the same goes for the extra devices of such a mount. erofs reads them with the credentials of the mounter so this doesn't hand out anything the mounter couldn't read anyway. But files on pseudo filesystems aren't images. Refuse them just like loop does.

Quoted 8 lines

file_check_backing() also checks that the file is open for reading. So a source file descriptor that erofs can't read from fails the mount right away instead of on the first read.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=42
author maintainer
#105 lore raw

RFC PATCH v3 43/44 acct: refuse files on pseudo filesystems

In reply to Christian Brauner

acct(2) already refuses to write its records to files on kernel internal filesystems and to procfs and sysfs files. It recognizes the latter two by FS_USERNS_MOUNT_RESTRICTED which misses every other pseudo filesystem. So a cgroup2 or binfmt_misc file is accepted as the accounting file.

The records are written with the credentials of whoever turned on accounting so this isn't abusable the way loop is. But files on pseudo filesystems aren't a place to store accounting records. Use file_check_backing() to refuse all of them.

SB_NOUSER doesn't need to be checked separately anymore. It is only raised by pseudo filesystems and by tmpfs instances that are either kernel internal or can't be mounted.

---
 kernel/acct.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/acct.c +3 -3
index c440d43479ca5..0c502f778fde0 100644
@@ -245,11 +245,11 @@ static int acct_on(const char __user *name)
 		return -EACCES;
 
 	/* Exclude kernel internal filesystems. */
-	if (file_inode(file)->i_sb->s_flags & (SB_NOUSER | SB_KERNMOUNT))
+	if (file_inode(file)->i_sb->s_flags & SB_KERNMOUNT)
 		return -EINVAL;
 
-	/* Exclude procfs and sysfs. */
-	if (file_inode(file)->i_sb->s_type->fs_flags & FS_USERNS_MOUNT_RESTRICTED)
+	/* Exclude pseudo filesystems. */
+	if (file_check_backing(file, 0, 0))
 		return -EINVAL;
 
 	if (!(file->f_mode & FMODE_CAN_WRITE))
Signature · 1 line
2.53.0
#106 lore raw

Re: [PATCH RFC v3 43/44] acct: refuse files on pseudo filesystems

Sashiko has reviewed this patch and found no issues.
Quoted 15 lines

acct(2) already refuses to write its records to files on kernel internal filesystems and to procfs and sysfs files. It recognizes the latter two by FS_USERNS_MOUNT_RESTRICTED which misses every other pseudo filesystem. So a cgroup2 or binfmt_misc file is accepted as the accounting file.

The records are written with the credentials of whoever turned on accounting so this isn't abusable the way loop is. But files on pseudo filesystems aren't a place to store accounting records. Use file_check_backing() to refuse all of them.

SB_NOUSER doesn't need to be checked separately anymore. It is only raised by pseudo filesystems and by tmpfs instances that are either kernel internal or can't be mounted.

Quoted 5 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=43
author maintainer
#107 lore raw

RFC PATCH v3 44/44 selftests/filesystems: add backing file tests for pseudo files

In reply to Christian Brauner

Add tests that files on pseudo filesystems can't be used as storage:

- a procfs file attached read-only to a loop device
- sysfs files attached read-only and read-write to a loop device
- a sysfs file behind a lower-only overlayfs attached to a loop device
- a symlink and a magic link to a sysfs file attached to a loop device
- a procfs file as the backing file of an nvme target namespace
- a procfs file as the backing file and as the protection file of a fileio device of the scsi target
- a procfs file as a zloop zone file
- a sysfs file as the backing file of a usb mass storage gadget LUN
- a sysfs file as the source of a file-backed erofs mount
- a sysfs file as fuse passthrough backing file, by O_PATH and by regular file descriptor
- an O_PATH file descriptor of an overlayfs metacopy file whose data can't be found as fuse passthrough backing file

Add tests that FIFOs and character devices can't be used as storage by loop, the nvme target, the fileio backend and zloop either.

And make sure that a memfd and another loop device still work as loop backing files, that a regular file and a block device still work for the nvme target and the fileio backend, that a regular file still works as fuse passthrough backing file, that reads and writes of a fuse file still reach its backing file when that was registered by O_PATH and by regular file descriptor and that loop refuses a backing file that isn't open for reading.

The nvme target test uses buffered_io as asked for in [1]. Most pseudo files can't be opened with O_DIRECT and the test would pass without ever reaching the check.

[1]: https://lore.kernel.org/r/[email protected]

---
 tools/testing/selftests/filesystems/.gitignore     |   1 +
 tools/testing/selftests/filesystems/Makefile       |   2 +-
 tools/testing/selftests/filesystems/config         |  16 +
 .../selftests/filesystems/pseudo_backing_test.c    | 936 +++++++++++++++++++++
 4 files changed, 954 insertions(+), 1 deletion(-)
tools/testing/selftests/filesystems/.gitignore +1 -0
index cf79000e4092a..8df38eabb1252 100644
@@ -7,3 +7,4 @@ kernfs_test
 idmapped_tmpfile
 ustat_test
 rw_hint_test
+pseudo_backing_test
tools/testing/selftests/filesystems/Makefile +1 -1
index fbd5c27505ef5..0ebb9005bcd28 100644
@@ -2,7 +2,7 @@
 
 CFLAGS += $(KHDR_INCLUDES)
 TEST_GEN_PROGS := devpts_pts anon_inode_test kernfs_test fclog ustat_test rw_hint_test
-TEST_GEN_PROGS += idmapped_tmpfile
+TEST_GEN_PROGS += idmapped_tmpfile pseudo_backing_test
 TEST_GEN_PROGS_EXTENDED := dnotify_test
 
 include ../lib.mk
tools/testing/selftests/filesystems/config +16 -0
index 9f45bc493a30a..90f6f71cb4d9d 100644
@@ -6,3 +6,19 @@ CONFIG_NET=y
 CONFIG_NET_NS=y
 CONFIG_INET=y
 CONFIG_SYSFS=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_OVERLAY_FS=y
+CONFIG_TMPFS=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_USB_GADGET=y
+CONFIG_USB_CONFIGFS=y
+CONFIG_USB_CONFIGFS_MASS_STORAGE=y
+CONFIG_EROFS_FS=y
+CONFIG_EROFS_FS_BACKED_BY_FILE=y
+CONFIG_NVME_TARGET=y
+CONFIG_TARGET_CORE=y
+CONFIG_TCM_FILEIO=y
+CONFIG_BLK_DEV_ZONED=y
+CONFIG_BLK_DEV_ZONED_LOOP=y
+CONFIG_FUSE_FS=y
+CONFIG_FUSE_PASSTHROUGH=y
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +936 -0

936 lines not on this page · raw message

Signature · 1 line
2.53.0
#108 lore raw

Re: [PATCH RFC v3 44/44] selftests/filesystems: add backing file tests for pseudo files

Sashiko has reviewed this patch and found no issues.
Quoted 17 lines

Add tests that files on pseudo filesystems can't be used as storage:

- a procfs file attached read-only to a loop device
- sysfs files attached read-only and read-write to a loop device
- a sysfs file behind a lower-only overlayfs attached to a loop device
- a symlink and a magic link to a sysfs file attached to a loop device
- a procfs file as the backing file of an nvme target namespace
- a procfs file as the backing file and as the protection file of a fileio device of the scsi target
- a procfs file as a zloop zone file
- a sysfs file as the backing file of a usb mass storage gadget LUN
- a sysfs file as the source of a file-backed erofs mount
- a sysfs file as fuse passthrough backing file, by O_PATH and by regular file descriptor
- an O_PATH file descriptor of an overlayfs metacopy file whose data [ ... ]

Quoted 4 lines

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=44
#109 lore raw

Re: [PATCH RFC v3 44/44] selftests/filesystems: add backing file tests for pseudo files

In reply to Christian Brauner
TL;DR: - Selftest: fuse tests may fail instead of skip without CONFIG_FUSE_PASSTHROUGH (-EOPNOTSUPP, not -EPERM) - Metacopy test may fail without CONFIG_TMPFS_XATTR - Minor duplicated setup code
Quoted 1 line

selftests/filesystems: add backing file tests for pseudo files

TL;DR:
- Selftest: fuse tests may fail instead of skip without CONFIG_FUSE_PASSTHROUGH (-EOPNOTSUPP, not -EPERM)
- Metacopy test may fail without CONFIG_TMPFS_XATTR
- Minor duplicated setup code

tools/testing/selftests/filesystems/config CONFIG_NET=y · line 12

Quoted 11 lines
tools/testing/selftests/filesystems/config +4 -0
@@ -6,3 +6,19 @@ CONFIG_NET=y
 CONFIG_NET_NS=y
 CONFIG_INET=y
 CONFIG_SYSFS=y
+CONFIG_BLK_DEV_LOOP=y
+CONFIG_OVERLAY_FS=y
+CONFIG_TMPFS=y
+CONFIG_CONFIGFS_FS=y

[ ... ]

Should CONFIG_TMPFS_XATTR=y be added here as well?

TEST(fuse_passthrough_overlayfs_metacopy_file) mounts a private tmpfs through setup_tmp() and then does:

    ASSERT_EQ(setxattr("/tmp/lower/file", "trusted.overlay.metacopy",
                       "", 0, 0), 0);

shmem_fill_super() only sets sb->s_xattr under CONFIG_TMPFS_XATTR, which defaults to n, and CONFIG_TMPFS does not select it. Without it setxattr() fails with EOPNOTSUPP, the ASSERT_EQ() aborts, and the run reports a failure rather than a skip. tools/testing/selftests/landlock/config lists CONFIG_TMPFS_XATTR=y next to CONFIG_TMPFS=y.

Alternatively the test could SKIP when setxattr() returns EOPNOTSUPP.

Quoted 4 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +0 -0
new file mode 100644

[ ... ]

tools/testing/selftests/filesystems/pseudo_backing_test.c line 244

Quoted 8 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +8 -0
+TEST(overlayfs_on_sysfs_backing_file)
+{
+	if (!can_use_loop())
+		SKIP(return, "loop devices unavailable");
+
+	ASSERT_EQ(unshare(CLONE_NEWNS), 0);
+	ASSERT_EQ(mount(NULL, "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
+	ASSERT_EQ(mount("tmpfs", "/tmp", "tmpfs", 0, NULL), 0);

this isn't a bug, but could overlayfs_on_sysfs_backing_file() call ASSERT_EQ(setup_tmp(), 0) like the other tests, instead of repeating its three steps? Similarly, usb_mass_storage_backing_file() repeats the statfs()/CONFIGFS_MAGIC/mount() logic of setup_configfs(), and the comment "Mounting configfs on top of itself fails with EBUSY." appears twice.

[ ... ]

Quoted 4 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +4 -0
+TEST(fuse_passthrough_backing_file)
+{
+	int fuse_fd, ret;
+

[ ... ]

tools/testing/selftests/filesystems/pseudo_backing_test.c line 667

Quoted 5 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +5 -0
+	ASSERT_EQ(create_file("/tmp/file"), 0);
+	ret = fuse_backing_path(fuse_fd, "/tmp/file", O_PATH);
+	if (ret == -EPERM)
+		SKIP(return, "no fuse passthrough");
+	EXPECT_EQ(ret, 0);

Is -EPERM the right errno to key the skip on? On a kernel with CONFIG_FUSE_FS=y and CONFIG_FUSE_PASSTHROUGH=n the test filesystem mounts fine, and then fuse_dev_ioctl_backing_open() returns before any permission check:

    if (!IS_ENABLED(CONFIG_FUSE_PASSTHROUGH))
        return -EOPNOTSUPP;

-EPERM only comes from fuse_backing_open_file() when fc->passthrough is clear or CAP_SYS_ADMIN is missing. So here EXPECT_EQ(ret, 0) and the later -EINVAL checks see -EOPNOTSUPP and fail, and the harness records "not ok" for a feature that is not configured. Kernels that predate FUSE_DEV_IOC_BACKING_OPEN return -ENOTTY and fail the same way.

Should -EOPNOTSUPP (and possibly -ENOTTY) also lead to the SKIP?

[ ... ]

Quoted 1 line

+TEST(fuse_passthrough_overlayfs_metacopy_file)

[ ... ]

tools/testing/selftests/filesystems/pseudo_backing_test.c line 697

Quoted 5 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +5 -0
+	ASSERT_EQ(create_file("/tmp/lower/file"), 0);
+	ASSERT_EQ(setxattr("/tmp/lower/file", "trusted.overlay.metacopy",
+			   "", 0, 0), 0);
+	ASSERT_EQ(setxattr("/tmp/lower/file", "trusted.overlay.redirect",
+			   "/missing", strlen("/missing"), 0), 0);

Can these setxattr() calls fail on a kernel without CONFIG_TMPFS_XATTR?

The private tmpfs from setup_tmp() has no xattr handlers in that case, so setxattr() returns EOPNOTSUPP, the ASSERT_EQ() aborts, and the program exits with a failure instead of KSFT_SKIP. The mount of overlayfs just below already has a SKIP for missing support. Would a SKIP on EOPNOTSUPP here, or CONFIG_TMPFS_XATTR=y in the config fragment, avoid this?

tools/testing/selftests/filesystems/pseudo_backing_test.c line 711

Quoted 4 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +4 -0
+	ret = fuse_backing_path(fuse_fd, "/tmp/file", O_PATH);
+	if (ret == -EPERM)
+		SKIP(return, "no fuse passthrough");
+	ASSERT_EQ(ret, 0);

The same -EPERM check as in fuse_passthrough_backing_file() is used here, so ASSERT_EQ(ret, 0) fails with -EOPNOTSUPP when CONFIG_FUSE_PASSTHROUGH is off.

[ ... ]

Quoted 1 line

+TEST(fuse_passthrough_io)

[ ... ]

tools/testing/selftests/filesystems/pseudo_backing_test.c line 896

Quoted 5 lines
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +5 -0
+		srv.backing_ids[i] = fuse_backing_open(srv.fd, fd);
+		EXPECT_EQ(close(fd), 0);
+		if (srv.backing_ids[i] == -EPERM)
+			SKIP(return, "no fuse passthrough");
+		ASSERT_GT(srv.backing_ids[i], 0);

Does this skip also miss the unconfigured case? With CONFIG_FUSE_PASSTHROUGH=n, fuse_backing_open() gets -EOPNOTSUPP from the ioctl, which is not -EPERM, so ASSERT_GT(srv.backing_ids[i], 0) fails and run_one() records "not ok" for the whole pseudo_backing_test. No fuse server has been started at this point, so nothing hangs. The config fragment does list CONFIG_FUSE_PASSTHROUGH=y, but should -EOPNOTSUPP and -ENOTTY also lead to SKIP(return, "no fuse passthrough") in all three fuse tests?

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/43858134663