mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Jan Kara <jack@suse.cz>, Shakeel Butt <shakeel.butt@linux.dev>,
	 Alexander Viro <viro@zeniv.linux.org.uk>,
	Jens Axboe <axboe@kernel.dk>,
	linux-fsdevel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	io-uring@vger.kernel.org, linux-block@vger.kernel.org,
	 linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org,
	target-devel@vger.kernel.org,  linux-unionfs@vger.kernel.org,
	bpf@vger.kernel.org, linux-nfs@vger.kernel.org,
	 stable@vger.kernel.org
Subject: Re: [PATCH 07/12] zloop: take freeze protection when recording write pointers
Date: Mon, 16 Nov 2026 10:41:49 +0100	[thread overview]
Message-ID: <20261116-biegen-flaute-flanke-cebddae97444@brauner> (raw)
In-Reply-To: <20261116064820.GB2964@lst.de>

On Mon, Nov 16, 2026 at 07:48:20AM +0100, Christoph Hellwig wrote:
> Looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> Can we get some kind of debug check into vfs_setxattr to enforce
> callers have taken the write protection?

I considered that and decided against it becuase it will mean everyone
starts splatting which means everyone needs to get their act together by
7.5.

You might not have seen it but I sent out a bunch of bug reports for
subsystems that suffer from the same bug class but that need way more
invasive fixes than anything I'm doing here.

But I guess we can do it if we use the VFS_* macros which are compiled
out unless CONFIG_DEBUG_FS is set. This will still mean that syzbot will
start splatting at these subsystems. If we're fine with that I'm good to
go with this.

Fwiw, the check can't go into __vfs_setxattr(), __vfs_setxattr_noperm()
or __vfs_removexattr(). cap_inode_killpriv(), IMA and EVM call those
from ->write_iter() via file_remove_privs() and kiocb_start_write()
hides the freeze protection from lockdep for aio and io_uring. I have
not bothered to figure out why. Maybe you already know? In any case,
until that's fixed we can't place it there which means this doesn't
catch IMA/EVM at which point this patch becomes pointless.

So that kiocb_start_write() stuff needs to be sorted first by someone.
I'm about 300+ patches or more deep into various tree-wide cleanups. I'm
going to defer this as this seems minor to all the other sh*it that's
waiting to be cleaned up.

-- >8 --
Subject: [PATCH] fs: assert freeze protection for xattr and acl writes

Writing an xattr or a POSIX ACL modifies the filesystem but
vfs_setxattr() and friends leave freeze protection to the caller. Most
callers get it from mnt_want_write(). Some in-kernel callers forgot
about it. zloop and overlayfs are fixed earlier in this series and
ecryptfs and ksmbd have been reported. Christoph asked for a debug check
to catch the next one (cf. [1]).

So warn in __vfs_setxattr_locked(), __vfs_removexattr_locked(),
vfs_set_acl(), vfs_remove_acl() and set_posix_acl() if SB_FREEZE_WRITE
isn't held. This only does something with CONFIG_DEBUG_VFS and lockdep.
Without lockdep sb_write_started() can't tell and claims it's held.
Until ecryptfs and ksmbd are fixed this will warn for them.

Note that __vfs_setxattr(), __vfs_setxattr_noperm() and
__vfs_removexattr() don't get the check. They're also called from
->write_iter() via file_remove_privs() -> notify_change() for
security.capability and by IMA and EVM. aio, io_uring and the in-kernel
async writers call kiocb_start_write() which hides the freeze protection
from lockdep before ->write_iter() is called. So the check would fire
for writes that are perfectly fine.

[1]: https://lore.kernel.org/r/20261116064820.GB2964@lst.de

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/posix_acl.c | 6 ++++++
 fs/xattr.c     | 4 ++++
 2 files changed, 10 insertions(+)

diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index fe77934ea8f20..61de6f105ff4f 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -942,6 +942,8 @@ set_posix_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
 {
 	struct inode *inode = d_inode(dentry);
 
+	VFS_WARN_ON_ONCE(!sb_write_started(inode->i_sb));
+
 	if (!IS_POSIXACL(inode))
 		return -EOPNOTSUPP;
 	if (!inode->i_op->set_acl)
@@ -1099,6 +1101,8 @@ int vfs_set_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
 	struct inode *inode = d_inode(dentry);
 	struct delegated_inode delegated_inode = { };
 
+	VFS_WARN_ON_ONCE(!sb_write_started(inode->i_sb));
+
 	acl_type = posix_acl_type(acl_name);
 	if (acl_type < 0)
 		return -EINVAL;
@@ -1220,6 +1224,8 @@ int vfs_remove_acl(const struct mnt_idmap *idmap, struct dentry *dentry,
 	struct inode *inode = d_inode(dentry);
 	struct delegated_inode delegated_inode = { };
 
+	VFS_WARN_ON_ONCE(!sb_write_started(inode->i_sb));
+
 	acl_type = posix_acl_type(acl_name);
 	if (acl_type < 0)
 		return -EINVAL;
diff --git a/fs/xattr.c b/fs/xattr.c
index 0705801a62cc5..715d04111c274 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -302,6 +302,8 @@ __vfs_setxattr_locked(const struct mnt_idmap *idmap, struct dentry *dentry,
 	struct inode *inode = dentry->d_inode;
 	int error;
 
+	VFS_WARN_ON_ONCE(!sb_write_started(inode->i_sb));
+
 	error = xattr_permission(idmap, inode, name, MAY_WRITE);
 	if (error)
 		return error;
@@ -564,6 +566,8 @@ __vfs_removexattr_locked(const struct mnt_idmap *idmap,
 	struct inode *inode = dentry->d_inode;
 	int error;
 
+	VFS_WARN_ON_ONCE(!sb_write_started(inode->i_sb));
+
 	error = xattr_permission(idmap, inode, name, MAY_WRITE);
 	if (error)
 		return error;

-- 

  reply	other threads:[~2026-11-16  9:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 10:47 [PATCH 00/12] fs: take freeze protection for writes to backing files Christian Brauner
2026-11-14 10:47 ` [PATCH 01/12] fs: add kiocb_start_write_trylock() Christian Brauner
2026-11-14 10:47 ` [PATCH 02/12] zloop: take freeze protection for writes Christian Brauner
2026-11-16  6:46   ` Christoph Hellwig
2026-11-14 10:47 ` [PATCH 03/12] nvmet: take freeze protection for writes to files Christian Brauner
2026-11-14 10:47 ` [PATCH 04/12] target: fileio: don't free the aio command under the filesystem Christian Brauner
2026-11-15  9:30   ` Christian Brauner
2026-11-14 10:47 ` [PATCH 05/12] target: fileio: take freeze protection for aio writes Christian Brauner
2026-11-14 10:47 ` [PATCH 06/12] loop: take freeze protection for discard and write zeroes Christian Brauner
2026-11-14 10:47 ` [PATCH 07/12] zloop: take freeze protection when recording write pointers Christian Brauner
2026-11-16  6:48   ` Christoph Hellwig
2026-11-16  9:41     ` Christian Brauner [this message]
2026-11-14 10:47 ` [PATCH 08/12] target: fileio: take freeze protection for unmap Christian Brauner
2026-11-14 10:47 ` [PATCH 09/12] coredump: take freeze protection for the truncate Christian Brauner
2026-11-14 10:47 ` [PATCH 10/12] ovl: take freeze protection when storing the uuid Christian Brauner
2026-11-14 12:19   ` Amir Goldstein
2026-11-14 10:47 ` [PATCH 11/12] bpf: fs/xattr: take freeze protection in the xattr kfuncs Christian Brauner
2026-11-14 10:47 ` [PATCH 12/12] nfsd: take freeze protection for the truncate on open Christian Brauner
2026-11-14 12:31 ` [PATCH 00/12] fs: take freeze protection for writes to backing files Amir Goldstein
2026-11-14 13:04   ` 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=20261116-biegen-flaute-flanke-cebddae97444@brauner \
    --to=brauner@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=bpf@vger.kernel.org \
    --cc=hch@lst.de \
    --cc=io-uring@vger.kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=shakeel.butt@linux.dev \
    --cc=stable@vger.kernel.org \
    --cc=target-devel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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

all inboxes | Powered by JetHome®