Linux EFI development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Jann Horn <jannh@google.com>, Chris Mason <mason@kernel.org>,
	 Josef Bacik <josef@toxicpanda.com>,
	Christoph Hellwig <hch@lst.de>,
	 linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-nvme@lists.infradead.org,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	 Jan Kara <jack@suse.cz>,
	linux-scsi@vger.kernel.org,  target-devel@vger.kernel.org,
	driver-core@lists.linux.dev,  linux-mm@kvack.org,
	bpf@vger.kernel.org,  linux-security-module@vger.kernel.org,
	selinux@vger.kernel.org,  apparmor@lists.ubuntu.com,
	linux-nfs@vger.kernel.org,  netdev@vger.kernel.org,
	fuse-devel@lists.linux.dev,  linux-efi@vger.kernel.org,
	xen-devel@lists.xenproject.org,  ocfs2-devel@lists.linux.dev,
	linux-s390@vger.kernel.org,  linuxppc-dev@lists.ozlabs.org,
	linux-usb@vger.kernel.org,  Amir Goldstein <amir73il@gmail.com>,
	linux-erofs@lists.ozlabs.org,  linux-kselftest@vger.kernel.org,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>,
	 Sashiko <sashiko-bot@kernel.org>
Subject: [PATCH RFC v2 37/42] target: fileio: refuse files on pseudo filesystems as backing files
Date: Sat, 14 Nov 2026 14:02:18 +0100	[thread overview]
Message-ID: <20261114-work-loop-pseudo-v2-37-98639a2286fb@kernel.org> (raw)
In-Reply-To: <20261114-work-loop-pseudo-v2-0-98639a2286fb@kernel.org>

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

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

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

Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/all/sashiko-outbox-206765@kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 drivers/target/target_core_file.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

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

-- 
2.53.0


  parent reply	other threads:[~2026-11-14 13:09 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 13:01 [PATCH RFC v2 00/42] fs: don't use pseudo filesystem files as storage Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 01/42] loop: refuse backing files that aren't open for reading Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 02/42] nvmet: check that the file backend supports ->{read,write}_iter Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 03/42] target: fileio: check that the backing file " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 04/42] fs: add SB_I_PSEUDO Christian Brauner
2026-11-14 13:54   ` bot+bpf-ci
2026-11-14 13:01 ` [PATCH RFC v2 05/42] kernfs: use fc_init_pseudo() Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 06/42] proc: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 07/42] binfmt_misc: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 08/42] mqueue: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 09/42] bpf: use fc_init_pseudo() for bpffs Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 10/42] nullfs: use fc_init_pseudo() Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 11/42] failfs: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 12/42] rust_binderfs: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 13/42] devpts: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 14/42] debugfs: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 15/42] tracefs: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 16/42] configfs: " Christian Brauner
2026-11-14 13:01 ` [PATCH RFC v2 17/42] securityfs: " Christian Brauner
2026-11-14 13:54   ` bot+bpf-ci
2026-11-14 13:01 ` [PATCH RFC v2 18/42] selinux: use fc_init_pseudo() for selinuxfs Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 19/42] smack: use fc_init_pseudo() for smackfs Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 20/42] apparmor: use fc_init_pseudo() for apparmorfs Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 21/42] nfsd: use fc_init_pseudo() Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 22/42] sunrpc: use fc_init_pseudo() for rpc_pipefs Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 23/42] fuse: use fc_init_pseudo() for fusectl Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 24/42] efivarfs: use fc_init_pseudo() Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 25/42] pstore: " Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 26/42] xenfs: " Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 27/42] openpromfs: " Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 28/42] ocfs2: use fc_init_pseudo() for dlmfs Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 29/42] s390/hypfs: use fc_init_pseudo() Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 30/42] powerpc/spufs: " Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 31/42] usb: gadget: f_fs: " Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 32/42] usb: gadget: gadgetfs: " Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 33/42] fs: add file_check_backing() Christian Brauner
2026-11-14 13:40   ` sashiko-bot
2026-11-14 13:55   ` bot+bpf-ci
2026-11-14 13:02 ` [PATCH RFC v2 34/42] loop: refuse files on pseudo filesystems as backing files Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 35/42] zloop: refuse zone files on pseudo filesystems Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 36/42] nvmet: refuse files on pseudo filesystems as namespace backing files Christian Brauner
2026-11-14 13:02 ` Christian Brauner [this message]
2026-11-14 13:02 ` [PATCH RFC v2 38/42] fuse: refuse files on pseudo filesystems as passthrough " Christian Brauner
2026-11-14 13:40   ` sashiko-bot
2026-11-14 13:02 ` [PATCH RFC v2 39/42] usb: gadget: f_mass_storage: refuse files on pseudo filesystems Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 40/42] erofs: refuse files on pseudo filesystems as backing files Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 41/42] acct: refuse files on pseudo filesystems Christian Brauner
2026-11-14 13:02 ` [PATCH RFC v2 42/42] selftests/filesystems: add backing file tests for pseudo files Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261114-work-loop-pseudo-v2-37-98639a2286fb@kernel.org \
    --to=brauner@kernel.org \
    --cc=amir73il@gmail.com \
    --cc=apparmor@lists.ubuntu.com \
    --cc=bpf@vger.kernel.org \
    --cc=driver-core@lists.linux.dev \
    --cc=fuse-devel@lists.linux.dev \
    --cc=hch@lst.de \
    --cc=jack@suse.cz \
    --cc=jannh@google.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-erofs@lists.ozlabs.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mason@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=ocfs2-devel@lists.linux.dev \
    --cc=sashiko-bot@kernel.org \
    --cc=selinux@vger.kernel.org \
    --cc=target-devel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox