From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796481593; b=ll+IaQuz5ELzohQhXNWG7dhhBdaedvf4/kmXfEcoatiHIF7OS/D94MVkCqpxCU7OzjFC GH+c8X4mYnvHvXGYO1EF1SbHEh9WaMsv754vejsk24/2aTHlueMm1wYCUTGRK3CH+G3iP uJCDZRHVBZAWRZG7NarK3UT3Jmudgs29Wg9L9d82TW1IDWzUxI0uNbVr5I0GBGRnjbpYp 0gaNpM9YdIGynTr7yy8oeebGVfKchVm/8SCiBD92hYNItu3iER2OOk6pMdm+m4bSGUgaV BZqPP4EHVIFM/4tGqcSm6XvbCV7r+24omgCuw65z5OzLHhbhaKMakPyK/M1vLO6V2UA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796481593; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=ooCe6YOpabAFRaYuJ+5qsDqgtL42BbAZ2l1qQWxmMC0=; b=CCgbIctvtwajbVw/1AkOnCl2ONtkiPn2zf7utiCZjBpt25uHoaiv8XMXF+OBbLtu7lg0 TxIo3jNemCSpnbZhWF2p2kY5gXQKIjpWSxE1kWz7gwlf7TccXxZvf9nTd95mD31tptZeA +X5aL8+mYk7zeFzExG8PQHA1ZY9MqjLH96QEwaqMNBaP2MhhBjx1GO+Ghh3frPOAPsfuC QBbkZud9agRHl/Op+6rMT/rhCJv4Q5Fu6RGRECpyRf25kKHNzhXDOLmrkRx2FO0+UnVvq 6Sk7MDLTiwA39s9mQb9myCP33D45Smdg922SrvWhq9oJgrZfmKBxVD21Q/4pNM27IOw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JErJhSED; arc=none smtp.remote-ip=209.85.128.52 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5208606A333 for ; Sat, 5 Dec 2026 14:39:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B5208606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=JErJhSED Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4a5177d78c7so18863755e9.2 for ; Sat, 05 Dec 2026 06:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796481591; x=1797086391; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=ooCe6YOpabAFRaYuJ+5qsDqgtL42BbAZ2l1qQWxmMC0=; b=JErJhSEDamuEycieVfIibb2ASYT+EjSTHCe3PtwqpLv44mOeft4aop/ZkVu6/khKra 7q2GFYDiOwvPO8owOio1ryKFcqQZ9jizSW8DXI6hEooqfxYDu4DS53jO1NJLudmQRlCn sylU5vzD+5L4ODd0hdCgCAH8SoGbOTmCEiLi+ezwfGFnqiq+mmEQNQRMpiwEo3F8mu9h SQgXCiisRMKcqH10Lr6zI+AvGZ9z7nczVZXhVvYck6B7HiveuHPwFWRhZeUJxBPkxYrK mkyfKM1sIjG3eeUFDs1hGLhexsrVm1hV3C00OqusEC2eLTjCrxspkbSs6DBDQHCsOGUK wB8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796481591; x=1797086391; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=ooCe6YOpabAFRaYuJ+5qsDqgtL42BbAZ2l1qQWxmMC0=; b=zrnTyCJxy5L3lPWlC6Yw9T7uInwp6lNJcmeKD8FIxVWmDUVN2qrBTNTT0cJk9NIlYw Th3c8U9sl2SNwdy49Op4NjSF/0p+esGXMNeJRk6Csh6O+uPx7Ti3wkACQuF6mNwett1W JhiA6tUT1dkMdVUGY931CTGDBj7xugarJm557AxTfghJpOW5gBNdODKCDYAtBmsEPn7V 0/gPi9cx9On3brTfWKSbIwfu9YmbxmOpI0OVHNyxqH+gqi4AxrWBmeFaQ7M5GqD8gPwm bZVdaFV4FeKJXE6sNABjs0HOHRTjIcJaCIVwF9xfxKIK08kzSBaPRqKJNihvn5tGH1pN NKOg== X-Forwarded-Encrypted: i=1; AL+hErGyhI2jal/KnrHFvev5lQ6zo2nR7fB42QmdZXa94q4I0R4mFdFH3ButqVLq5ktctm/aLsX+KIJD0J7KXH5RjDXI/W1X4+w=@vger.kernel.org X-Gm-Message-State: APuU4Z/rS+IsbqYjWKpU1EeXO6wq5fybY2njTqUKl0BbEMeuBy+ybuBc 6pYllGSUpuX6EqgjU/QdSw+U847+hMHxSMyHThpc66/vfcSq+3anr/ZH X-Gm-Gg: AZFdTZc8z4W2RRvQptueGboErzW5ETSbWTPUaSd9R0uIlJ64D6OYL4KuPgnlhwY2tuJ oQa/tNGGyWmG8KQ6y3RhXJ5ZC9JpGeZ56p+QCySt3JgnmbSYFpC1g8clpyb1LK985BmbrG1Jz5k 8j75ST7YdI/6wj9CCS5CWfqX0YaHkmbI2WBm42h3JcmZtxAI5azL9ej6sVgpSFyzYp39bvN3Y/X 7rOXwNC3VV+Yuy4oUH0BQX3I6gbHLziLmk0ooPyaGDuCX6YVhYj/fRJmUx/u4pAkr5Qkuk9Is9y 9IGlAENePCPbEnHuOYV/r2FwzOgxUDUDp5I7cmHQTXABtYIhFqwk9bq4wS3tJaYkzpeUqSX5pFW hTwtfQr3zqwx9SNEvtuGEY4LlTeUwmAjrdbZ/P/Bhl5FoBVeq0phALCgsMsHxH141mnTbWVYFLZ qtZ6kY21s8Dh1qJM7FNNHzGubiNoqtqYNNK8zUlCkgYVj2MOvRGDlY870Lb0wCajTbzoNaWz3Z3 ALKeLd7OC//jM8bvZvL+xU1z4OY+xRZFgCD/Xrad0yqkcLp7KmM1RspyCduCZFV+zM7qho5etu7 TG2d050jo6GXrOS+G5zAl6gUiLWBpQpSzuyzE0FsIYR3CYKj8Zs8wg8AgF3Iyoa+EMqn2kDsewD 6wKbmwZmAF39VIyO39neuRG1bYHo= X-Received: by 2002:a05:600c:3b04:b0:4bb:db77:2a5f with SMTP id 5b1f17b1804b1-4bbeb8bcf84mr95758405e9.28.1796481590894; Sat, 05 Dec 2026 06:39:50 -0800 (PST) Received: from andreayoga.localdomain (ftto-lindb29.fastnet.it. [195.96.196.30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea2a0484sm131732215e9.11.2026.12.05.06.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 06:39:50 -0800 (PST) From: Andrea Parri To: Alexander Viro , Christian Brauner , KP Singh , Matt Bobrowski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi Cc: Jan Kara , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Ihor Solodrai , Chuck Lever , Jeff Layton , Anton Protopopov , linux-fsdevel@vger.kernel.org, bpf@vger.kernel.org, linux-nfs@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [BUG] bpf: fs/xattr: bpf_set_dentry_xattr() hangs on path_link and on inode_getxattr from nfsd Date: Sat, 5 Dec 2026 15:39:43 +0100 Message-ID: <20261205143944.45754-1-parri.andrea@gmail.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 #include #include 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//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