[PATCH 11/12] bpf: fs/xattr: take freeze protection in the xattr kfuncs
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Sat Nov 14 03:11:36 PST 2026
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] bpf: deadlock in bpf_set_dentry_xattr() via
bpf_lsm_inode_need_killpriv() [1]
--
commit 486e046b7935f74b8ef238345d31e9322cf39132
Author: Christian Brauner <brauner at kernel.org>
bpf: fs/xattr: take freeze protection in the xattr kfuncs
This commit takes superblock freeze protection via
sb_start_write_trylock() in bpf_set_dentry_xattr() and
bpf_remove_dentry_xattr() so that BPF LSM programs cannot modify a frozen
filesystem.
> diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c
> index 35ccd98a4de64..7f61e2efa08ba 100644
> --- a/fs/bpf_fs_kfuncs.c
> +++ b/fs/bpf_fs_kfuncs.c
> @@ -295,9 +295,13 @@ __bpf_kfunc int bpf_set_dentry_xattr(struct dentry *dentry, const char *name__st
> if (!inode)
> return -EINVAL;
>
> + /* The hook may hold locks or freeze protection already. */
> + if (!sb_start_write_trylock(inode->i_sb))
> + return -EBUSY;
> inode_lock(inode);
> ret = bpf_set_dentry_xattr_locked(dentry, name__str, value_p, flags);
> inode_unlock(inode);
> + sb_end_write(inode->i_sb);
> return ret;
> }
[Severity: High]
This problem wasn't introduced by this patch, but can calling
bpf_set_dentry_xattr() or bpf_remove_dentry_xattr() from
bpf_lsm_inode_need_killpriv() deadlock on inode_lock(inode) [1]?
During file writes, callers of file_remove_privs_flags() ->
dentry_needs_remove_privs() -> security_inode_need_killpriv() already hold
inode_lock(inode). Because bpf_lsm_inode_need_killpriv is missing from
d_inode_locked_hooks, the verifier routes xattr kfunc calls from that hook
to the unlocked variants instead of the _locked ones, causing the thread
to self-deadlock on inode->i_rwsem.
[1] https://sashiko.dev/#/bug/linux-8b38dfb7-78dd-457e-8674-7955f142df39
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261114-work-fs-frozen_writes-v1-0-f5ae61c898b1@kernel.org?part=11
More information about the Linux-nvme
mailing list