[PATCH 11/12] bpf: fs/xattr: take freeze protection in the xattr kfuncs
Christian Brauner
brauner at kernel.org
Sat Nov 14 03:37:44 PST 2026
On Sat, Nov 14, 2026 at 11:11:36AM +0000, sashiko-bot at kernel.org wrote:
> 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]?
Yes, I've been pointing that out quite a few times already.
This needs bpf infrastructure changes to be able to automatically track
the locking context a function can be called from (or something
similar).
More information about the Linux-nvme
mailing list