fs: don't use pseudo filesystem files as storage
Subsystems (39)
Christian Brauner
maintainercover 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 permittedBut 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.
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 seven 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 or 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 and selinuxfs. 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. Note that systemd mounts most of these filesystems with noexec and nodev already.
file_is_pseudo() looks at d_real_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.
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.
---
Christian Brauner (41):
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()
fs: add file_is_pseudo()
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 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 | 6 + drivers/block/zloop.c | 5 + drivers/nvme/target/io-cmd-file.c | 10 + drivers/target/target_core_file.c | 15 ++ drivers/usb/gadget/function/f_fs.c | 2 + drivers/usb/gadget/function/storage_common.c | 5 + 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 | 6 +- fs/failfs.c | 3 +- fs/fuse/backing.c | 3 + fs/fuse/control.c | 2 + 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/proc/root.c | 4 +- fs/pstore/inode.c | 2 + fs/tracefs/inode.c | 2 + include/linux/fs.h | 12 + include/linux/fs/super_types.h | 1 + include/linux/pseudo_fs.h | 11 + ipc/mqueue.c | 3 +- kernel/bpf/inode.c | 4 +- net/sunrpc/rpc_pipe.c | 2 + security/apparmor/apparmorfs.c | 2 + security/inode.c | 2 + 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 | 9 + .../selftests/filesystems/pseudo_backing_test.c | 274 +++++++++++++++++++++ 43 files changed, 419 insertions(+), 15 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261109-work-loop-pseudo-890844168ef1
Christian Brauner
maintainerRFC PATCH 1/41 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.
--- drivers/block/loop.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -0
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 01/41] loop: refuse backing files that aren't open for reading
Sashiko has reviewed this patch and found no issues.
Quoted 15 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 throughvfs_iter_read()which refuses files withoutFMODE_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 aboutO_DIRECThandling and theFMODE_READcheck 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.
Quoted 8 lines
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")Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH RFC 01/41] loop: refuse backing files that aren't open for reading
In reply to Christian BraunerQuoted 15 lines · Christian Brauner
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 throughvfs_iter_read()which refuses files withoutFMODE_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 aboutO_DIRECThandling and theFMODE_READcheck 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.
Quoted 8 lines
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")Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 22 lines
--- drivers/block/loop.c | 3 +++ 1 file changed, 3 insertions(+)drivers/block/loop.c +3
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 01/41] loop: refuse backing files that aren't open for reading
In reply to Christian BraunerThe fix itself looks good:
But i wonder if we want a thin wrapper around ->read_iter/_write_iter to do this check so that it matches the normal read/write path?
Christian Brauner
maintainerRe: [PATCH RFC 01/41] loop: refuse backing files that aren't open for reading
Quoted 2 lines · Christoph Hellwig
But i wonder if we want a thin wrapper around ->read_iter/_write_iter to do this check so that it matches the normal read/write path?
Yes, I had thought about that as well. We could use vfs_iocb_iter_{read,write}() for that but it's not thin at all and brings in the LSM into these codepaths where they shouldn't meddle.
So maybe as a follow-up series with a new vfs_iocb_iter_{read,write}_raw() or whatever. Feel free to make a suggestion.
Re: [PATCH RFC 01/41] loop: refuse backing files that aren't open for reading
In reply to Christian BraunerQuoted 26 lines · Christian Brauner
loop_configure()takes any file as long as it implements -Quoted 1 line
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
withoutFMODE_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 aboutO_DIRECThandling and theFMODE_READcheck 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 fileO_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 5 lines
Fixes bc07c10a3603 ("block: loop: support DIO & AIO")Fixes f2fed441c69b ("loop: stop using vfs_iter_{read,write} forbuffered I/O")
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 19 lines
---
drivers/block/loop.c | 3 +++1 file changed, 3 insertions(+)drivers/block/loop.c +0
-0@@ -528,6 +528,9 @@ static void loop_assign_backing_file(struct loop_device *lo, struct file *file)
static intloop_check_backing_file(struct file *file){drivers/block/loop.c +3
-0+if (!(file->f_mode &FMODE_READ )) +return -EBADF ; +if (!file->f_op->read_iter)
return-EINVAL;
Christian Brauner
maintainerRFC PATCH 2/41 nvmet: check that the file backend supports ->{read,write}_iter
In reply to Christian BraunerThe 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").
--- drivers/nvme/target/io-cmd-file.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/nvme/target/io-cmd-file.c +5 -0
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 02/41] nvmet: check that the file backend supports ->{read,write}_iter
Sashiko has reviewed this patch and found no issues.
Quoted 6 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_DIRECTopen fails for such files.
Quoted 6 lines
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")Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH RFC 02/41] nvmet: check that the file backend supports ->{read,write}_iter
In reply to Christian BraunerQuoted 6 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_DIRECTopen fails for such files.
Quoted 6 lines
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")Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 24 lines
--- drivers/nvme/target/io-cmd-file.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/nvme/target/io-cmd-file.c +5
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 02/41] nvmet: check that the file backend supports ->{read,write}_iter
In reply to Christian BraunerLooks good:
Christian Brauner
maintainerRFC PATCH 3/41 target: fileio: check that the backing file supports ->{read,write}_iter
In reply to Christian BraunerWith 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.
--- drivers/target/target_core_file.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/target/target_core_file.c +8 -0
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 03/41] target: fileio: check that the backing file supports ->{read,write}_iter
Sashiko has reviewed this patch and found no issues.
Quoted 6 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()andvfs_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.
Quoted 6 lines
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")Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH RFC 03/41] target: fileio: check that the backing file supports ->{read,write}_iter
In reply to Christian BraunerQuoted 6 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()andvfs_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.
Quoted 6 lines
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")Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 27 lines
--- drivers/target/target_core_file.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/target/target_core_file.c +8
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 03/41] target: fileio: check that the backing file supports ->{read,write}_iter
In reply to Christian BraunerQuoted 9 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()andvfs_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.
Looks good:
Christian Brauner
maintainerRFC PATCH 4/41 fs: add SB_I_PSEUDO
In reply to Christian BraunerCurrently, 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 or device nodes. 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 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 | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-)
fs/libfs.c +1 -1
@@ -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
@@ -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 +11 -0
@@ -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,14 @@ 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 or device nodes. +*/ +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
[email protected]
AI reviewRe: [PATCH RFC 04/41] fs: add SB_I_PSEUDO
Sashiko has reviewed this patch and found no issues.
Quoted 22 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_PSEUDOso a filesystem can state that its regular files are kernel interfaces and must not be used as storage.Pseudo filesystems also never hold executables or device nodes. But currently each of them decides on its own whether to raise
SB_I_NOEXECandSB_I_NODEV. Some do, most don't. Addfc_init_pseudo()as the common initialization point for all pseudo filesystems that raises all three flags and switchinit_pseudo()over to it. The following patches convert the mountable pseudo filesystems.
Quoted 3 lines
Nothing checks
SB_I_PSEUDOyet so no functional changes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH RFC 04/41] fs: add SB_I_PSEUDO
In reply to Christian BraunerQuoted 22 lines · 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_PSEUDOso a filesystem can state that its regular files are kernel interfaces and must not be used as storage.Pseudo filesystems also never hold executables or device nodes. But currently each of them decides on its own whether to raise
SB_I_NOEXECandSB_I_NODEV. Some do, most don't. Addfc_init_pseudo()as the common initialization point for all pseudo filesystems that raises all three flags and switchinit_pseudo()over to it. The following patches convert the mountable pseudo filesystems.
Quoted 3 lines
Nothing checks
SB_I_PSEUDOyet so no functional changes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 61 lines
--- fs/libfs.c | 2 +- include/linux/fs/super_types.h | 1 + include/linux/pseudo_fs.h | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-)fs/libfs.c +1
-1@@ -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@@ -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 +11
-0@@ -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,14 @@ 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 or device nodes. +*/ +static inline void fc_init_pseudo (struct fs_context *fc) +{ + fc->s_iflags |=SB_I_PSEUDO |SB_I_NOEXEC |SB_I_NODEV ; +} +#endif Signature · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 04/41] fs: add SB_I_PSEUDO
In reply to Christian BraunerLooks good:
Re: [PATCH RFC 04/41] fs: add SB_I_PSEUDO
In reply to Christian BraunerQuoted 27 lines · 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_PSEUDOso a filesystem can state that its regular files are kernel interfaces and must not be used as storage.Pseudo filesystems also never hold executables or device nodes. But currently each of them decides on its own whether to raise
SB_I_NOEXEC
andSB_I_NODEV. Some do, most don't. Addfc_init_pseudo()as the common
initialization point for all pseudo filesystems that raises all three flags and switchinit_pseudo()over to it. The following patches convert the mountable pseudo filesystems.
Quoted 3 lines
Nothing checks
SB_I_PSEUDOyet so no functional changes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 65 lines
---
fs/libfs.c | 2 +-
include/linux/fs/super_types.h | 1 +
include/linux/pseudo_fs.h | 11 +++++++++++3 files changed, 13 insertions(+), 1 deletion(-)fs/libfs.c +1
-1@@ -735,7 +735,7 @@ struct pseudo_fs_context *init_pseudo(structfs_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 +0
-0@@ -359,5 +359,6 @@ struct super_block { #define SB_I_NOIDMAP 0x00002000 /* No idmapped mounts onthis superblock */
#defineSB_I_ALLOW_HSM0x00004000/* Allow HSM events on this
superblock */
#defineSB_I_NO_DATA_INTEGRITY0x00008000/* fs cannot guarantee
data persistence on sync */
+#defineSB_I_PSEUDO0x00010000/* regular files are kernel
interfaces, not storage */
#endif /*_LINUX_FS_SUPER_TYPES_H*/include/linux/pseudo_fs.h +0
-0@@ -2,6 +2,7 @@ #define __LINUX_PSEUDO_FS__
#include <linux/fs_context.h>
+#include <linux/fs/super_types.h>
structpseudo_fs_context{
const structsuper_operations*ops;include/linux/pseudo_fs.h +0
-0@@ -15,4 +16,14 @@ 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 or device nodes.
+ */include/linux/pseudo_fs.h +5
-0+static inline void fc_init_pseudo (struct fs_context *fc) +{ + fc->s_iflags |=SB_I_PSEUDO |SB_I_NOEXEC |SB_I_NODEV ; +} +#endif
Christian Brauner
maintainerRFC PATCH 5/41 kernfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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 *kstruct 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
[email protected]
AI reviewRe: [PATCH RFC 05/41] kernfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
Initialize all kernfs based filesystems as pseudo filesystems in
kernfs_get_tree()instead of raisingSB_I_NOEXECandSB_I_NODEVby hand inkernfs_fill_super(). This addsSB_I_PSEUDOfor sysfs, cgroupfs and resctrl.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH RFC 05/41] kernfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
Initialize all kernfs based filesystems as pseudo filesystems in
kernfs_get_tree()instead of raisingSB_I_NOEXECandSB_I_NODEVby hand inkernfs_fill_super(). This addsSB_I_PSEUDOfor sysfs, cgroupfs and resctrl.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Makes sense. Feel free to add:
Honza
Quoted 37 lines
--- fs/kernfs/mount.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/kernfs/mount.c +2
-2@@ -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 *kstruct 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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 05/41] kernfs: use fc_init_pseudo()
In reply to Christian BraunerLooks good:
Re: [PATCH RFC 05/41] kernfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 7 lines · Christian Brauner
Initialize all kernfs based filesystems as pseudo filesystems in
kernfs_get_tree()instead of raisingSB_I_NOEXECandSB_I_NODEVby hand
inkernfs_fill_super(). This addsSB_I_PSEUDOfor sysfs, cgroupfs and resctrl.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 35 lines
---
fs/kernfs/mount.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)fs/kernfs/mount.c +0
-0@@ -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>fs/kernfs/mount.c +0
-0@@ -298,8 +299,6 @@ static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *k struct dentry *root;
info->sb= sb;fs/kernfs/mount.c +0
-1-/* Userspace would break if executables or devices appear on sysfs */
fs/kernfs/mount.c +0
-1- 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;fs/kernfs/mount.c +0
-0@@ -388,6 +387,7 @@ int kernfs_get_tree(struct fs_context *fc) info->ns = kfc->ns_tag; INIT_LIST_HEAD(&info->node);fs/kernfs/mount.c +1
-0+fc_init_pseudo (fc);
fc->s_fs_info= info;
sb =sget_fc(fc, kernfs_test_super, kernfs_set_super); if (IS_ERR(sb))
Christian Brauner
maintainerRFC PATCH 6/41 proc: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 06/41] proc: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Initialize procfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH RFC 06/41] proc: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize procfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Makes sense. Feel free to add:
Honza
Quoted 37 lines
--- fs/proc/root.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)fs/proc/root.c +2
-2@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 06/41] proc: use fc_init_pseudo()
In reply to Christian BraunerLooks good:
Re: [PATCH RFC 06/41] proc: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize procfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 35 lines
fs/proc/root.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)fs/proc/root.c +1
-0@@ -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;fs/proc/root.c +0
-1-/* User space would break if executables or devices appear on proc */
fs/proc/root.c +0
-1- 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;fs/proc/root.c +1
-0@@ -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;}
Christian Brauner
maintainerRFC PATCH 7/41 binfmt_misc: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 07/41] binfmt_misc: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Initialize
binfmt_miscas a pseudo filesystem instead of raisingSB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
Re: [PATCH RFC 07/41] binfmt_misc: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize
binfmt_miscas a pseudo filesystem instead of raisingSB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
OK. Feel free to add:
Honza
Quoted 38 lines
--- fs/binfmt_misc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)fs/binfmt_misc.c +3
-2@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 07/41] binfmt_misc: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize
binfmt_miscas a pseudo filesystem instead of raisingSB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 36 lines
---
fs/binfmt_misc.c | 5 +++--1 file changed, 3 insertions(+), 2 deletions(-)fs/binfmt_misc.c +1
-0@@ -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;fs/binfmt_misc.c +0
-1-/* Never exec off this instance and never let anything stack on it. */
fs/binfmt_misc.c +1
-1- sb->s_iflags |=SB_I_NOEXEC |SB_I_NODEV ; +/* Never let anything stack on this instance. */
sb->s_stack_depth=FILESYSTEM_MAX_STACK_DEPTH;
/*fs/binfmt_misc.c +0
-0@@ -1660,6 +1660,7 @@ static void bm_kill_sb(struct super_block *sb)
static intbm_init_fs_context(struct fs_context *fc){fs/binfmt_misc.c +1
-0+fc_init_pseudo (fc);
fc->ops=&bm_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 8/41 mqueue: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 08/41] mqueue: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Initialize mqueue as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH RFC 08/41] mqueue: use fc_init_pseudo()
In reply to Christian BraunerLooks good:
Re: [PATCH RFC 08/41] mqueue: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize mqueue as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 34 lines
---
ipc/mqueue.c | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)ipc/mqueue.c +1
-0@@ -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;ipc/mqueue.c +0
-1- 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;ipc/mqueue.c +1
-0@@ -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;}
Christian Brauner
maintainerRFC PATCH 9/41 bpf: use fc_init_pseudo() for bpffs
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 09/41] bpf: use fc_init_pseudo() for bpffs
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Initialize bpffs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH RFC 09/41] bpf: use fc_init_pseudo() for bpffs
In reply to Christian BraunerLooks good:
Re: [PATCH RFC 09/41] bpf: use fc_init_pseudo() for bpffs
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize bpffs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 35 lines
---
kernel/bpf/inode.c | 4 ++--1 file changed, 2 insertions(+), 2 deletions(-)kernel/bpf/inode.c +1
-2@@ -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);kernel/bpf/inode.c +0
-0@@ -1261,6 +1260,7 @@ static int bpf_init_fs_context(struct fs_context *fc) opts->delegate_attachs = 0;
fc->s_fs_info= opts;kernel/bpf/inode.c +1
-0+fc_init_pseudo (fc);
fc->ops=&bpf_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 10/41 nullfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 10/41] nullfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Initialize nullfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
Re: [PATCH RFC 10/41] nullfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize nullfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 29 lines
--- fs/nullfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/nullfs.c +2
-1@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 10/41] nullfs: use fc_init_pseudo()
In reply to Christian BraunerRe: [PATCH RFC 10/41] nullfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize nullfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 26 lines
---
fs/nullfs.c | 3 ++-1 file changed, 2 insertions(+), 1 deletion(-)fs/nullfs.c +2
-1@@ -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; }
Christian Brauner
maintainerRFC PATCH 11/41 failfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 11/41] failfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines
Initialize failfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
Re: [PATCH RFC 11/41] failfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 4 lines · Christian Brauner
Initialize failfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 29 lines
--- fs/failfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)fs/failfs.c +2
-1@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 11/41] failfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 2 lines · Christian Brauner
Initialize failfs as a pseudo filesystem instead of raising
SB_I_NOEXECandSB_I_NODEVby hand. This addsSB_I_PSEUDO.
Looks good:
Christian Brauner
maintainerRFC PATCH 12/41 rust_binderfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 12/41] 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_NOEXECby hand. This addsSB_I_PSEUDO.binderfs_fill_super()keeps clearingSB_I_NODEVfor the binder device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
Christian Brauner
maintainerRFC PATCH 13/41 devpts: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 13/41] devpts: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize devpts as a pseudo filesystem. This raises
SB_I_PSEUDOandSB_I_NOEXEC. devpts never holds executables.devpts_fill_super()keeps clearingSB_I_NODEVfor the pty device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
Re: [PATCH RFC 13/41] devpts: use fc_init_pseudo()
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
Initialize devpts as a pseudo filesystem. This raises
SB_I_PSEUDOandSB_I_NOEXEC. devpts never holds executables.devpts_fill_super()keeps
clearingSB_I_NODEVfor the pty device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/devpts/inode.c | 2 ++1 file changed, 2 insertions(+)fs/devpts/inode.c +1
-0@@ -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;fs/devpts/inode.c +1
-0+fc_init_pseudo (fc);
fc->ops=&devpts_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 14/41 debugfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 14/41] debugfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Initialize debugfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. debugfs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. The debugfs files that can be mapped, kcov, relay channels and powernv's memtrace, map data.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
Re: [PATCH RFC 14/41] debugfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 8 lines · Christian Brauner
Initialize debugfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. debugfs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. The debugfs files that can be mapped, kcov, relay channels and powernv's memtrace, map data.Signed-off-by Christian Brauner (Amutable) <[email protected]>
OK, makes sense. Feel free to add:
Honza
Quoted 28 lines
--- fs/debugfs/inode.c | 2 ++ 1 file changed, 2 insertions(+)fs/debugfs/inode.c +2
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 14/41] debugfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 9 lines · Christian Brauner
Initialize debugfs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. debugfs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. The debugfs files that can be mapped, kcov, relay channels and powernv's memtrace, map data.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/debugfs/inode.c | 2 ++1 file changed, 2 insertions(+)fs/debugfs/inode.c +1
-0@@ -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;fs/debugfs/inode.c +1
-0+fc_init_pseudo (fc);
fc->ops=&debugfs_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 15/41 tracefs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 15/41] tracefs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 9 lines
Initialize tracefs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. tracefs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. The only tracefs files that can be mapped are the ring buffers and__rb_map_vma()refusesVM_EXECalready.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
Re: [PATCH RFC 15/41] tracefs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 10 lines · Christian Brauner
Initialize tracefs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. tracefs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. The only tracefs files that can be mapped are the ring buffers and__rb_map_vma()refusesVM_EXECalready.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/tracefs/inode.c | 2 ++1 file changed, 2 insertions(+)fs/tracefs/inode.c +1
-0@@ -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;fs/tracefs/inode.c +1
-0+fc_init_pseudo (fc);
fc->ops=&tracefs_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 16/41 configfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 16/41] configfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize configfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. configfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=16
Re: [PATCH RFC 16/41] configfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 5 lines · Christian Brauner
Initialize configfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. configfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Makes sense. Feel free to add:
Honza
Quoted 28 lines
--- fs/configfs/mount.c | 2 ++ 1 file changed, 2 insertions(+)fs/configfs/mount.c +2
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 16/41] configfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 5 lines · Christian Brauner
Initialize configfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. configfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Re: [PATCH RFC 16/41] configfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
Initialize configfs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. configfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/configfs/mount.c | 2 ++1 file changed, 2 insertions(+)fs/configfs/mount.c +1
-0@@ -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 intconfigfs_init_fs_context(struct fs_context *fc){fs/configfs/mount.c +1
-0+fc_init_pseudo (fc);
fc->ops=&configfs_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 17/41 securityfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize securityfs as a pseudo filesystem. This raises SB_I_PSEUDO and also SB_I_NOEXEC and SB_I_NODEV. securityfs never holds executables or device nodes.
AppArmor puts a .null device node into securityfs but only ever opens it via dentry_open() which doesn't care about SB_I_NODEV.
--- security/inode.c | 2 ++ 1 file changed, 2 insertions(+)
security/inode.c +2 -0
@@ -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>
@@ -64,6 +65,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
[email protected]
AI reviewRe: [PATCH RFC 17/41] securityfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Initialize securityfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. securityfs never holds executables or device nodes.AppArmor puts a .null device node into securityfs but only ever opens it via
dentry_open()which doesn't care aboutSB_I_NODEV.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=17
Re: [PATCH RFC 17/41] securityfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 10 lines · Christian Brauner
Initialize securityfs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. securityfs never holds executables or
device nodes.AppArmor puts a .null device node into securityfs but only ever opens it via
dentry_open()which doesn't care aboutSB_I_NODEV.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
security/inode.c | 2 ++1 file changed, 2 insertions(+)security/inode.c +1
-0@@ -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>@@ -64,6 +65,7 @@ static const struct fs_context_operations securityfs_context_ops = {
static intsecurityfs_init_fs_context(struct fs_context *fc){security/inode.c +1
-0+fc_init_pseudo (fc);
fc->ops=&securityfs_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 18/41 selinux: use fc_init_pseudo() for selinuxfs
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 18/41] selinux: use fc_init_pseudo() for selinuxfs
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize selinuxfs as a pseudo filesystem. This raises
SB_I_PSEUDOandSB_I_NOEXEC. selinuxfs never holds executables.SB_I_NOEXECalso refusesPROT_EXECmappings but the status and policy files are only ever mapped for reading.
Quoted 7 lines
But selinuxfs needs device nodes. The kernel replaces file descriptors with
/sys/fs/selinux/nullon exec viadentry_open()which doesn't care aboutSB_I_NODEV. Android init however opens/sys/fs/selinux/nullby path as/dev/nulldoesn't exist yet at that point. So clearSB_I_NODEVagain insel_fill_super().Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=18
Re: [PATCH RFC 18/41] selinux: use fc_init_pseudo() for selinuxfs
In reply to Christian BraunerQuoted 15 lines · Christian Brauner
Initialize selinuxfs as a pseudo filesystem. This raises
SB_I_PSEUDOandSB_I_NOEXEC. selinuxfs never holds executables.SB_I_NOEXECalso refusesPROT_EXECmappings 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/nullon exec viadentry_open()which doesn't care
aboutSB_I_NODEV. Android init however opens/sys/fs/selinux/nullby path as/dev/nulldoesn't exist yet at that point. So clearSB_I_NODEV
again insel_fill_super().
Quoted 1 line
Signed-off-by Christian Brauner (Amutable) <[email protected]>
I.
Quoted 37 lines
---
security/selinux/selinuxfs.c | 5 +++++1 file changed, 5 insertions(+)security/selinux/selinuxfs.c +1
-0@@ -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;security/selinux/selinuxfs.c +0
-0@@ -1955,6 +1959,7 @@ static const struct fs_context_operations sel_context_ops = {
static intsel_init_fs_context(struct fs_context *fc){
+fc_init_pseudo(fc);
fc->ops=&sel_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 19/41 smack: use fc_init_pseudo() for smackfs
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 19/41] smack: use fc_init_pseudo() for smackfs
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize smackfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. smackfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=19
Re: [apparmor] [PATCH RFC 19/41] smack: use fc_init_pseudo() for smackfs
In reply to Christian BraunerQuoted 5 lines · Christian Brauner via AppArmor
Initialize smackfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. smackfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Please include me at least as a CC on Smack patches. I ain't dead yet. Nonetheless,
Quoted 25 lines
--- security/smack/smackfs.c | 2 ++ 1 file changed, 2 insertions(+)security/smack/smackfs.c +2
-0@@ -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 ; }
Re: [PATCH RFC 19/41] smack: use fc_init_pseudo() for smackfs
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
Initialize smackfs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. smackfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
security/smack/smackfs.c | 2 ++1 file changed, 2 insertions(+)security/smack/smackfs.c +1
-0@@ -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)security/smack/smackfs.c +1
-0@@ -2880,6 +2881,7 @@ static const struct fs_context_operationssmk_context_ops = { */ static int smk_init_fs_context(struct fs_context *fc) { +fc_init_pseudo (fc); fc->ops = &smk_context_ops; return 0;}
Christian Brauner
maintainerRFC PATCH 20/41 apparmor: use fc_init_pseudo() for apparmorfs
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 20/41] apparmor: use fc_init_pseudo() for apparmorfs
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize apparmorfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. apparmorfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=20
Re: [PATCH RFC 20/41] apparmor: use fc_init_pseudo() for apparmorfs
In reply to Christian BraunerQuoted 7 lines · Christian Brauner
Initialize apparmorfs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. apparmorfs never holds executables or
device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 26 lines
---
security/apparmor/apparmorfs.c | 2 ++1 file changed, 2 insertions(+)security/apparmor/apparmorfs.c +1
-0@@ -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 intapparmorfs_init_fs_context(struct fs_context *fc){security/apparmor/apparmorfs.c +1
-0+fc_init_pseudo (fc);
fc->ops=&apparmorfs_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 21/41 nfsd: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 21/41] nfsd: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize the nfsd filesystem as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. It never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=21
Re: [PATCH RFC 21/41] nfsd: use fc_init_pseudo()
In reply to Christian BraunerQuoted 32 lines · Christian Brauner
Initialize the nfsd filesystem as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. It never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>--- fs/nfsd/nfsctl.c | 2 ++ 1 file changed, 2 insertions(+)fs/nfsd/nfsctl.c +2
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 1 line
Chuck Lever (Come to NFS bake-a-thon! https://nfsv4bat.org)
Christian Brauner
maintainerRFC PATCH 22/41 sunrpc: use fc_init_pseudo() for rpc_pipefs
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 22/41] sunrpc: use fc_init_pseudo() for rpc_pipefs
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize
rpc_pipefsas a pseudo filesystem. This raisesSB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV.rpc_pipefsnever holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=22
Re: [PATCH RFC 22/41] sunrpc: use fc_init_pseudo() for rpc_pipefs
In reply to Christian BraunerQuoted 7 lines · Christian Brauner
Initialize
rpc_pipefsas a pseudo filesystem. This raisesSB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV.rpc_pipefsnever holds executables or
device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
net/sunrpc/rpc_pipe.c | 2 ++1 file changed, 2 insertions(+)net/sunrpc/rpc_pipe.c +2
-0@@ -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;}
Christian Brauner
maintainerRFC PATCH 23/41 fuse: use fc_init_pseudo() for fusectl
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 23/41] fuse: use fc_init_pseudo() for fusectl
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize fusectl as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. fusectl never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=23
Re: [PATCH RFC 23/41] fuse: use fc_init_pseudo() for fusectl
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
Initialize fusectl as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. fusectl never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/fuse/control.c | 2 ++1 file changed, 2 insertions(+)fs/fuse/control.c +1
-0@@ -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>
#defineFUSE_CTL_SUPER_MAGIC0x65735543fs/fuse/control.c +0
-0@@ -334,6 +335,7 @@ static const struct fs_context_operations fuse_ctl_context_ops = {
static intfuse_ctl_init_fs_context(struct fs_context *fsc){fs/fuse/control.c +1
-0+fc_init_pseudo (fsc);
fsc->ops=&fuse_ctl_context_ops;
return 0;
}
Christian Brauner
maintainerRFC PATCH 24/41 efivarfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 24/41] efivarfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize efivarfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. efivarfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=24
Re: [PATCH RFC 24/41] efivarfs: use fc_init_pseudo()
In reply to Christian BraunerQuoted 6 lines · Christian Brauner
Initialize efivarfs as a pseudo filesystem. This raises
SB_I_PSEUDOand
alsoSB_I_NOEXECandSB_I_NODEV. efivarfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/efivarfs/super.c | 2 ++1 file changed, 2 insertions(+)fs/efivarfs/super.c +1
-0@@ -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;fs/efivarfs/super.c +1
-0+fc_init_pseudo (fc);
fc->ops=&efivarfs_context_ops;
return 0;
Christian Brauner
maintainerRFC PATCH 25/41 pstore: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 25/41] pstore: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize pstore as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. pstore never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=25
Re: [PATCH RFC 25/41] pstore: use fc_init_pseudo()
In reply to Christian BraunerQuoted 5 lines · Christian Brauner
Initialize pstore as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. pstore never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 25 lines
---
fs/pstore/inode.c | 2 ++1 file changed, 2 insertions(+)fs/pstore/inode.c +1
-0@@ -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;fs/pstore/inode.c +1
-0+fc_init_pseudo (fc);
fc->ops=&pstore_context_ops;
return 0;
Christian Brauner
maintainerRFC PATCH 26/41 xenfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 26/41] xenfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
Initialize xenfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. xenfs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. xenfs maps the xenstore page and guest memory through privcmd, both data.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=26
Christian Brauner
maintainerRFC PATCH 27/41 openpromfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 27/41] 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_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. openpromfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=27
Christian Brauner
maintainerRFC PATCH 28/41 ocfs2: use fc_init_pseudo() for dlmfs
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 28/41] ocfs2: use fc_init_pseudo() for dlmfs
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize dlmfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. dlmfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=28
Re: [PATCH RFC 28/41] ocfs2: use fc_init_pseudo() for dlmfs
In reply to Christian BraunerQuoted 5 lines · Christian Brauner
Initialize dlmfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. dlmfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 28 lines
--- fs/ocfs2/dlmfs/dlmfs.c | 2 ++ 1 file changed, 2 insertions(+)fs/ocfs2/dlmfs/dlmfs.c +2
-0@@ -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 · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Christian Brauner
maintainerRFC PATCH 29/41 s390/hypfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 29/41] 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_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. hypfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=29
Christian Brauner
maintainerRFC PATCH 30/41 powerpc/spufs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 30/41] 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_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. spufs never holds executables or device nodes.
SB_I_NOEXECalso refusesPROT_EXECmappings. The spufs files that can be mapped expose local store and problem state areas of the SPU, nothing the PPU executes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=30
Christian Brauner
maintainerRFC PATCH 31/41 usb: gadget: f_fs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 31/41] usb: gadget: f_fs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize functionfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. functionfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=31
Christian Brauner
maintainerRFC PATCH 32/41 usb: gadget: gadgetfs: use fc_init_pseudo()
In reply to Christian BraunerInitialize 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
@@ -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
[email protected]
AI reviewRe: [PATCH RFC 32/41] usb: gadget: gadgetfs: use fc_init_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 5 lines
Initialize gadgetfs as a pseudo filesystem. This raises
SB_I_PSEUDOand alsoSB_I_NOEXECandSB_I_NODEV. gadgetfs never holds executables or device nodes.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=32
Christian Brauner
maintainerRFC PATCH 33/41 fs: add file_is_pseudo()
In reply to Christian BraunerAdd a helper to check whether a file is a regular file on a pseudo filesystem. Only regular files count. Device nodes on pseudo filesystems such as devpts, binderfs or the block devices on bdevfs are what they are.
Look at the inode that actually provides the data via d_real_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.
No functional changes.
--- include/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/fs.h +12 -0
@@ -2553,6 +2553,18 @@ static inline const struct inode *file_user_inode(const struct file *f)return file_inode (f); } +/* +* Regular files on pseudo filesystems are kernel interfaces and must not be +* used as storage. Look through stacking filesystems at the inode that +* provides the data. +*/ +static inline bool file_is_pseudo (const struct file *file) +{ +const struct inode *inode =d_real_inode (file->f_path.dentry); + +return S_ISREG (inode->i_mode) && (inode->i_sb->s_iflags &SB_I_PSEUDO ); +} +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
[email protected]
AI reviewRe: [PATCH RFC 33/41] fs: add file_is_pseudo()
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines
Add a helper to check whether a file is a regular file on a pseudo filesystem. Only regular files count. Device nodes on pseudo filesystems such as devpts, binderfs or the block devices on bdevfs are what they are.
Look at the inode that actually provides the data via
d_real_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.
Quoted 3 lines
No functional changes.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=33
Re: [PATCH RFC 33/41] fs: add file_is_pseudo()
In reply to Christian BraunerQuoted 11 lines · Christian Brauner
Add a helper to check whether a file is a regular file on a pseudo filesystem. Only regular files count. Device nodes on pseudo filesystems such as devpts, binderfs or the block devices on bdevfs are what they are.
Look at the inode that actually provides the data via
d_real_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.
Quoted 3 lines
No functional changes.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 31 lines
--- include/linux/fs.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)include/linux/fs.h +12
-0@@ -2553,6 +2553,18 @@ static inline const struct inode *file_user_inode(const struct file *f)return file_inode (f); } +/* +* Regular files on pseudo filesystems are kernel interfaces and must not be +* used as storage. Look through stacking filesystems at the inode that +* provides the data. +*/ +static inline bool file_is_pseudo (const struct file *file) +{ +const struct inode *inode =d_real_inode (file->f_path.dentry); + +return S_ISREG (inode->i_mode) && (inode->i_sb->s_iflags &SB_I_PSEUDO ); +} +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
Re: [PATCH RFC 33/41] fs: add file_is_pseudo()
In reply to Christian BraunerQuoted 12 lines · Christian Brauner
Add a helper to check whether a file is a regular file on a pseudo filesystem. Only regular files count. Device nodes on pseudo filesystems
such as devpts, binderfs or the block devices on bdevfs are what they are.Look at the inode that actually provides the data via
d_real_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.
Quoted 3 lines
No functional changes.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 33 lines
---
include/linux/fs.h | 12 ++++++++++++1 file changed, 12 insertions(+)include/linux/fs.h +0
-0@@ -2553,6 +2553,18 @@ static inline const struct inode *file_user_inode(const struct file *f) return file_inode(f); }
+/*
+ * Regular files on pseudo filesystems are kernel interfaces and must not be
+ * used as storage. Look through stacking filesystems at the inode that
+ * provides the data.
+ */include/linux/fs.h +3
-0+static inline bool file_is_pseudo (const struct file *file) +{ + const struct inode *inode = d_real_inode(file-Quoted 1 line
f_path.dentry);
include/linux/fs.h +2
-0+ + return S_ISREG(inode->i_mode) && (inode->i_sb->s_iflags &
SB_I_PSEUDO);include/linux/fs.h +2
-0+} +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);
Christian Brauner
maintainerRFC PATCH 34/41 loop: refuse files on pseudo filesystems as backing files
In reply to Christian BraunerCurrently 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. Note that file_is_pseudo() looks through overlayfs so stacking overlayfs on top of sysfs doesn't get around this.
--- drivers/block/loop.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/block/loop.c +3 -0
@@ -537,6 +537,9 @@ static int loop_check_backing_file(struct file *file)if ((file->f_mode &FMODE_WRITE ) && !file->f_op->write_iter)return -EINVAL ; +if (file_is_pseudo (file)) +return -EINVAL ; +return 0 ; }
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 34/41] loop: refuse files on pseudo filesystems as backing files
Sashiko has reviewed this patch and found no issues.
Quoted 20 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/kcoreattaches 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/enabledchanges 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 [ ... ]
Refuse files on pseudo filesystems as loop backing files. Note thatfile_is_pseudo()looks through overlayfs so stacking overlayfs on top of sysfs doesn't get around this.
Quoted 1 line
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=34
Re: [PATCH RFC 34/41] loop: refuse files on pseudo filesystems as backing files
In reply to Christian BraunerQuoted 31 lines · 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/kcoreattaches 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/enabledchanges 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/modeasmode_store()requiresCAP_SYS_BOOT. Writing "warm" through a loop device works.- uid 0 without any capabilities can't read the files in
/sys/firmware/dmi/entries/*/asdmi_sysfs_attr_show()requiresCAP_SYS_ADMIN. Reading them through a loop device works.- An unprivileged container that was handed a loop device can't change
gro_flush_timeoutof its own network devices asgro_flush_timeout_store()requiresCAP_NET_ADMINin the initial user namespace. Writing it through a loop device works.
Quoted 8 lines
The same goes for
hard_offline_page, the md and sd attributes, rfkill and others.Refuse files on pseudo filesystems as loop backing files. Note that
file_is_pseudo()looks through overlayfs so stacking overlayfs on top of sysfs doesn't get around this.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 22 lines
--- drivers/block/loop.c | 3 +++ 1 file changed, 3 insertions(+)drivers/block/loop.c +3
-0@@ -537,6 +537,9 @@ static int loop_check_backing_file(struct file *file)if ((file->f_mode &FMODE_WRITE ) && !file->f_op->write_iter)return -EINVAL ; +if (file_is_pseudo (file)) +return -EINVAL ; +return 0 ; }Signature · 2 lines
-- 2.53.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Re: [PATCH RFC 34/41] loop: refuse files on pseudo filesystems as backing files
In reply to Christian BraunerQuoted 45 lines · 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/kcoreattaches 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/enabledchanges the THP setting.That's not just nonsensical, it can be abused. Loop calls -
Quoted 1 line
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
asmode_store()requiresCAP_SYS_BOOT. Writing "warm" through a loop
device works.- uid 0 without any capabilities can't read the files in
/sys/firmware/dmi/entries/*/asdmi_sysfs_attr_show()requiresCAP_SYS_ADMIN. Reading them through a loop device works.- An unprivileged container that was handed a loop device can't change
gro_flush_timeoutof its own network devices asgro_flush_timeout_store()requiresCAP_NET_ADMINin 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.
Quoted 6 lines
Refuse files on pseudo filesystems as loop backing files. Note that
file_is_pseudo()looks through overlayfs so stacking overlayfs on top of
sysfs doesn't get around this.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 19 lines
---
drivers/block/loop.c | 3 +++1 file changed, 3 insertions(+)drivers/block/loop.c +0
-0@@ -537,6 +537,9 @@ static int loop_check_backing_file(struct file *file) if ((file->f_mode & FMODE_WRITE) && !file->f_op->write_iter) return -EINVAL;drivers/block/loop.c +3
-0+if (file_is_pseudo (file)) +return -EINVAL ; +return 0;
}
Christian Brauner
maintainerRFC PATCH 35/41 zloop: refuse zone files on pseudo filesystems
In reply to Christian Braunerzloop 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.
--- drivers/block/zloop.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/block/zloop.c +5 -0
@@ -1137,6 +1137,11 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, goto out_fput; } +if (file_is_pseudo (zone->file)) { + ret = -EINVAL ; + goto out_fput; + } +if (zlo->block_size) { ret =zloop_get_block_size (zlo, zone);if (ret)
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 35/41] zloop: refuse zone files on pseudo filesystems
Sashiko has reviewed this patch and found no issues.
Quoted 5 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.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=35
Re: [PATCH RFC 35/41] zloop: refuse zone files on pseudo filesystems
In reply to Christian BraunerQuoted 7 lines · 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.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 21 lines
---
drivers/block/zloop.c | 5 +++++1 file changed, 5 insertions(+)drivers/block/zloop.c +0
-0@@ -1137,6 +1137,11 @@ static int zloop_init_zone(struct zloop_device *zlo, struct zloop_options *opts, goto out_fput; }drivers/block/zloop.c +5
-0+if (file_is_pseudo (zone->file)) { + ret = -EINVAL ; + goto out_fput; + } +if (
zlo->block_size) {
ret =zloop_get_block_size(zlo, zone); if (ret)
Christian Brauner
maintainerRFC PATCH 36/41 nvmet: refuse files on pseudo filesystems as namespace backing files
In reply to Christian BraunerThe file backend takes any path that isn't a block device. 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.
--- drivers/nvme/target/io-cmd-file.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/nvme/target/io-cmd-file.c +5 -0
@@ -52,6 +52,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) goto err; } +if (file_is_pseudo (ns->file)) { + ret = -EINVAL ; + goto err; + } +nvmet_file_ns_revalidate (ns);/*
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 36/41] nvmet: refuse files on pseudo filesystems as namespace backing files
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines
The file backend takes any path that isn't a block device. 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.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=36
Re: [PATCH RFC 36/41] nvmet: refuse files on pseudo filesystems as namespace backing files
In reply to Christian BraunerQuoted 17 lines · Christian Brauner
The file backend takes any path that isn't a block device. 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.
Signed-off-by Christian Brauner (Amutable) <[email protected]>--- drivers/nvme/target/io-cmd-file.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/nvme/target/io-cmd-file.c +0
-0@@ -52,6 +52,11 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) goto err;
drivers/nvme/target/io-cmd-file.c int nvmet_file_ns_enable(struct nvmet_ns *ns) · line 62
Quoted 10 lines
drivers/nvme/target/io-cmd-file.c +5
-0} +if (file_is_pseudo (ns->file)) { + ret = -EINVAL ; + goto err; + } +nvmet_file_ns_revalidate (ns);/*
I noticed patch 41/41 doesn't include a test for nvmet. Would it make sense to add one with buffered_io=1? The test would need a pseudo file that can be opened with O_RDWR and supports both read_iter and write_iter. Otherwise, it could pass without ever reaching the new file_is_pseudo() check.
Thanks.
Christian Brauner
maintainerRFC PATCH 37/41 target: fileio: refuse files on pseudo filesystems as backing files
In reply to Christian Braunerfd_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.
--- drivers/target/target_core_file.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/target/target_core_file.c +7 -0
@@ -152,6 +152,13 @@ static int fd_configure_device(struct se_device *dev) goto fail; } +if (file_is_pseudo (file)) { +pr_err ("FILEIO: %s is on a pseudo filesystem\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
[email protected]
AI reviewRe: [PATCH RFC 37/41] target: fileio: refuse files on pseudo filesystems as backing files
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] target: fileio: missing file_is_pseudo() check in fd_init_prot() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] target: fileio: missing file_is_pseudo() check in fd_init_prot()
--
commit 4e15db58376b542897dd4203d7acdfd99df1aec4
Author: Christian Brauner <[email protected]>
target: fileio: refuse files on pseudo filesystems as backing files
This commit rejects files on pseudo filesystems in fd_configure_device() so that SCSI initiators cannot read or write kernel interfaces such as procfs or sysfs with kernel credentials.
Quoted 5 lines
drivers/target/target_core_file.c +0
-0
drivers/target/target_core_file.c static int fd_configure_device(struct se_device *dev) · line 160
Quoted 9 lines
drivers/target/target_core_file.c +6
-0@@ -152,6 +152,13 @@ static int fd_configure_device(struct se_device *dev) goto fail; } +if (file_is_pseudo (file)) { +pr_err ("FILEIO: %s is on a pseudo filesystem\n" , + fd_dev->fd_dev_name); + ret = -EINVAL ; + goto fail; + }
[Severity: Medium]
Should fd_init_prot() also check file_is_pseudo() (and ->read_iter / ->write_iter) when opening fd_dev->fd_prot_file?
When DIF protection is enabled via pi_prot_type_store(), fd_init_prot() opens "%s.protection" by pathname without these checks. If that path is a symlink or bind mount to a procfs or sysfs file, fd_execute_rw_buffered() -> fd_do_rw() will still read and write it with kernel worker credentials.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=37
Christian Brauner
maintainerRFC PATCH 38/41 fuse: refuse files on pseudo filesystems as passthrough backing files
In reply to Christian BraunerThe 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.
--- fs/fuse/backing.c | 3 +++ 1 file changed, 3 insertions(+)
fs/fuse/backing.c +3 -0
@@ -147,6 +147,9 @@ 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 ; +if (file_is_pseudo (file)) +return -EINVAL ; + fb->type =FUSE_BACKING_PATH ; fb->path = file->f_path;path_get (&fb->path);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 38/41] fuse: refuse files on pseudo filesystems as passthrough backing files
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
The fuse server can register any regular file as a backing file. procfs and
binfmt_miscfiles are already refused by the stacking depth check as both sets_stack_depthtoFILESYSTEM_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.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=38
Re: [PATCH RFC 38/41] fuse: refuse files on pseudo filesystems as passthrough backing files
In reply to Christian BraunerQuoted 30 lines · Christian Brauner
The fuse server can register any regular file as a backing file. procfs and
binfmt_miscfiles are already refused by the stacking depth check as both sets_stack_depthtoFILESYSTEM_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.Signed-off-by Christian Brauner (Amutable) <[email protected]>--- fs/fuse/backing.c | 3 +++ 1 file changed, 3 insertions(+)fs/fuse/backing.c +3
-0@@ -147,6 +147,9 @@ 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 ; +if (file_is_pseudo (file)) +return -EINVAL ; + fb->type =FUSE_BACKING_PATH ; fb->path = file->f_path;path_get (&fb->path);Signature · 2 lines
-- 2.53.0
Christoph Hellwig
maintainerRe: [PATCH RFC 38/41] fuse: refuse files on pseudo filesystems as passthrough backing files
In reply to Christian BraunerI've seen setups where people use fuse to mediate access to sysfs sysfs in odd ways. No idea if that's still around, but if so, this patch will break it.
Re: [PATCH RFC 38/41] fuse: refuse files on pseudo filesystems as passthrough backing files
Hi Christoph,
Quoted 3 lines · Christoph Hellwig
I've seen setups where people use fuse to mediate access to sysfs sysfs in odd ways. No idea if that's still around, but if so, this patch will break it.
Oh, that's painful. Do they use backing files for that? It's a relatively new feature in FUSE...
Kind regards,
Alex
Amir Goldstein
maintainerRe: [PATCH RFC 38/41] fuse: refuse files on pseudo filesystems as passthrough backing files
Quoted 11 lines · Alexander Mikhalitsyn
Hi Christoph,
Quoted 3 lines · Christoph Hellwig
I've seen setups where people use fuse to mediate access to sysfs sysfs in odd ways. No idea if that's still around, but if so, this patch will break it.
Oh, that's painful. Do they use backing files for that? It's a relatively new feature in FUSE...
Very unlikely that they use FUSE passthrough and if they did very unlikely that it would break their filesystem.
The API for fuse passthrough is that the server requests to setup a backing file before open via ioctl and if ioctl fails (as this patch does) then server falls back to non-passthrough open.
The ioctl can already fail for many reasons such as MAX_STACK_DEPTH on procfs as the commit message says, so server needs to cope with the fall back.
Thanks,
Amir.
Christian Brauner
maintainerRFC PATCH 39/41 usb: gadget: f_mass_storage: refuse files on pseudo filesystems
In reply to Christian Braunerfsg_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.
--- drivers/usb/gadget/function/storage_common.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/usb/gadget/function/storage_common.c +5 -0
@@ -211,6 +211,11 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename) goto out; } +if (file_is_pseudo (filp)) { +LINFO (curlun,"file on a pseudo filesystem: %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.
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 39/41] usb: gadget: f_mass_storage: refuse files on pseudo filesystems
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
fsg_lun_open()takes any regular file as the backing file of a LUN. The file-storage kthread then reads and writes it withkernel_read()andkernel_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.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=39
Re: [PATCH RFC 39/41] usb: gadget: f_mass_storage: refuse files on pseudo filesystems
In reply to Christian BraunerQuoted 9 lines · 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 withkernel_read()andkernel_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.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 23 lines
---
drivers/usb/gadget/function/storage_common.c | 5 +++++1 file changed, 5 insertions(+)drivers/usb/gadget/function/storage_common.c +0
-0@@ -211,6 +211,11 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename) goto out; }drivers/usb/gadget/function/storage_common.c +2
-0+if (file_is_pseudo (filp)) { + LINFO(curlun, "file on a pseudo filesystem: %s\n",filename);
drivers/usb/gadget/function/storage_common.c +3
-0+ goto out; + } +/*
* If we can't read the file, it's no good.
* If we can't write the file, use it read-only.
Christian Brauner
maintainerRFC PATCH 40/41 erofs: refuse files on pseudo filesystems as backing files
In reply to Christian BraunerFile-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.
--- fs/erofs/super.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/erofs/super.c +5 -1
@@ -158,7 +158,8 @@ 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 (!S_ISREG (file_inode (file)->i_mode) || +file_is_pseudo (file)) {fput (file);return -EINVAL ; }
@@ -835,6 +836,9 @@ static int erofs_file_get_tree(struct fs_context *fc) {struct erofs_sb_info *sbi = fc->s_fs_info; +if (file_is_pseudo (sbi->dif0.file)) +return invalfc (fc,"source is on a pseudo filesystem" ); +if (!test_opt (&sbi->opt,SUPERBLOCK_SHARE ))return get_tree_nodev (fc, erofs_fc_fill_super);
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 40/41] erofs: refuse files on pseudo filesystems as backing files
Sashiko has reviewed this patch and found no issues.
Quoted 7 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.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=40
Re: [PATCH RFC 40/41] erofs: refuse files on pseudo filesystems as backing files
In reply to Christian BraunerQuoted 7 lines · 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.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Thanks,
Gao Xiang
Re: [PATCH RFC 40/41] erofs: refuse files on pseudo filesystems as backing files
In reply to Christian BraunerQuoted 9 lines · 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.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 33 lines
---
fs/erofs/super.c | 6 +++++-1 file changed, 5 insertions(+), 1 deletion(-)fs/erofs/super.c +0
-0@@ -158,7 +158,8 @@ 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);fs/erofs/super.c +2
-1- }else if (!S_ISREG (file_inode (file)->i_mode)) { + }else if (!S_ISREG (file_inode (file)->i_mode) || + file_is_pseudo(file)) {fput(file);
return-EINVAL;
}fs/erofs/super.c +0
-0@@ -835,6 +836,9 @@ static int erofs_file_get_tree(struct fs_context *fc) { struct erofs_sb_info *sbi = fc->s_fs_info;fs/erofs/super.c +2
-0+if (file_is_pseudo (sbi->dif0.file)) + return invalfc(fc, "source is on a pseudofilesystem");
+
if (!test_opt(&sbi->opt,SUPERBLOCK_SHARE)) returnget_tree_nodev(fc, erofs_fc_fill_super);
Christian Brauner
maintainerRFC PATCH 41/41 selftests/filesystems: add backing file tests for pseudo files
In reply to Christian BraunerAdd 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 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
And make sure that a memfd and another loop device still work as loop backing files and that loop refuses a backing file that isn't open for reading.
--- tools/testing/selftests/filesystems/.gitignore | 1 + tools/testing/selftests/filesystems/Makefile | 2 +- tools/testing/selftests/filesystems/config | 9 + .../selftests/filesystems/pseudo_backing_test.c | 274 +++++++++++++++++++++ 4 files changed, 285 insertions(+), 1 deletion(-)
tools/testing/selftests/filesystems/.gitignore +1 -0
@@ -7,3 +7,4 @@ kernfs_test idmapped_tmpfile ustat_test rw_hint_test +pseudo_backing_test
tools/testing/selftests/filesystems/Makefile +1 -1
@@ -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 +9 -0
@@ -6,3 +6,12 @@ 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
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +274 -0
274 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH RFC 41/41] selftests/filesystems: add backing file tests for pseudo files
Sashiko has reviewed this patch and found no issues.
Quoted 8 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 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
Quoted 5 lines
And make sure that a memfd and another loop device still work as loop backing files and that loop refuses a backing file that isn't open for reading.
Signed-off-by Christian Brauner (Amutable) <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=41
Re: [PATCH RFC 41/41] selftests/filesystems: add backing file tests for pseudo files
In reply to Christian BraunerQuoted 9 lines · 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 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
Quoted 6 lines
And make sure that a memfd and another loop device still work as loop backing files and that loop refuses a backing file that isn't open for
reading.Signed-off-by Christian Brauner (Amutable) <[email protected]>
Quoted 350 lines
---
tools/testing/selftests/filesystems/.gitignore | 1 + tools/testing/selftests/filesystems/Makefile | 2 +- tools/testing/selftests/filesystems/config | 9 + .../selftests/filesystems/pseudo_backing_test.c | 274
+++++++++++++++++++++4 files changed, 285 insertions(+), 1 deletion(-)tools/testing/selftests/filesystems/.gitignore +0
-0@@ -7,3 +7,4 @@ kernfs_testidmapped_tmpfile
ustat_test
rw_hint_testtools/testing/selftests/filesystems/.gitignore +1
-0+pseudo_backing_testtools/testing/selftests/filesystems/Makefile +0
-0@@ -2,7 +2,7 @@
CFLAGS += $(KHDR_INCLUDES)
TEST_GEN_PROGS :=devpts_ptsanon_inode_testkernfs_testfclogustat_testrw_hint_testtools/testing/selftests/filesystems/Makefile +1
-1-TEST_GEN_PROGS += idmapped_tmpfile +TEST_GEN_PROGS += idmapped_tmpfile pseudo_backing_testTEST_GEN_PROGS_EXTENDED :=
dnotify_test
include../lib.mktools/testing/selftests/filesystems/config +0
-0@@ -6,3 +6,12 @@ CONFIG_NET=yCONFIG_NET_NS=y
CONFIG_INET=y
CONFIG_SYSFS=ytools/testing/selftests/filesystems/config +9
-0+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=ydiff --git
a/tools/testing/selftests/filesystems/pseudo_backing_test.cb/tools/testing/selftests/filesystems/pseudo_backing_test.cnew file mode 100644
index 000000000000..bc8e17ab8e6etools/testing/selftests/filesystems/pseudo_backing_test.c new file +80
-0@@ -0,0 +1,274 @@ +// SPDX-License-Identifier: GPL-2.0 +#define _GNU_SOURCE + +#include <errno.h> +#include <fcntl.h> +#include <limits.h> +#include <sched.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <linux/loop.h> +#include <linux/magic.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/mount.h> +#include <sys/stat.h> +#include <sys/vfs.h> + +#include "kselftest_harness.h" +#include "wrappers.h" + +/* +* Put @fd behind a free loop device. The device is set up with +* LO_FLAGS_AUTOCLEAR and goes away again when it is closed here. +*/ +static int loop_attach (int fd,bool rw,char *dev,size_t len) +{ +struct loop_config cfg = {}; +int ctl, nr, lfd, ret =0 ; + + ctl =open ("/dev/loop-control" ,O_RDWR |O_CLOEXEC ); +if (ctl <0 ) +return -errno; + nr =ioctl (ctl,LOOP_CTL_GET_FREE ); +if (nr <0 ) + ret = -errno; +close (ctl); +if (ret) +return ret; + +snprintf (dev, len,"/dev/loop%d" , nr); + lfd =open (dev, (rw ?O_RDWR :O_RDONLY ) |O_CLOEXEC ); +if (lfd <0 ) +return -errno; + + cfg.fd = fd; + cfg.info.lo_flags =LO_FLAGS_AUTOCLEAR ; +if (!rw) + cfg.info.lo_flags |=LO_FLAGS_READ_ONLY ; +if (ioctl (lfd,LOOP_CONFIGURE , &cfg)) { + ret = -errno; +close (lfd); + }else { + ret = lfd; + } +return ret; +} + +static int attach_path (const char *path,bool rw) +{ +char dev[PATH_MAX ]; +int fd, ret; + + fd =open (path, (rw ?O_RDWR :O_RDONLY ) |O_CLOEXEC ); +if (fd <0 ) +return -errno; + ret =loop_attach (fd, rw, dev,sizeof (dev)); +close (fd); +if (ret >=0 ) { +close (ret); + ret =0 ; + } +return ret; +} + +static bool can_use_loop (void ) +{ + return geteuid() == 0 && access("/dev/loop-control", R_OK |
W_OK) == 0;tools/testing/selftests/filesystems/pseudo_backing_test.c new file +59
-0+} + +TEST (memfd_backing_file) +{ +char dev[PATH_MAX ]; +int fd, lfd; + +if (!can_use_loop ()) +SKIP (return,"loop devices unavailable" ); + + fd =memfd_create ("pseudo_backing_test" ,MFD_CLOEXEC ); +ASSERT_GE (fd,0 ); +ASSERT_EQ (ftruncate (fd,1 <<20 ),0 ); + + lfd =loop_attach (fd, true, dev,sizeof (dev)); +ASSERT_GE (lfd,0 ); +EXPECT_EQ (close (lfd),0 ); +EXPECT_EQ (close (fd),0 ); +} + +TEST (loop_device_backing_file) +{ +char dev[PATH_MAX ], dev2[PATH_MAX ]; +int fd, lfd, bfd, lfd2; + +if (!can_use_loop ()) +SKIP (return,"loop devices unavailable" ); + + fd =memfd_create ("pseudo_backing_test" ,MFD_CLOEXEC ); +ASSERT_GE (fd,0 ); +ASSERT_EQ (ftruncate (fd,1 <<20 ),0 ); + lfd =loop_attach (fd, true, dev,sizeof (dev)); +ASSERT_GE (lfd,0 ); + +/* A block device stays fine as a backing file. */ + bfd =open (dev,O_RDWR |O_CLOEXEC ); +ASSERT_GE (bfd,0 ); + lfd2 =loop_attach (bfd, true, dev2,sizeof (dev2)); +ASSERT_GE (lfd2,0 ); + +EXPECT_EQ (close (lfd2),0 ); +EXPECT_EQ (close (bfd),0 ); +EXPECT_EQ (close (lfd),0 ); +EXPECT_EQ (close (fd),0 ); +} + +TEST (write_only_backing_file) +{ +char dev[PATH_MAX ], path[PATH_MAX ]; +int fd, wfd, lfd; + +if (!can_use_loop ()) +SKIP (return,"loop devices unavailable" ); + + fd =memfd_create ("pseudo_backing_test" ,MFD_CLOEXEC ); +ASSERT_GE (fd,0 ); +ASSERT_EQ (ftruncate (fd,1 <<20 ),0 ); + +/* Loop reads from its backing file so it must be open for reading. */
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +26
-0+snprintf (path,sizeof (path),"/proc/self/fd/%d" , fd); + wfd =open (path,O_WRONLY |O_CLOEXEC ); +ASSERT_GE (wfd,0 ); + + lfd =loop_attach (wfd, true, dev,sizeof (dev)); +if (lfd >=0 ) +close (lfd); +EXPECT_EQ (lfd, -EBADF ); +EXPECT_EQ (close (wfd),0 ); +EXPECT_EQ (close (fd),0 ); +} + +TEST (procfs_backing_file) +{ +if (!can_use_loop ()) +SKIP (return,"loop devices unavailable" ); + +ASSERT_EQ (attach_path ("/proc/cpuinfo" , false), -EINVAL ); +} + +TEST (sysfs_backing_file) +{ +if (!can_use_loop ()) +SKIP (return,"loop devices unavailable" ); + + ASSERT_EQ(attach_path("/sys/kernel/warn_count", false), -EINVAL);
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +4
-0+ +if (access ("/sys/kernel/reboot/mode" ,F_OK )) +SKIP (return,"no /sys/kernel/reboot/mode" ); + ASSERT_EQ(attach_path("/sys/kernel/reboot/mode", true), -EINVAL);
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +9
-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);
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +8
-0+ASSERT_EQ (mount ("tmpfs" ,"/tmp" ,"tmpfs" ,0 ,NULL ),0 ); +ASSERT_EQ (mkdir ("/tmp/empty" ,0755 ),0 ); +ASSERT_EQ (mkdir ("/tmp/merged" ,0755 ),0 ); + +/* A lower-only overlayfs serves reads from sysfs. */ +if (mount ("overlay" ,"/tmp/merged" ,"overlay" ,MS_RDONLY , + "lowerdir=/sys/kernel:/tmp/empty")) + SKIP(return, "no overlayfs on top of sysfs: %s",strerror(errno));
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +2
-0+ + ASSERT_EQ(attach_path("/tmp/merged/warn_count", false), -EINVAL);
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +18
-0+} + +#define CONFIGFS_DIR "/sys/kernel/config" +#define GADGET_DIR CONFIGFS_DIR "/usb_gadget/pseudo_backing_test" +#define MASS_STORAGE_DIR GADGET_DIR "/functions/mass_storage.0" + +TEST(usb_mass_storage_backing_file) +{ + const char *path = "/sys/kernel/warn_count"; + struct statfs sfs; + ssize_t ret; + int fd, err; + + if (geteuid()) + SKIP(return, "needs root"); + + /* Mounting configfs on top of itself fails with EBUSY. */ + if (statfs(CONFIGFS_DIR, &sfs) || sfs.f_type !=
CONFIGFS_MAGIC) {tools/testing/selftests/filesystems/pseudo_backing_test.c new file +2
-0+ASSERT_EQ (unshare (CLONE_NEWNS ),0 ); + ASSERT_EQ(mount(NULL, "/", NULL, MS_REC |
MS_PRIVATE, NULL), 0);tools/testing/selftests/filesystems/pseudo_backing_test.c new file +1
-0+ if (mount("configfs", CONFIGFS_DIR, "configfs", 0,NULL))
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +1
-0+ SKIP(return, "no configfs: %s",strerror(errno));
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +4
-0+ } + +if (mkdir (GADGET_DIR ,0755 )) + SKIP(return, "no usb gadget configfs: %s",strerror(errno));
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +4
-0+if (mkdir (MASS_STORAGE_DIR ,0755 )) { + err = errno; +rmdir (GADGET_DIR ); + SKIP(return, "no usb mass storage function: %s",strerror(err));
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +3
-0+ } + +/* Writing the path opens the LUN's backing file right away. */
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +1
-0+ fd = open(MASS_STORAGE_DIR "/lun.0/file", O_WRONLY |
O_CLOEXEC);tools/testing/selftests/filesystems/pseudo_backing_test.c new file +30
-0+EXPECT_GE (fd,0 ); +if (fd >=0 ) { + ret =write (fd, path,strlen (path)); + err = errno; +EXPECT_EQ (ret,-1 ); +EXPECT_EQ (err,EINVAL ); +EXPECT_EQ (close (fd),0 ); + } + +EXPECT_EQ (rmdir (MASS_STORAGE_DIR ),0 ); +EXPECT_EQ (rmdir (GADGET_DIR ),0 ); +} + +TEST (erofs_backing_file) +{ +bool refused = false; +char buf[256 ]; +int fsfd, ret, err; +ssize_t n; + +if (geteuid ()) +SKIP (return,"needs root" ); + + fsfd =sys_fsopen ("erofs" ,FSOPEN_CLOEXEC ); +if (fsfd <0 ) +SKIP (return,"no erofs: %s" ,strerror (errno)); + +ASSERT_EQ (sys_fsconfig (fsfd,FSCONFIG_SET_STRING ,"source" , + "/sys/kernel/warn_count", 0), 0); + ret = sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL,0);
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +10
-0+ err = errno; +if (ret && err ==ENOTBLK ) { +close (fsfd); +SKIP (return,"no file-backed erofs mounts" ); + } +ASSERT_EQ (ret,-1 ); +ASSERT_EQ (err,EINVAL ); + +/* +* Something that isn't an erofs image fails with EINVAL as well so
tools/testing/selftests/filesystems/pseudo_backing_test.c new file +12
-0+* check that the source itself was refused. +*/ +while ((n =read (fsfd, buf,sizeof (buf) -1 )) >0 ) { + buf[n] ='\0' ; +if (strstr (buf,"pseudo filesystem" )) + refused = true; + } +EXPECT_TRUE (refused); +EXPECT_EQ (close (fsfd),0 ); +} + +TEST_HARNESS_MAIN
Quoted 239 lines · Christian Brauner
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/kcoreattaches 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/enabledfor the loop device
and writing a block to the loop device changes the THP settingIt'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 thecapable()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 permittedBut put
hard_offline_pagebehind a loop device, write a block containing0x220689000to 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 at7f468e972000That
hard_offline_pageis 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()requiresCAP_SYS_ADMINfor every md attribute.(4) reconfigure scsi disks via
/sys/class/scsi_disk/*/allow_restartand
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_timeoutof its own network devices. That usually requiresCAP_NET_ADMINin 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.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 withbmap()which no pseudo filesystem implements.So this series adds
SB_I_PSEUDOto state that the regular files of a filesystem are kernel interfaces and not storage and makes all seven refuse such files.I didn't want to sprinkle
SB_I_PSEUDOover all pseudo filesystems one by
one. Instead there's now a common initialization point for all of them
viafc_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 raisesSB_I_PSEUDO,SB_I_NOEXECandSB_I_NODEV. Pseudo filesystems never hold executables or
device nodes. Some of them raisedSB_I_NOEXECandSB_I_NODEValready, 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 refusesVM_EXECanyway.
SB_I_NODEVis cleared again by devpts, binderfs and selinuxfs. The first
two did that already. selinuxfs needs it because Android init opens/sys/fs/selinux/nullby path as/dev/nulldoesn't exist yet at that point. Note that systemd mounts most of these filesystems with noexec and nodev already.
file_is_pseudo()looks atd_real_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
andbinfmt_miscare refused as they sets_stack_depthtoFILESYSTEM_MAX_STACK_DEPTH.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_PSEUDOoverlayfs
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 throughvfs_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.Signed-off-by Christian Brauner (Amutable) <[email protected]>---
Christian Brauner (41):
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 -Quoted 1 line
{read,write}_iter
fs: add
SB_I_PSEUDO
kernfs: usefc_init_pseudo()
proc: usefc_init_pseudo()
binfmt_misc: usefc_init_pseudo()
mqueue: usefc_init_pseudo()
bpf: usefc_init_pseudo()for bpffs
nullfs: usefc_init_pseudo()
failfs: usefc_init_pseudo()
rust_binderfs: usefc_init_pseudo()
devpts: usefc_init_pseudo()
debugfs: usefc_init_pseudo()
tracefs: usefc_init_pseudo()
configfs: usefc_init_pseudo()
securityfs: usefc_init_pseudo()
selinux: usefc_init_pseudo()for selinuxfs
smack: usefc_init_pseudo()for smackfs
apparmor: usefc_init_pseudo()for apparmorfs
nfsd: usefc_init_pseudo()
sunrpc: usefc_init_pseudo()forrpc_pipefs
fuse: usefc_init_pseudo()for fusectl
efivarfs: usefc_init_pseudo()
pstore: usefc_init_pseudo()
xenfs: usefc_init_pseudo()
openpromfs: usefc_init_pseudo()
ocfs2: usefc_init_pseudo()for dlmfs
s390/hypfs: usefc_init_pseudo()
powerpc/spufs: usefc_init_pseudo()
usb: gadget:f_fs: usefc_init_pseudo()
usb: gadget: gadgetfs: usefc_init_pseudo()
fs: addfile_is_pseudo()
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 selftests/filesystems: add backing file tests for pseudo filesarch/powerpc/platforms/cell/spufs/inode.c | 2 + arch/s390/hypfs/inode.c | 2 + drivers/android/binder/rust_binderfs.c | 3 +- drivers/block/loop.c | 6 + drivers/block/zloop.c | 5 + drivers/nvme/target/io-cmd-file.c | 10 + drivers/target/target_core_file.c | 15 ++ drivers/usb/gadget/function/f_fs.c | 2 + drivers/usb/gadget/function/storage_common.c | 5 + 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 | 6 +- fs/failfs.c | 3 +-
fs/fuse/backing.c | 3 + fs/fuse/control.c | 2 + 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/proc/root.c | 4 +- fs/pstore/inode.c | 2 + fs/tracefs/inode.c | 2 + include/linux/fs.h | 12 + include/linux/fs/super_types.h | 1 + include/linux/pseudo_fs.h | 11 + ipc/mqueue.c | 3 +- kernel/bpf/inode.c | 4 +- net/sunrpc/rpc_pipe.c | 2 + security/apparmor/apparmorfs.c | 2 + security/inode.c | 2 + 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 | 9 + .../selftests/filesystems/pseudo_backing_test.c | 274
+++++++++++++++++++++
Quoted 4 lines
43 files changed, 419 insertions(+), 15 deletions(-)---
base-commit:6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261109-work-loop-pseudo-890844168ef1
Hi Christian,
I think we should also cover acct(2) case with something like this:
kernel/acct.c +0 -1
@@ -245,11 +245,10 @@ 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)
+ if (file_is_pseudo(file))
return -EINVAL;
if (!(file->f_mode & FMODE_CAN_WRITE))