Re: [PATCH 07/12] zloop: take freeze protection when recording write pointers
From: Christian Brauner
Date: Mon Nov 16 2026 - 04:42:13 EST
On Mon, Nov 16, 2026 at 07:48:20AM +0100, Christoph Hellwig wrote:
> Looks good:
>
> Reviewed-by: Christoph Hellwig <hch@xxxxxx>
>
> 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@xxxxxx
Suggested-by: Christoph Hellwig <hch@xxxxxx>
Signed-off-by: Christian Brauner (Amutable) <brauner@xxxxxxxxxx>
---
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;
--