[BUG] bpf: fs/xattr: bpf_set_dentry_xattr() hangs on path_link and on inode_getxattr from nfsd

From: Andrea Parri

Date: Sat Dec 05 2026 - 09:40:02 EST


Hi,

On 7.4-rc5 and next-20261204 (x86_64), a sleepable BPF LSM program that
calls bpf_set_dentry_xattr() hangs the calling task in the two cases
below. Each case reproduced in 3 of 3 runs on each kernel, with the
program and commands at the end of this mail.

1. path_link, kfunc called on old_dentry

link("A", "A/x"), with A a directory, never returns. Run as uid 65534
with no capabilities and with fs.protected_hardlinks=1, the task stays
in D state, also after SIGKILL, with security_path_link() and
bpf_set_dentry_xattr() on its stack. Two tasks running link("A", "B/y")
and link("B", "A/x") in a loop both end up in D state with the same
stack. lockdep reported nothing in these runs.

2. inode_getxattr, from nfsd

getxattr() on a file of a loopback NFSv4.2 mount never returns. The
nfsd thread stays in D state, with nfsd_getxattr() and
bpf_set_dentry_xattr() on its stack, and lockdep reports recursive
locking. The same getxattr() on the file's local path, run in the same
VM before the export, returns ENODATA.

bpf_set_dentry_xattr() was added by commit 56467292794b ("bpf: fs/xattr:
Add BPF kfuncs to set and remove xattrs").

The bug was found with the help of an LLM, which was also used to write
this report and the reproducer.

Reproducer
==========

repro.bpf.c:

// SPDX-License-Identifier: GPL-2.0
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_tracing.h>

struct dentry {};
extern int bpf_set_dentry_xattr(struct dentry *dentry, const char *name__str,
const struct bpf_dynptr *value_p, int flags) __ksym;

char _license[] SEC("license") = "GPL";
char value[1] = "x";

static __always_inline void set_xattr(struct dentry *dentry)
{
struct bpf_dynptr ptr;

bpf_dynptr_from_mem(value, sizeof(value), 0, &ptr);
bpf_set_dentry_xattr(dentry, "security.bpf.x", &ptr, 0);
}

SEC("lsm.s/path_link")
int BPF_PROG(path_link, struct dentry *old_dentry)
{
set_xattr(old_dentry);
return 0;
}

SEC("lsm.s/inode_getxattr")
int BPF_PROG(inode_getxattr, struct dentry *dentry)
{
set_xattr(dentry);
return 0;
}

Build it as repro.bpf.o, from the kernel tree:

make -C tools/lib/bpf
clang -O2 -g --target=bpf -I tools/include/uapi -I tools/lib \
-c repro.bpf.c -o repro.bpf.o

Both kernels were built with virtme-ng; "bpf" is in the resulting
CONFIG_LSM:

vng --build --skip-modules \
--configitem CONFIG_BPF_SYSCALL=y --configitem CONFIG_BPF_JIT=y \
--configitem CONFIG_BPF_LSM=y --configitem CONFIG_SECURITY=y \
--configitem CONFIG_SECURITY_PATH=y \
--configitem CONFIG_DEBUG_INFO_DWARF5=y \
--configitem CONFIG_DEBUG_INFO_BTF=y \
--configitem CONFIG_FUNCTION_TRACER=y \
--configitem CONFIG_DYNAMIC_FTRACE=y \
--configitem CONFIG_PROVE_LOCKING=y --configitem CONFIG_STACKTRACE=y \
--configitem CONFIG_TMPFS_XATTR=y \
--configitem CONFIG_DETECT_HUNG_TASK=y \
--configitem CONFIG_NFS_FS=y --configitem CONFIG_NFS_V4=y \
--configitem CONFIG_NFS_V4_2=y --configitem CONFIG_NFSD=y \
--configitem CONFIG_NFSD_V4=y

Each case ran in a fresh VM, started with:

vng --run arch/x86/boot/bzImage --user root --cpus 2

The output below is from 7.4-rc5.

First, as root:

mount -t bpf bpf /sys/fs/bpf
bpftool prog loadall repro.bpf.o /sys/fs/bpf/repro autoattach
mount -t tmpfs -o mode=1777 none /mnt

Case 1; the link() call, made as an unprivileged user, never returns:

sysctl -w fs.protected_hardlinks=1
setpriv --reuid=65534 --regid=65534 --clear-groups \
python3 -c 'import os; os.mkdir("/mnt/A"); os.link("/mnt/A", "/mnt/A/x")'

The task is in D state, with /proc/<pid>/stack:

bpf_set_dentry_xattr+0x38/0x70
bpf_prog_5c3a9b6ead487187_path_link+0x55/0x5c
bpf_trampoline_6442529122+0x65/0xf9
security_path_link+0x39/0x60
filename_linkat+0x232/0x2c0
__x64_sys_linkat+0x55/0x80

The ABBA variant left two tasks with the same stack in each run:

mkdir /mnt/A /mnt/B
python3 -c '
import os
if os.fork(): a, b = "/mnt/A", "/mnt/B/y"
else: a, b = "/mnt/B", "/mnt/A/x"
while True:
try: os.link(a, b)
except OSError: pass'

Case 2 first reads the file locally; this getxattr() returns ENODATA:

echo x > /mnt/f
python3 -c 'import os; os.getxattr("/mnt/f", "user.x")'

It then exports /mnt over NFSv4.2 to 127.0.0.1 and mounts it on /srv.
The writes to /proc/net/rpc stand in for rpc.mountd:

mount -t nfsd nfsd /proc/fs/nfsd
echo "-3 +4 +4.1 +4.2" > /proc/fs/nfsd/versions
echo "tcp 2049" > /proc/fs/nfsd/portlist
echo 1 > /proc/fs/nfsd/threads
N=2147483647
echo "nfsd 127.0.0.1 $N d" > /proc/net/rpc/auth.unix.ip/channel
printf 'd 1 \\x00000000 %s /mnt\n' $N > /proc/net/rpc/nfsd.fh/channel
echo "d /mnt $N 9218 65534 65534 0" > /proc/net/rpc/nfsd.export/channel
mount -t nfs4 -o vers=4.2,addr=127.0.0.1 127.0.0.1:/ /srv
python3 -c 'import os; os.getxattr("/srv/f", "user.x")'

The getxattr() never returns, and the nfsd thread is in D state:

bpf_set_dentry_xattr+0x38/0x70
bpf_prog_5c3a9b6ead487187_inode_getxattr+0x55/0x5c
bpf_trampoline_6442529050+0x61/0xf9
security_inode_getxattr+0x34/0x60
vfs_getxattr+0x7f/0x150
nfsd_getxattr+0x7b/0x220
nfsd4_proc_compound+0x2f3/0x800

WARNING: possible recursive locking detected
nfsd/98 is trying to acquire lock:
(&sb->s_type->i_mutex_key#9){++++}-{4:4}, at: bpf_set_dentry_xattr+0x38/0x70
but task is already holding lock:
(&sb->s_type->i_mutex_key#9){++++}-{4:4}, at: nfsd_getxattr+0x64/0x220

Thanks,
Andrea