| 0/0 |
2026/05/16 04:07 |
flow |
assessment-security |
39m
Results: map[DenialOfService:true Explanation:**Bug Analysis:**
The bug report indicates a circular locking dependency (potential deadlock)
detected by lockdep. The dependency chain involves three lock classes:
1. `sk_lock-AF_INET6` (Socket lock)
2. `fs_reclaim` (Memory reclaim pseudo-lock)
3. `nsock->tx_lock` (NBD socket transmission lock)
**Trigger Mechanism:**
The deadlock scenario occurs as follows:
- **CPU 0:** A user process calls `tcp_recvmsg` on a socket, acquiring
`sk_lock`. During the receive operation, it faults on a user-space buffer
(`copy_to_user`), triggering memory allocation. Under memory pressure, this
enters direct memory reclaim (`fs_reclaim`), which submits a block I/O request
(bio) to an NBD (Network Block Device). The NBD driver then attempts to acquire
`nsock->tx_lock` to transmit the request.
- **CPU 1:** Concurrently, the NBD driver's receive worker thread (`recv_work`)
holds `nsock->tx_lock` and encounters an error or disconnect. It then calls
`nbd_mark_nsock_dead`, which attempts to acquire `sk_lock` to shut down the
socket.
This creates an AB-BA deadlock if both operations happen on the exact same
socket, or a lockdep warning (due to lock classes) if they happen on different
sockets. Syzkaller triggered this by passing a socket to the NBD driver and then
intentionally calling `recvmsg` on that same socket concurrently from user
space.
**Security Impact Assessment:**
* **Exploitable:** **No.** This is a circular locking dependency that results in
a thread deadlock (hang). It does not cause memory corruption, use-after-free,
or out-of-bounds accesses, and therefore cannot be exploited for privilege
escalation or arbitrary code execution.
* **Denial Of Service:** **Yes.** If successfully triggered, the involved
threads will deadlock, potentially hanging the NBD device and any processes
attempting to perform I/O on it or use the involved sockets.
* **Accessible From Unprivileged Processes & User Namespaces:** **No.** To
trigger this bug, an attacker must configure an NBD device and pass a socket to
it. Both the `ioctl` interface (`nbd_ioctl`) and the Netlink interface
(`nbd_genl_connect`) for configuring NBD strictly require `CAP_SYS_ADMIN` in the
initial user namespace (`init_user_ns`). Unprivileged users, even those who have
created a new user namespace, cannot bypass this check.
* **Other Triggers (VM Guest, Network, Peripheral, Filesystem):** **No.** The
bug is a local host-side issue requiring explicit configuration of an NBD device
via privileged administrative interfaces. It cannot be triggered remotely, by a
VM guest, or by plugging in a malicious device/filesystem.
**Conclusion:**
This is a local Denial of Service (deadlock) that is strictly limited to the
global root user (`CAP_SYS_ADMIN`). Since root already has full control over the
system and can cause a DoS through numerous legitimate means, this bug presents
no meaningful security boundary crossing or risk to production environments. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/16 04:07 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/05/16 04:07 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/a7966833164a791a1f7c3009b83c0bfc0425cdbf]
|
| 3/1 |
2026/05/16 04:07 |
action |
kernel-builder |
22m
Results: map[KernelObj:/app/workdir/cache/build/f5c0b1ca31ee8687100e00b3ab65ae92a5176eb5]
|
| 4/1 |
2026/05/16 04:30 |
action |
codesearch-prepare |
14m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/16 04:45 |
agent |
expert |
2m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction:
You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by greeping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Don't make assumptions; verify them with source code access. Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completly wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control tranfers, that's also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitabability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidetial Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
======================================================
WARNING: possible circular locking dependency detected
syzkaller #0 Not tainted
------------------------------------------------------
syz.5.1357/11580 is trying to acquire lock:
ffffffff8e9b0780 (fs_reclaim){+.+.}-{0:0}, at: might_alloc include/linux/sched/mm.h:317 [inline]
ffffffff8e9b0780 (fs_reclaim){+.+.}-{0:0}, at: prepare_alloc_pages+0x166/0x5f0 mm/page_alloc.c:4995
but task is already holding lock:
ffff88801b726e60 (sk_lock-AF_INET6){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1713 [inline]
ffff88801b726e60 (sk_lock-AF_INET6){+.+.}-{0:0}, at: tcp_recvmsg+0x11d/0x630 net/ipv4/tcp.c:2947
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #6 (sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x41/0xf0 net/core/sock.c:3783
lock_sock include/net/sock.h:1713 [inline]
inet_shutdown+0x67/0x410 net/ipv4/af_inet.c:915
nbd_mark_nsock_dead+0xae/0x5c0 drivers/block/nbd.c:318
recv_work+0x5fb/0x8c0 drivers/block/nbd.c:1021
process_one_work+0xa0e/0x1980 kernel/workqueue.c:3302
process_scheduled_works kernel/workqueue.c:3385 [inline]
worker_thread+0x5ef/0xe50 kernel/workqueue.c:3466
kthread+0x370/0x450 kernel/kthread.c:436
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
-> #5 (&nsock->tx_lock){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x1a4/0x1b10 kernel/locking/mutex.c:820
nbd_handle_cmd drivers/block/nbd.c:1143 [inline]
nbd_queue_rq+0x428/0x1080 drivers/block/nbd.c:1207
blk_mq_dispatch_rq_list+0x422/0x1e70 block/blk-mq.c:2148
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:168 [inline]
blk_mq_do_dispatch_sched block/blk-mq-sched.c:182 [inline]
__blk_mq_sched_dispatch_requests+0xcea/0x1620 block/blk-mq-sched.c:307
blk_mq_sched_dispatch_requests+0xd7/0x1c0 block/blk-mq-sched.c:329
blk_mq_run_hw_queue+0x23c/0x670 block/blk-mq.c:2386
blk_mq_dispatch_list+0x51d/0x1360 block/blk-mq.c:2949
blk_mq_flush_plug_list block/blk-mq.c:2997 [inline]
blk_mq_flush_plug_list+0x130/0x600 block/blk-mq.c:2969
__blk_flush_plug+0x2c4/0x4b0 block/blk-core.c:1230
blk_finish_plug block/blk-core.c:1257 [inline]
__submit_bio+0x584/0x6c0 block/blk-core.c:649
__submit_bio_noacct_mq block/blk-core.c:722 [inline]
submit_bio_noacct_nocheck+0x543/0xbf0 block/blk-core.c:753
submit_bio_noacct+0xd18/0x2000 block/blk-core.c:884
blk_crypto_submit_bio include/linux/blk-crypto.h:203 [inline]
submit_bh_wbc+0x681/0x890 fs/buffer.c:2737
submit_bh fs/buffer.c:2742 [inline]
block_read_full_folio+0x4c8/0x8e0 fs/buffer.c:2358
filemap_read_folio+0xfc/0x3b0 mm/filemap.c:2502
do_read_cache_folio+0x2d7/0x6b0 mm/filemap.c:4107
read_mapping_folio include/linux/pagemap.h:1017 [inline]
read_part_sector+0xd1/0x370 block/partitions/core.c:724
adfspart_check_ICS+0x91/0x7d0 block/partitions/acorn.c:356
check_partition block/partitions/core.c:143 [inline]
blk_add_partitions block/partitions/core.c:591 [inline]
bdev_disk_changed+0x7a3/0x1250 block/partitions/core.c:695
blkdev_get_whole+0x187/0x290 block/bdev.c:756
bdev_open+0x2c7/0xe40 block/bdev.c:965
blkdev_open+0x34e/0x4f0 block/fops.c:697
do_dentry_open+0x6d8/0x1660 fs/open.c:947
vfs_open+0x82/0x3f0 fs/open.c:1079
do_open fs/namei.c:4699 [inline]
path_openat+0x208c/0x31a0 fs/namei.c:4858
do_file_open+0x20e/0x430 fs/namei.c:4887
do_sys_openat2+0x10d/0x1e0 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x12d/0x210 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x10b/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #4 (&cmd->lock){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x1a4/0x1b10 kernel/locking/mutex.c:820
nbd_queue_rq+0xba/0x1080 drivers/block/nbd.c:1199
blk_mq_dispatch_rq_list+0x422/0x1e70 block/blk-mq.c:2148
__blk_mq_do_dispatch_sched block/blk-mq-sched.c:168 [inline]
blk_mq_do_dispatch_sched block/blk-mq-sched.c:182 [inline]
__blk_mq_sched_dispatch_requests+0xcea/0x1620 block/blk-mq-sched.c:307
blk_mq_sched_dispatch_requests+0xd7/0x1c0 block/blk-mq-sched.c:329
blk_mq_run_hw_queue+0x23c/0x670 block/blk-mq.c:2386
blk_mq_dispatch_list+0x51d/0x1360 block/blk-mq.c:2949
blk_mq_flush_plug_list block/blk-mq.c:2997 [inline]
blk_mq_flush_plug_list+0x130/0x600 block/blk-mq.c:2969
__blk_flush_plug+0x2c4/0x4b0 block/blk-core.c:1230
blk_finish_plug block/blk-core.c:1257 [inline]
__submit_bio+0x584/0x6c0 block/blk-core.c:649
__submit_bio_noacct_mq block/blk-core.c:722 [inline]
submit_bio_noacct_nocheck+0x543/0xbf0 block/blk-core.c:753
submit_bio_noacct+0xd18/0x2000 block/blk-core.c:884
blk_crypto_submit_bio include/linux/blk-crypto.h:203 [inline]
submit_bh_wbc+0x681/0x890 fs/buffer.c:2737
submit_bh fs/buffer.c:2742 [inline]
block_read_full_folio+0x4c8/0x8e0 fs/buffer.c:2358
filemap_read_folio+0xfc/0x3b0 mm/filemap.c:2502
do_read_cache_folio+0x2d7/0x6b0 mm/filemap.c:4107
read_mapping_folio include/linux/pagemap.h:1017 [inline]
read_part_sector+0xd1/0x370 block/partitions/core.c:724
adfspart_check_ICS+0x91/0x7d0 block/partitions/acorn.c:356
check_partition block/partitions/core.c:143 [inline]
blk_add_partitions block/partitions/core.c:591 [inline]
bdev_disk_changed+0x7a3/0x1250 block/partitions/core.c:695
blkdev_get_whole+0x187/0x290 block/bdev.c:756
bdev_open+0x2c7/0xe40 block/bdev.c:965
blkdev_open+0x34e/0x4f0 block/fops.c:697
do_dentry_open+0x6d8/0x1660 fs/open.c:947
vfs_open+0x82/0x3f0 fs/open.c:1079
do_open fs/namei.c:4699 [inline]
path_openat+0x208c/0x31a0 fs/namei.c:4858
do_file_open+0x20e/0x430 fs/namei.c:4887
do_sys_openat2+0x10d/0x1e0 fs/open.c:1364
do_sys_open fs/open.c:1370 [inline]
__do_sys_openat fs/open.c:1386 [inline]
__se_sys_openat fs/open.c:1381 [inline]
__x64_sys_openat+0x12d/0x210 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x10b/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #3 (set->srcu){.+.+}-{0:0}:
srcu_lock_sync include/linux/srcu.h:199 [inline]
__synchronize_srcu+0xa2/0x300 kernel/rcu/srcutree.c:1481
blk_mq_wait_quiesce_done block/blk-mq.c:284 [inline]
blk_mq_wait_quiesce_done block/blk-mq.c:281 [inline]
blk_mq_quiesce_queue block/blk-mq.c:304 [inline]
blk_mq_quiesce_queue+0x149/0x1c0 block/blk-mq.c:299
elevator_switch+0x17b/0x7e0 block/elevator.c:576
elevator_change+0x352/0x530 block/elevator.c:681
elevator_set_default+0x29e/0x360 block/elevator.c:754
blk_register_queue+0x48e/0x630 block/blk-sysfs.c:987
__add_disk+0x73f/0xe40 block/genhd.c:528
add_disk_fwnode+0x118/0x5c0 block/genhd.c:597
add_disk include/linux/blkdev.h:794 [inline]
nbd_dev_add+0x77a/0xb10 drivers/block/nbd.c:1984
nbd_init+0x291/0x2b0 drivers/block/nbd.c:2692
do_one_initcall+0x121/0x750 init/main.c:1392
do_initcall_level init/main.c:1454 [inline]
do_initcalls init/main.c:1470 [inline]
do_basic_setup init/main.c:1490 [inline]
kernel_init_freeable+0x6ea/0x7b0 init/main.c:1703
kernel_init+0x1f/0x1e0 init/main.c:1593
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
-> #2 (&q->elevator_lock){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x1a4/0x1b10 kernel/locking/mutex.c:820
elevator_change+0x1bc/0x530 block/elevator.c:679
elevator_set_none+0x92/0xf0 block/elevator.c:769
blk_mq_elv_switch_none block/blk-mq.c:5131 [inline]
__blk_mq_update_nr_hw_queues block/blk-mq.c:5176 [inline]
blk_mq_update_nr_hw_queues+0x4c1/0x15f0 block/blk-mq.c:5241
nbd_start_device+0x1a6/0xbd0 drivers/block/nbd.c:1489
nbd_genl_connect+0xff2/0x1a40 drivers/block/nbd.c:2239
genl_family_rcv_msg_doit+0x214/0x300 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0x560/0x800 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x159/0x420 net/netlink/af_netlink.c:2550
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0x585/0x850 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x8b0/0xda0 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:787 [inline]
__sock_sendmsg net/socket.c:802 [inline]
____sys_sendmsg+0x9e1/0xb70 net/socket.c:2698
___sys_sendmsg+0x190/0x1e0 net/socket.c:2752
__sys_sendmsg+0x170/0x220 net/socket.c:2784
do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
__do_fast_syscall_32+0xe7/0x950 arch/x86/entry/syscall_32.c:307
do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:332
entry_SYSENTER_compat_after_hwframe+0x84/0x8e
-> #1 (&q->q_usage_counter(io)#49){++++}-{0:0}:
blk_alloc_queue+0x610/0x790 block/blk-core.c:461
blk_mq_alloc_queue+0x174/0x290 block/blk-mq.c:4450
__blk_mq_alloc_disk+0x29/0x120 block/blk-mq.c:4497
nbd_dev_add+0x492/0xb10 drivers/block/nbd.c:1954
nbd_init+0x291/0x2b0 drivers/block/nbd.c:2692
do_one_initcall+0x121/0x750 init/main.c:1392
do_initcall_level init/main.c:1454 [inline]
do_initcalls init/main.c:1470 [inline]
do_basic_setup init/main.c:1490 [inline]
kernel_init_freeable+0x6ea/0x7b0 init/main.c:1703
kernel_init+0x1f/0x1e0 init/main.c:1593
ret_from_fork+0x72b/0xd50 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
-> #0 (fs_reclaim){+.+.}-{0:0}:
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x14b8/0x2630 kernel/locking/lockdep.c:5237
lock_acquire kernel/locking/lockdep.c:5868 [inline]
lock_acquire+0x1b1/0x370 kernel/locking/lockdep.c:5825
__fs_reclaim_acquire mm/page_alloc.c:4325 [inline]
fs_reclaim_acquire+0xc4/0x100 mm/page_alloc.c:4339
might_alloc include/linux/sched/mm.h:317 [inline]
prepare_alloc_pages+0x166/0x5f0 mm/page_alloc.c:4995
__alloc_frozen_pages_noprof+0x19a/0x2bc0 mm/page_alloc.c:5215
alloc_pages_mpol+0x1fb/0x540 mm/mempolicy.c:2490
folio_alloc_mpol_noprof+0x36/0x260 mm/mempolicy.c:2509
vma_alloc_folio_noprof+0xed/0x1d0 mm/mempolicy.c:2544
folio_prealloc mm/memory.c:1191 [inline]
alloc_anon_folio mm/memory.c:5282 [inline]
do_anonymous_page+0xb46/0x2050 mm/memory.c:5376
do_pte_missing mm/memory.c:4548 [inline]
handle_pte_fault mm/memory.c:6411 [inline]
__handle_mm_fault+0x1d2c/0x2a00 mm/memory.c:6549
handle_mm_fault+0x36d/0xa20 mm/memory.c:6718
do_user_addr_fault+0x74c/0x12f0 arch/x86/mm/fault.c:1385
handle_page_fault arch/x86/mm/fault.c:1474 [inline]
exc_page_fault+0x6f/0xd0 arch/x86/mm/fault.c:1527
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
copy_user_generic arch/x86/include/asm/uaccess_64.h:126 [inline]
raw_copy_to_user arch/x86/include/asm/uaccess_64.h:147 [inline]
copy_to_user_iter lib/iov_iter.c:25 [inline]
iterate_ubuf include/linux/iov_iter.h:30 [inline]
iterate_and_advance2 include/linux/iov_iter.h:302 [inline]
iterate_and_advance include/linux/iov_iter.h:330 [inline]
_copy_to_iter+0x38c/0x1720 lib/iov_iter.c:197
copy_to_iter include/linux/uio.h:220 [inline]
simple_copy_to_iter+0x46/0x90 net/core/datagram.c:521
__skb_datagram_iter+0x5c8/0x900 net/core/datagram.c:435
skb_copy_datagram_iter+0xa5/0x270 net/core/datagram.c:535
skb_copy_datagram_msg include/linux/skbuff.h:4243 [inline]
tcp_recvmsg_locked+0x1b74/0x2a20 net/ipv4/tcp.c:2844
tcp_recvmsg+0x141/0x630 net/ipv4/tcp.c:2948
inet6_recvmsg+0xd5/0x4c0 net/ipv6/af_inet6.c:657
sock_recvmsg_nosec net/socket.c:1137 [inline]
sock_recvmsg+0xfe/0x1f0 net/socket.c:1159
sock_read_iter+0x2c6/0x3c0 net/socket.c:1229
new_sync_read fs/read_write.c:493 [inline]
vfs_read+0x957/0xb30 fs/read_write.c:574
ksys_read+0x1f8/0x250 fs/read_write.c:717
do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
__do_fast_syscall_32+0xe7/0x950 arch/x86/entry/syscall_32.c:307
do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:332
entry_SYSENTER_compat_after_hwframe+0x84/0x8e
other info that might help us debug this:
Chain exists of:
fs_reclaim --> &nsock->tx_lock --> sk_lock-AF_INET6
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
lock(sk_lock-AF_INET6);
lock(&nsock->tx_lock);
lock(sk_lock-AF_INET6);
lock(fs_reclaim);
*** DEADLOCK ***
2 locks held by syz.5.1357/11580:
#0: ffff88801b726e60 (sk_lock-AF_INET6){+.+.}-{0:0}, at: lock_sock include/net/sock.h:1713 [inline]
#0: ffff88801b726e60 (sk_lock-AF_INET6){+.+.}-{0:0}, at: tcp_recvmsg+0x11d/0x630 net/ipv4/tcp.c:2947
#1: ffff8880137758f8 (&mm->mmap_lock){++++}-{4:4}, at: mmap_read_trylock include/linux/mmap_lock.h:611 [inline]
#1: ffff8880137758f8 (&mm->mmap_lock){++++}-{4:4}, at: get_mmap_lock_carefully mm/mmap_lock.c:441 [inline]
#1: ffff8880137758f8 (&mm->mmap_lock){++++}-{4:4}, at: lock_mm_and_find_vma+0x35/0x6f0 mm/mmap_lock.c:501
stack backtrace:
CPU: 1 UID: 0 PID: 11580 Comm: syz.5.1357 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_circular_bug.cold+0x178/0x1c7 kernel/locking/lockdep.c:2043
check_noncircular+0x146/0x160 kernel/locking/lockdep.c:2175
check_prev_add kernel/locking/lockdep.c:3165 [inline]
check_prevs_add kernel/locking/lockdep.c:3284 [inline]
validate_chain kernel/locking/lockdep.c:3908 [inline]
__lock_acquire+0x14b8/0x2630 kernel/locking/lockdep.c:5237
lock_acquire kernel/locking/lockdep.c:5868 [inline]
lock_acquire+0x1b1/0x370 kernel/locking/lockdep.c:5825
__fs_reclaim_acquire mm/page_alloc.c:4325 [inline]
fs_reclaim_acquire+0xc4/0x100 mm/page_alloc.c:4339
might_alloc include/linux/sched/mm.h:317 [inline]
prepare_alloc_pages+0x166/0x5f0 mm/page_alloc.c:4995
__alloc_frozen_pages_noprof+0x19a/0x2bc0 mm/page_alloc.c:5215
alloc_pages_mpol+0x1fb/0x540 mm/mempolicy.c:2490
folio_alloc_mpol_noprof+0x36/0x260 mm/mempolicy.c:2509
vma_alloc_folio_noprof+0xed/0x1d0 mm/mempolicy.c:2544
folio_prealloc mm/memory.c:1191 [inline]
alloc_anon_folio mm/memory.c:5282 [inline]
do_anonymous_page+0xb46/0x2050 mm/memory.c:5376
do_pte_missing mm/memory.c:4548 [inline]
handle_pte_fault mm/memory.c:6411 [inline]
__handle_mm_fault+0x1d2c/0x2a00 mm/memory.c:6549
handle_mm_fault+0x36d/0xa20 mm/memory.c:6718
do_user_addr_fault+0x74c/0x12f0 arch/x86/mm/fault.c:1385
handle_page_fault arch/x86/mm/fault.c:1474 [inline]
exc_page_fault+0x6f/0xd0 arch/x86/mm/fault.c:1527
asm_exc_page_fault+0x26/0x30 arch/x86/include/asm/idtentry.h:618
RIP: 0010:copy_user_generic arch/x86/include/asm/uaccess_64.h:126 [inline]
RIP: 0010:raw_copy_to_user arch/x86/include/asm/uaccess_64.h:147 [inline]
RIP: 0010:copy_to_user_iter lib/iov_iter.c:25 [inline]
RIP: 0010:iterate_ubuf include/linux/iov_iter.h:30 [inline]
RIP: 0010:iterate_and_advance2 include/linux/iov_iter.h:302 [inline]
RIP: 0010:iterate_and_advance include/linux/iov_iter.h:330 [inline]
RIP: 0010:_copy_to_iter+0x38c/0x1720 lib/iov_iter.c:197
Code: 00 00 00 00 e9 4d ff ff ff e8 e0 55 13 fd 4c 8b 74 24 18 44 89 fe 4c 89 f7 e8 a0 1e 80 fd 0f 01 cb 4c 89 f9 48 89 df 4c 89 f6 <f3> a4 0f 1f 00 48 89 cb 0f 01 ca 4c 89 f8 48 29 c8 48 89 44 24 08
RSP: 0018:ffffc90004ef7708 EFLAGS: 00050246
RAX: 0000000000000001 RBX: 00000000800075c0 RCX: 0000000000000002
RDX: 0000000000000001 RSI: ffff88804dbd8000 RDI: 00000000800075c0
RBP: ffffc90004ef7c38 R08: 0000000000000000 R09: ffffed1009b7b000
R10: ffff88804dbd8001 R11: 0000000000000000 R12: 00000000800075c2
R13: 00007ffffffff000 R14: ffff88804dbd8000 R15: 0000000000000002
copy_to_iter include/linux/uio.h:220 [inline]
simple_copy_to_iter+0x46/0x90 net/core/datagram.c:521
__skb_datagram_iter+0x5c8/0x900 net/core/datagram.c:435
skb_copy_datagram_iter+0xa5/0x270 net/core/datagram.c:535
skb_copy_datagram_msg include/linux/skbuff.h:4243 [inline]
tcp_recvmsg_locked+0x1b74/0x2a20 net/ipv4/tcp.c:2844
tcp_recvmsg+0x141/0x630 net/ipv4/tcp.c:2948
inet6_recvmsg+0xd5/0x4c0 net/ipv6/af_inet6.c:657
sock_recvmsg_nosec net/socket.c:1137 [inline]
sock_recvmsg+0xfe/0x1f0 net/socket.c:1159
sock_read_iter+0x2c6/0x3c0 net/socket.c:1229
new_sync_read fs/read_write.c:493 [inline]
vfs_read+0x957/0xb30 fs/read_write.c:574
ksys_read+0x1f8/0x250 fs/read_write.c:717
do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:83 [inline]
__do_fast_syscall_32+0xe7/0x950 arch/x86/entry/syscall_32.c:307
do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:332
entry_SYSENTER_compat_after_hwframe+0x84/0x8e
RIP: 0023:0xf6ffefcc
Code: d2 74 05 c1 e8 0c 89 02 8b 5d fc 31 c0 c9 c3 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 0f 1f 00 51 52 55 89 e5 0f 34 cd 80 <5d> 5a 59 c3 90 2e 8d b4 26 00 00 00 00 8d b4 26 00 00 00 00 58 b8
RSP: 002b:00000000f53ed50c EFLAGS: 00000292 ORIG_RAX: 0000000000000003
RAX: ffffffffffffffda RBX: 0000000000000005 RCX: 00000000800075c0
RDX: 0000000000002020 RSI: 0000000000000000 RDI: 0000000000000000
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000292 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
</TASK>
----------------
Code disassembly (best guess):
0: 00 00 add %al,(%rax)
2: 00 00 add %al,(%rax)
4: e9 4d ff ff ff jmp 0xffffff56
9: e8 e0 55 13 fd call 0xfd1355ee
e: 4c 8b 74 24 18 mov 0x18(%rsp),%r14
13: 44 89 fe mov %r15d,%esi
16: 4c 89 f7 mov %r14,%rdi
19: e8 a0 1e 80 fd call 0xfd801ebe
1e: 0f 01 cb stac
21: 4c 89 f9 mov %r15,%rcx
24: 48 89 df mov %rbx,%rdi
27: 4c 89 f6 mov %r14,%rsi
* 2a: f3 a4 rep movsb %ds:(%rsi),%es:(%rdi) <-- trapping instruction
2c: 0f 1f 00 nopl (%rax)
2f: 48 89 cb mov %rcx,%rbx
32: 0f 01 ca clac
35: 4c 89 f8 mov %r15,%rax
38: 48 29 c8 sub %rcx,%rax
3b: 48 89 44 24 08 mov %rax,0x8(%rsp)
Reply: **Bug Analysis:**
The bug report indicates a circular locking dependency (potential deadlock) detected by lockdep. The dependency chain involves three lock classes:
1. `sk_lock-AF_INET6` (Socket lock)
2. `fs_reclaim` (Memory reclaim pseudo-lock)
3. `nsock->tx_lock` (NBD socket transmission lock)
**Trigger Mechanism:**
The deadlock scenario occurs as follows:
- **CPU 0:** A user process calls `tcp_recvmsg` on a socket, acquiring `sk_lock`. During the receive operation, it faults on a user-space buffer (`copy_to_user`), triggering memory allocation. Under memory pressure, this enters direct memory reclaim (`fs_reclaim`), which submits a block I/O request (bio) to an NBD (Network Block Device). The NBD driver then attempts to acquire `nsock->tx_lock` to transmit the request.
- **CPU 1:** Concurrently, the NBD driver's receive worker thread (`recv_work`) holds `nsock->tx_lock` and encounters an error or disconnect. It then calls `nbd_mark_nsock_dead`, which attempts to acquire `sk_lock` to shut down the socket.
This creates an AB-BA deadlock if both operations happen on the exact same socket, or a lockdep warning (due to lock classes) if they happen on different sockets. Syzkaller triggered this by passing a socket to the NBD driver and then intentionally calling `recvmsg` on that same socket concurrently from user space.
**Security Impact Assessment:**
* **Exploitable:** **No.** This is a circular locking dependency that results in a thread deadlock (hang). It does not cause memory corruption, use-after-free, or out-of-bounds accesses, and therefore cannot be exploited for privilege escalation or arbitrary code execution.
* **Denial Of Service:** **Yes.** If successfully triggered, the involved threads will deadlock, potentially hanging the NBD device and any processes attempting to perform I/O on it or use the involved sockets.
* **Accessible From Unprivileged Processes & User Namespaces:** **No.** To trigger this bug, an attacker must configure an NBD device and pass a socket to it. Both the `ioctl` interface (`nbd_ioctl`) and the Netlink interface (`nbd_genl_connect`) for configuring NBD strictly require `CAP_SYS_ADMIN` in the initial user namespace (`init_user_ns`). Unprivileged users, even those who have created a new user namespace, cannot bypass this check.
* **Other Triggers (VM Guest, Network, Peripheral, Filesystem):** **No.** The bug is a local host-side issue requiring explicit configuration of an NBD device via privileged administrative interfaces. It cannot be triggered remotely, by a VM guest, or by plugging in a malicious device/filesystem.
**Conclusion:**
This is a local Denial of Service (deadlock) that is strictly limited to the global root user (`CAP_SYS_ADMIN`). Since root already has full control over the system and can cause a DoS through numerous legitimate means, this bug presents no meaningful security boundary crossing or risk to production environments.
|
| 6/2 |
2026/05/16 04:45 |
llm |
expert |
0m
Model:
Tokens:
input: 14554
output: 40
thoughts: 2279
Thoughts: **Analyzing a Circular Locking Dependency in the NBD Driver**
Okay, so I'm looking at this lockdep warning. It's screaming a potential deadlock scenario at me, specifically involving `fs_reclaim`, `nsock->tx_lock`, and `sk_lock-AF_INET6`. The report clearly shows a circular dependency. CPU0 seems to be acquiring `sk_lock-AF_INET6` while CPU1 has acquired `nsock->tx_lock` and then they try to acquire each other's locks in the wrong order, and deadlock.
Let me break down the chain. The call trace shows `tcp_recvmsg` eventually leads to `fs_reclaim`. It appears that `tcp_recvmsg` holds `sk_lock-AF_INET6` and then triggers a page fault (memory allocation). Now, this memory allocation can call into direct reclaim, which then can submit a bio. If the block device is NBD, we then call `nbd_queue_rq`. Critically, `nbd_queue_rq` acquires `nsock->tx_lock`.
On the other hand, the `nbd` driver's `recv_work` function eventually calls `inet_shutdown`, which requires `sk_lock-AF_INET6`. But `nbd`'s `nbd_queue_rq` is called from block layer, and block layer can be called during memory reclaim (`fs_reclaim`). This also means it acquires `nsock->tx_lock`. Hence the circular dependency: `fs_reclaim` -> `nsock->tx_lock` -> `sk_lock-AF_INET6` -> `fs_reclaim`.
Now, if one thread is doing `tcp_recvmsg`, it holds `sk_lock` and triggers a page fault that then does memory allocation. Direct reclaim can submit a block I/O that hits the NBD driver and attempts to acquire `nsock->tx_lock`. If at the same time, another thread, within the NBD driver's `recv_work`, tries to acquire `sk_lock`, it could cause a deadlock. Let me double check if `recv_work` holds `nsock->tx_lock`, specifically in `nbd_mark_nsock_dead`. Okay, no, `recv_work` does not hold `nsock->tx_lock` when calling `nbd_mark_nsock_dead` so there isn't a problem here.
Let's look at `drivers/block/nbd.c`, and check how `recv_work` works.
|
| 7/2 |
2026/05/16 04:45 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:recv_work]
Results: map[SourceCode: 970: static void recv_work(struct work_struct *work)
971: {
972: struct recv_thread_args *args = container_of(work,
973: struct recv_thread_args,
974: work);
975: struct nbd_device *nbd = args->nbd;
976: struct nbd_config *config = nbd->config;
977: struct request_queue *q = nbd->disk->queue;
978: struct nbd_sock *nsock = args->nsock;
979: struct nbd_cmd *cmd;
980: struct request *rq;
981:
982: while (1) {
983: struct nbd_reply reply;
984:
985: if (nbd_read_reply(nbd, nsock->sock, &reply))
986: break;
987:
988: /*
989: * Grab .q_usage_counter so request pool won't go away, then no
990: * request use-after-free is possible during nbd_handle_reply().
991: * If queue is frozen, there won't be any inflight requests, we
992: * needn't to handle the incoming garbage message.
993: */
994: if (!percpu_ref_tryget(&q->q_usage_counter)) {
995: dev_err(disk_to_dev(nbd->disk), "%s: no io inflight\n",
996: __func__);
997: break;
998: }
999:
1000: cmd = nbd_handle_reply(nbd, args->index, &reply);
1001: if (IS_ERR(cmd)) {
1002: percpu_ref_put(&q->q_usage_counter);
1003: break;
1004: }
1005:
1006: rq = blk_mq_rq_from_pdu(cmd);
1007: if (likely(!blk_should_fake_timeout(rq->q))) {
1008: bool complete;
1009:
1010: mutex_lock(&cmd->lock);
1011: complete = __test_and_clear_bit(NBD_CMD_INFLIGHT,
1012: &cmd->flags);
1013: mutex_unlock(&cmd->lock);
1014: if (complete)
1015: blk_mq_complete_request(rq);
1016: }
1017: percpu_ref_put(&q->q_usage_counter);
1018: }
1019:
1020: mutex_lock(&nsock->tx_lock);
1021: nbd_mark_nsock_dead(nbd, nsock, 1);
1022: mutex_unlock(&nsock->tx_lock);
1023:
1024: atomic_dec(&config->recv_threads);
1025: wake_up(&config->recv_wq);
1026: nbd_config_put(nbd);
1027: kfree(args);
1028: }
SourceFile:drivers/block/nbd.c]
|
| 8/2 |
2026/05/16 04:45 |
llm |
expert |
0m
Model:
Tokens:
input: 18361
output: 43
thoughts: 180
Thoughts: **Analyzing a Potential Locking Issue**
Okay, so I'm digging into this `recv_work` function, and it looks like it *definitely* holds `nsock->tx_lock` when it calls `nbd_mark_nsock_dead`. Specifically, right here, on lines 1020-1022: I see the `mutex_lock` and `mutex_unlock` calls bracketing `nbd_mark_nsock_dead`.
```c
mutex_lock(&nsock->tx_lock);
nbd_mark_nsock_dead(nbd, nsock, 1);
mutex_unlock(&nsock->tx_lock);
```
Now, the crucial bit... `nbd_mark_nsock_dead` then calls `kernel_sock_shutdown`, which, as I recall from my previous work with sockets, *acquires* the `sk_lock`. This means we have a lock ordering issue: `nsock->tx_lock` is acquired *before* `sk_lock`.
That alone is a red flag. I remember that the `nbd_queue_rq` function *also* acquires `nsock->tx_lock`, and from memory, it may acquire it under `fs_reclaim`, which can be a tricky context for locking. This is something I have to examine more closely.
So now, let me just check the exact call stack of `nbd_queue_rq` to see if my assumption holds.
|
| 9/2 |
2026/05/16 04:45 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_queue_rq]
Results: map[SourceCode:1184: static blk_status_t nbd_queue_rq(struct blk_mq_hw_ctx *hctx,
1185: const struct blk_mq_queue_data *bd)
1186: {
1187: struct nbd_cmd *cmd = blk_mq_rq_to_pdu(bd->rq);
1188: blk_status_t ret;
1189:
1190: /*
1191: * Since we look at the bio's to send the request over the network we
1192: * need to make sure the completion work doesn't mark this request done
1193: * before we are done doing our send. This keeps us from dereferencing
1194: * freed data if we have particularly fast completions (ie we get the
1195: * completion before we exit sock_xmit on the last bvec) or in the case
1196: * that the server is misbehaving (or there was an error) before we're
1197: * done sending everything over the wire.
1198: */
1199: mutex_lock(&cmd->lock);
1200: clear_bit(NBD_CMD_REQUEUED, &cmd->flags);
1201:
1202: /* We can be called directly from the user space process, which means we
1203: * could possibly have signals pending so our sendmsg will fail. In
1204: * this case we need to return that we are busy, otherwise error out as
1205: * appropriate.
1206: */
1207: ret = nbd_handle_cmd(cmd, hctx->queue_num);
1208: mutex_unlock(&cmd->lock);
1209:
1210: return ret;
1211: }
SourceFile:drivers/block/nbd.c]
|
| 10/2 |
2026/05/16 04:45 |
llm |
expert |
0m
Model:
Tokens:
input: 19426
output: 43
thoughts: 28
Thoughts: Here's my understanding of the situation, phrased as if I were thinking it through:
**Analyzing the NBD Command Handling Flow**
Okay, so I'm looking at how the Network Block Device (NBD) commands are processed. Specifically, I'm tracing the execution flow from the moment a command hits the system. I see that `nbd_handle_cmd` is the key function in play here. It's the one responsible for... well, handling the actual command. This makes sense.
And, following the code further, I note something important: `nbd_handle_cmd` then calls `nbd_send_cmd`. Right, that's expected - after handling the command, we need to *send* it to its destination or, at least, make the necessary preparation.
Now, here's where the critical bit comes in. I see that within `nbd_send_cmd`, a specific lock is acquired: `nsock->tx_lock`. So, the transmission path has a serialized mechanism. This lock suggests that `nbd_send_cmd` handles the transmission of the command data, and that this data-path is protected against concurrent operations, which makes good sense. We're most likely dealing with a shared resource on the network, like a socket, and the lock is there to ensure that transmissions don't collide or get interleaved in a way that would corrupt the data. Okay, got it. This looks like a fairly standard, thread-safe approach.
|
| 11/2 |
2026/05/16 04:45 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_handle_cmd]
Results: map[SourceCode:1117: static blk_status_t nbd_handle_cmd(struct nbd_cmd *cmd, int index)
1118: {
1119: struct request *req = blk_mq_rq_from_pdu(cmd);
1120: struct nbd_device *nbd = cmd->nbd;
1121: struct nbd_config *config;
1122: struct nbd_sock *nsock;
1123: blk_status_t ret;
1124:
1125: lockdep_assert_held(&cmd->lock);
1126:
1127: config = nbd_get_config_unlocked(nbd);
1128: if (!config) {
1129: dev_err_ratelimited(disk_to_dev(nbd->disk),
1130: "Socks array is empty\n");
1131: return BLK_STS_IOERR;
1132: }
1133:
1134: if (index >= config->num_connections) {
1135: dev_err_ratelimited(disk_to_dev(nbd->disk),
1136: "Attempted send on invalid socket\n");
1137: nbd_config_put(nbd);
1138: return BLK_STS_IOERR;
1139: }
1140: cmd->status = BLK_STS_OK;
1141: again:
1142: nsock = config->socks[index];
1143: mutex_lock(&nsock->tx_lock);
1144: if (nsock->dead) {
1145: int old_index = index;
1146: index = find_fallback(nbd, index);
1147: mutex_unlock(&nsock->tx_lock);
1148: if (index < 0) {
1149: if (wait_for_reconnect(nbd)) {
1150: index = old_index;
1151: goto again;
1152: }
1153: /* All the sockets should already be down at this point,
1154: * we just want to make sure that DISCONNECTED is set so
1155: * any requests that come in that were queue'ed waiting
1156: * for the reconnect timer don't trigger the timer again
1157: * and instead just error out.
1158: */
1159: sock_shutdown(nbd);
1160: nbd_config_put(nbd);
1161: return BLK_STS_IOERR;
1162: }
1163: goto again;
1164: }
1165:
1166: /* Handle the case that we have a pending request that was partially
1167: * transmitted that _has_ to be serviced first. We need to call requeue
1168: * here so that it gets put _after_ the request that is already on the
1169: * dispatch list.
1170: */
1171: blk_mq_start_request(req);
1172: if (unlikely(nsock->pending && nsock->pending != req)) {
1173: nbd_requeue_cmd(cmd);
1174: ret = BLK_STS_OK;
1175: goto out;
1176: }
1177: ret = nbd_send_cmd(nbd, cmd, index);
1178: out:
1179: mutex_unlock(&nsock->tx_lock);
1180: nbd_config_put(nbd);
1181: return ret;
1182: }
SourceFile:drivers/block/nbd.c]
|
| 12/2 |
2026/05/16 04:45 |
llm |
expert |
0m
Model:
Tokens:
input: 20858
output: 43
thoughts: 1019
Thoughts: **Analyzing a Potential Deadlock in the NBD Driver**
Okay, let's break this down. It looks like we've got a potential lock order reversal issue lurking in the NBD driver. First, `nbd_handle_cmd` acquires `nsock->tx_lock`. So that's the starting point. That means we have the following potential lock acquisition sequence: `fs_reclaim` -> `nsock->tx_lock` is possible. Then, `nsock->tx_lock` -> `sk_lock` is possible through `recv_work`. Finally, we can go from `sk_lock` -> `fs_reclaim` in `tcp_recvmsg` during `copy_to_user` because that could fault and trigger memory allocation.
So, is this a real deadlock situation? Let's trace it through a hypothetical scenario. CPU0 is running `tcp_recvmsg`, meaning it's holding `sk_lock`. Then, a fault occurs during allocation and the code enters direct reclaim. Direct reclaim then has to submit a bio to the NBD device. This calls `nbd_queue_rq`, which *tries* to get `nsock->tx_lock`.
Now, if CPU1 is running `recv_work`, it could acquire `nsock->tx_lock` and then call `nbd_mark_nsock_dead`, which then *tries* to get `sk_lock`.
This looks like the classic AB-BA deadlock: CPU0 is holding `sk_lock` and waiting for `nsock->tx_lock`, while CPU1 is holding `nsock->tx_lock` and waiting for `sk_lock`.
But is this the same socket? If `tcp_recvmsg` is called on the same socket that NBD is using, that's not right. The NBD socket is usually used within the kernel to send/receive data, and user space shouldn't be concurrently calling `tcp_recvmsg` on it, unless there's a bug or malicious intent.
Wait, can a user space process retain a file descriptor to the socket after giving it to NBD via `ioctl(NBD_SET_SOCK)`? Yes, it can. If the user space process *then* calls `recvmsg` on that socket, it gets `sk_lock`. Then there is a fault. Direct memory reclaim is triggered. Then a bio is submitted to an NBD device.
Crucially, can this memory reclaim submit a bio to *the same* NBD device? Yes, it's possible under memory pressure. Direct reclaim can submit bios to *any* block device, including the NBD device. If that happens, then `nbd_queue_rq` will try to acquire `nsock->tx_lock` for the same socket.
Meanwhile, `recv_work` for the *same* NBD device could be running, holding `nsock->tx_lock` and waiting to get `sk_lock` to shut down the socket.
Deadlock!
Wait, even if it's NOT the same socket, lockdep tracks locks by *class*. `sk_lock-AF_INET6` is a class, and `nsock->tx_lock` is another. If CPU0 holds `sk_lock` for socket A and waits for `nsock->tx_lock` for NBD B. And CPU1 holds `nsock->tx_lock` for NBD B, and waits for `sk_lock` for socket B, it's a deadlock if socket A and socket B are the same, or if we have a cycle.
Let's rethink this. CPU0 has lock A, waits for lock B. CPU1 has lock B, and waits for lock C. Unless lock A and lock C are the same *instance*, there's no deadlock. But lockdep warns about the *classes*.
So, is it possible for socket A and socket B to be the SAME socket? Yes, if the user process calls `recvmsg` on the NBD socket, and then the direct reclaim submits a bio to the *same* NBD device.
Now, how can we trigger direct reclaim that submits a bio to the same NBD device? If the NBD device is used for swap, or if it has a filesystem mounted and the memory being reclaimed is from that filesystem.
Wait, doesn't NBD set `memalloc_noio` or something similar? We need to verify if NBD sockets have `sk_allocation` set to `GFP_NOIO`, or if NBD sets `PF_MEMALLOC_NOIO`. We should check this in `nbd_set_size` or `nbd_add_socket`.
|
| 13/2 |
2026/05/16 04:45 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_add_socket]
Results: map[SourceCode:1241: static int nbd_add_socket(struct nbd_device *nbd, unsigned long arg,
1242: bool netlink)
1243: {
1244: struct nbd_config *config = nbd->config;
1245: struct socket *sock;
1246: struct nbd_sock **socks;
1247: struct nbd_sock *nsock;
1248: unsigned int memflags;
1249: int err;
1250:
1251: /* Arg will be cast to int, check it to avoid overflow */
1252: if (arg > INT_MAX)
1253: return -EINVAL;
1254: sock = nbd_get_socket(nbd, arg, &err);
1255: if (!sock)
1256: return err;
1257:
1258: /*
1259: * We need to make sure we don't get any errant requests while we're
1260: * reallocating the ->socks array.
1261: */
1262: memflags = blk_mq_freeze_queue(nbd->disk->queue);
1263:
1264: if (!netlink && !nbd->task_setup &&
1265: !test_bit(NBD_RT_BOUND, &config->runtime_flags))
1266: nbd->task_setup = current;
1267:
1268: if (!netlink &&
1269: (nbd->task_setup != current ||
1270: test_bit(NBD_RT_BOUND, &config->runtime_flags))) {
1271: dev_err(disk_to_dev(nbd->disk),
1272: "Device being setup by another task");
1273: err = -EBUSY;
1274: goto put_socket;
1275: }
1276:
1277: nsock = kzalloc_obj(*nsock);
1278: if (!nsock) {
1279: err = -ENOMEM;
1280: goto put_socket;
1281: }
1282:
1283: socks = krealloc(config->socks, (config->num_connections + 1) *
1284: sizeof(struct nbd_sock *), GFP_KERNEL);
1285: if (!socks) {
1286: kfree(nsock);
1287: err = -ENOMEM;
1288: goto put_socket;
1289: }
1290:
1291: config->socks = socks;
1292:
1293: nsock->fallback_index = -1;
1294: nsock->dead = false;
1295: mutex_init(&nsock->tx_lock);
1296: nsock->sock = sock;
1297: nsock->pending = NULL;
1298: nsock->sent = 0;
1299: nsock->cookie = 0;
1300: INIT_WORK(&nsock->work, nbd_pending_cmd_work);
1301: socks[config->num_connections++] = nsock;
1302: atomic_inc(&config->live_connections);
1303: blk_mq_unfreeze_queue(nbd->disk->queue, memflags);
1304:
1305: return 0;
1306:
1307: put_socket:
1308: blk_mq_unfreeze_queue(nbd->disk->queue, memflags);
1309: sockfd_put(sock);
1310: return err;
1311: }
SourceFile:drivers/block/nbd.c]
|
| 14/2 |
2026/05/16 04:45 |
llm |
expert |
0m
Model:
Tokens:
input: 23990
output: 43
thoughts: 48
Thoughts: Okay, let me think this through...
**Analyzing Socket Allocation in the NBD Driver**
Hmm, so I'm focusing on the Network Block Device, specifically how socket memory is handled. The current assumption is that `nbd_add_socket` should be setting the socket's memory allocation flags. Now I'm remembering that it doesn't. That feels...off. We've likely talked about this before, but I'm not currently seeing a `GFP_NOIO` setting there.
Wait a minute, where *is* this memory allocation controlled? Is this something that's handled in `nbd_set_size` or during `nbd_start_device`? That's probably where I should be looking for the actual memory management related to the sockets. I need to trace this control flow through those functions. Okay, that's the next step; figure out when and how that allocation flag is set.
|
| 15/2 |
2026/05/16 04:45 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_start_device]
Results: map[SourceCode:1471: static int nbd_start_device(struct nbd_device *nbd)
1472: {
1473: struct nbd_config *config = nbd->config;
1474: int num_connections = config->num_connections;
1475: int error = 0, i;
1476:
1477: if (nbd->pid)
1478: return -EBUSY;
1479: if (!config->socks)
1480: return -EINVAL;
1481: if (num_connections > 1 &&
1482: !(config->flags & NBD_FLAG_CAN_MULTI_CONN)) {
1483: dev_err(disk_to_dev(nbd->disk), "server does not support multiple connections per device.\n");
1484: return -EINVAL;
1485: }
1486:
1487: retry:
1488: mutex_unlock(&nbd->config_lock);
1489: blk_mq_update_nr_hw_queues(&nbd->tag_set, num_connections);
1490: mutex_lock(&nbd->config_lock);
1491:
1492: /* if another code path updated nr_hw_queues, retry until succeed */
1493: if (num_connections != config->num_connections) {
1494: num_connections = config->num_connections;
1495: goto retry;
1496: }
1497:
1498: nbd->pid = task_pid_nr(current);
1499:
1500: nbd_parse_flags(nbd);
1501:
1502: error = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
1503: if (error) {
1504: dev_err(disk_to_dev(nbd->disk), "device_create_file failed for pid!\n");
1505: return error;
1506: }
1507: set_bit(NBD_RT_HAS_PID_FILE, &config->runtime_flags);
1508:
1509: nbd_dev_dbg_init(nbd);
1510: for (i = 0; i < num_connections; i++) {
1511: struct recv_thread_args *args;
1512:
1513: args = kzalloc_obj(*args);
1514: if (!args) {
1515: sock_shutdown(nbd);
1516: /*
1517: * If num_connections is m (2 < m),
1518: * and NO.1 ~ NO.n(1 < n < m) kzallocs are successful.
1519: * But NO.(n + 1) failed. We still have n recv threads.
1520: * So, add flush_workqueue here to prevent recv threads
1521: * dropping the last config_refs and trying to destroy
1522: * the workqueue from inside the workqueue.
1523: */
1524: if (i)
1525: flush_workqueue(nbd->recv_workq);
1526: return -ENOMEM;
1527: }
1528: sk_set_memalloc(config->socks[i]->sock->sk);
1529: if (nbd->tag_set.timeout)
1530: config->socks[i]->sock->sk->sk_sndtimeo =
1531: nbd->tag_set.timeout;
1532: atomic_inc(&config->recv_threads);
1533: refcount_inc(&nbd->config_refs);
1534: INIT_WORK(&args->work, recv_work);
1535: args->nbd = nbd;
1536: args->nsock = config->socks[i];
1537: args->index = i;
1538: queue_work(nbd->recv_workq, &args->work);
1539: }
1540: return nbd_set_size(nbd, config->bytesize, nbd_blksize(config));
1541: }
SourceFile:drivers/block/nbd.c]
|
| 16/2 |
2026/05/16 04:45 |
llm |
expert |
0m
Model:
Tokens:
input: 25465
output: 41
thoughts: 267
Thoughts: **My Analysis of a Potential Deadlock**
Okay, so I see `sk_set_memalloc(config->socks[i]->sock->sk);` being called. Right, that sets `SOCK_MEMALLOC` on the socket. This means we're dealing with a socket used for swapping or similar operations, and any memory allocations for it will utilize those `PF_MEMALLOC` reserves. This sparks a concern in my head, specifically, does the call to `sk_set_memalloc` potentially interfere with how `fs_reclaim` interacts with `tcp_recvmsg`?
If a user process calls `tcp_recvmsg` on this socket, it's still going to trigger page faults on the user's buffer, which should lead to `fs_reclaim` being invoked. However, let's consider the NBD socket in particular. When a user calls `tcp_recvmsg` on the NBD socket, it grabs `sk_lock`. Then, a fault occurs, and `fs_reclaim` is entered. `fs_reclaim` subsequently submits a bio to the NBD device. Now, the NBD device calls `nbd_queue_rq`, which tries to acquire `nsock->tx_lock`. *That* is where the potential deadlock lies!
The pieces are all falling into place. `tcp_recvmsg` holding `sk_lock`, then calling `fs_reclaim`, which attempts to interact with NBD and potentially gets blocked on `nsock->tx_lock`. Bingo! This looks like a classic resource ordering issue.
Now, a crucial question arises: is this exploitable? Is it possible for an unprivileged user to actually trigger this condition? NBD configuration usually requires `CAP_SYS_ADMIN`, but I'd better be sure. Let's dig into the `nbd_ioctl` function and see what's actually needed.
|
| 17/2 |
2026/05/16 04:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_ioctl]
Results: map[SourceCode:1640: static int nbd_ioctl(struct block_device *bdev, blk_mode_t mode,
1641: unsigned int cmd, unsigned long arg)
1642: {
1643: struct nbd_device *nbd = bdev->bd_disk->private_data;
1644: struct nbd_config *config = nbd->config;
1645: int error = -EINVAL;
1646:
1647: if (!capable(CAP_SYS_ADMIN))
1648: return -EPERM;
1649:
1650: /* The block layer will pass back some non-nbd ioctls in case we have
1651: * special handling for them, but we don't so just return an error.
1652: */
1653: if (_IOC_TYPE(cmd) != 0xab)
1654: return -EINVAL;
1655:
1656: mutex_lock(&nbd->config_lock);
1657:
1658: /* Don't allow ioctl operations on a nbd device that was created with
1659: * netlink, unless it's DISCONNECT or CLEAR_SOCK, which are fine.
1660: */
1661: if (!test_bit(NBD_RT_BOUND, &config->runtime_flags) ||
1662: (cmd == NBD_DISCONNECT || cmd == NBD_CLEAR_SOCK))
1663: error = __nbd_ioctl(bdev, nbd, cmd, arg);
1664: else
1665: dev_err(nbd_to_dev(nbd), "Cannot use ioctl interface on a netlink controlled device.\n");
1666: mutex_unlock(&nbd->config_lock);
1667: return error;
1668: }
SourceFile:drivers/block/nbd.c]
|
| 18/2 |
2026/05/16 04:46 |
llm |
expert |
0m
Model:
Tokens:
input: 26707
output: 44
thoughts: 30
Thoughts: Okay, here's my interpretation of those thoughts, framed as my own, given my expertise:
**Exploring NBD Security and Alternative Control Mechanisms**
Alright, so I'm thinking about the security implications of `nbd_ioctl` and the fact that it needs `CAP_SYS_ADMIN`. That's a pretty broad permission, and frankly, it makes me a little uneasy. Granting that capability is a significant security risk, especially in environments where network block devices are used dynamically or by less-trusted processes. We need to be careful with that.
My next thought is, can we bypass this requirement? Can we implement an alternative method to communicate with the NBD server that doesn't necessitate such a powerful capability? The obvious candidate that springs to mind is Netlink. We *should* be looking at `nbd_genl_connect` and the possibilities it offers. Perhaps we can craft a more granular and controlled interface using Netlink, allowing us to manage NBD connections and operations without needing the blunt instrument of `CAP_SYS_ADMIN`. It might require more work, but it would be a much more elegant and secure approach in the long run. The trade-off is worth investigating.
|
| 19/2 |
2026/05/16 04:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_genl_connect]
Results: map[SourceCode:2073: static int nbd_genl_connect(struct sk_buff *skb, struct genl_info *info)
2074: {
2075: struct nbd_device *nbd;
2076: struct nbd_config *config;
2077: int index = -1;
2078: int ret;
2079: bool put_dev = false;
2080:
2081: if (!netlink_capable(skb, CAP_SYS_ADMIN))
2082: return -EPERM;
2083:
2084: if (info->attrs[NBD_ATTR_INDEX]) {
2085: index = nla_get_u32(info->attrs[NBD_ATTR_INDEX]);
2086:
2087: /*
2088: * Too big first_minor can cause duplicate creation of
2089: * sysfs files/links, since index << part_shift might overflow, or
2090: * MKDEV() expect that the max bits of first_minor is 20.
2091: */
2092: if (index < 0 || index > MINORMASK >> part_shift) {
2093: pr_err("illegal input index %d\n", index);
2094: return -EINVAL;
2095: }
2096: }
2097: if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_SOCKETS)) {
2098: pr_err("must specify at least one socket\n");
2099: return -EINVAL;
2100: }
2101: if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_SIZE_BYTES)) {
2102: pr_err("must specify a size in bytes for the device\n");
2103: return -EINVAL;
2104: }
2105: again:
2106: mutex_lock(&nbd_index_mutex);
2107: if (index == -1) {
2108: nbd = nbd_find_get_unused();
2109: } else {
2110: nbd = idr_find(&nbd_index_idr, index);
2111: if (nbd) {
2112: if ((test_bit(NBD_DESTROY_ON_DISCONNECT, &nbd->flags) &&
2113: test_bit(NBD_DISCONNECT_REQUESTED, &nbd->flags)) ||
2114: !refcount_inc_not_zero(&nbd->refs)) {
2115: mutex_unlock(&nbd_index_mutex);
2116: pr_err("device at index %d is going down\n",
2117: index);
2118: return -EINVAL;
2119: }
2120: }
2121: }
2122: mutex_unlock(&nbd_index_mutex);
2123:
2124: if (!nbd) {
2125: nbd = nbd_dev_add(index, 2);
2126: if (IS_ERR(nbd)) {
2127: pr_err("failed to add new device\n");
2128: return PTR_ERR(nbd);
2129: }
2130: }
2131:
2132: mutex_lock(&nbd->config_lock);
2133: if (refcount_read(&nbd->config_refs)) {
2134: mutex_unlock(&nbd->config_lock);
2135: nbd_put(nbd);
2136: if (index == -1)
2137: goto again;
2138: pr_err("nbd%d already in use\n", index);
2139: return -EBUSY;
2140: }
2141:
2142: ret = nbd_alloc_and_init_config(nbd);
2143: if (ret) {
2144: mutex_unlock(&nbd->config_lock);
2145: nbd_put(nbd);
2146: pr_err("couldn't allocate config\n");
2147: return ret;
2148: }
2149:
2150: config = nbd->config;
2151: set_bit(NBD_RT_BOUND, &config->runtime_flags);
2152: ret = nbd_genl_size_set(info, nbd);
2153: if (ret)
2154: goto out;
2155:
2156: if (info->attrs[NBD_ATTR_TIMEOUT])
2157: nbd_set_cmd_timeout(nbd,
2158: nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]));
2159: if (info->attrs[NBD_ATTR_DEAD_CONN_TIMEOUT]) {
2160: config->dead_conn_timeout =
2161: nla_get_u64(info->attrs[NBD_ATTR_DEAD_CONN_TIMEOUT]);
2162: config->dead_conn_timeout *= HZ;
2163: }
2164: if (info->attrs[NBD_ATTR_SERVER_FLAGS])
2165: config->flags =
2166: nla_get_u64(info->attrs[NBD_ATTR_SERVER_FLAGS]);
2167: if (info->attrs[NBD_ATTR_CLIENT_FLAGS]) {
2168: u64 flags = nla_get_u64(info->attrs[NBD_ATTR_CLIENT_FLAGS]);
2169: if (flags & NBD_CFLAG_DESTROY_ON_DISCONNECT) {
2170: /*
2171: * We have 1 ref to keep the device around, and then 1
2172: * ref for our current operation here, which will be
2173: * inherited by the config. If we already have
2174: * DESTROY_ON_DISCONNECT set then we know we don't have
2175: * that extra ref already held so we don't need the
2176: * put_dev.
2177: */
2178: if (!test_and_set_bit(NBD_DESTROY_ON_DISCONNECT,
2179: &nbd->flags))
2180: put_dev = true;
2181: } else {
2182: if (test_and_clear_bit(NBD_DESTROY_ON_DISCONNECT,
2183: &nbd->flags))
2184: refcount_inc(&nbd->refs);
2185: }
2186: if (flags & NBD_CFLAG_DISCONNECT_ON_CLOSE) {
2187: set_bit(NBD_RT_DISCONNECT_ON_CLOSE,
2188: &config->runtime_flags);
2189: }
2190: }
2191:
2192: if (info->attrs[NBD_ATTR_SOCKETS]) {
2193: struct nlattr *attr;
2194: int rem, fd;
2195:
2196: nla_for_each_nested(attr, info->attrs[NBD_ATTR_SOCKETS],
2197: rem) {
2198: struct nlattr *socks[NBD_SOCK_MAX+1];
2199:
2200: if (nla_type(attr) != NBD_SOCK_ITEM) {
2201: pr_err("socks must be embedded in a SOCK_ITEM attr\n");
2202: ret = -EINVAL;
2203: goto out;
2204: }
2205: ret = nla_parse_nested_deprecated(socks, NBD_SOCK_MAX,
2206: attr,
2207: nbd_sock_policy,
2208: info->extack);
2209: if (ret != 0) {
2210: pr_err("error processing sock list\n");
2211: ret = -EINVAL;
2212: goto out;
2213: }
2214: if (!socks[NBD_SOCK_FD])
2215: continue;
2216: fd = (int)nla_get_u32(socks[NBD_SOCK_FD]);
2217: ret = nbd_add_socket(nbd, fd, true);
2218: if (ret)
2219: goto out;
2220: }
2221: }
2222:
2223: if (info->attrs[NBD_ATTR_BACKEND_IDENTIFIER]) {
2224: nbd->backend = nla_strdup(info->attrs[NBD_ATTR_BACKEND_IDENTIFIER],
2225: GFP_KERNEL);
2226: if (!nbd->backend) {
2227: ret = -ENOMEM;
2228: goto out;
2229: }
2230: }
2231: ret = device_create_file(disk_to_dev(nbd->disk), &backend_attr);
2232: if (ret) {
2233: dev_err(disk_to_dev(nbd->disk),
2234: "device_create_file failed for backend!\n");
2235: goto out;
2236: }
2237: set_bit(NBD_RT_HAS_BACKEND_FILE, &config->runtime_flags);
2238:
2239: ret = nbd_start_device(nbd);
2240: out:
2241: if (!ret) {
2242: set_bit(NBD_RT_HAS_CONFIG_REF, &config->runtime_flags);
2243: refcount_inc(&nbd->config_refs);
2244: nbd_connect_reply(info, nbd->index);
2245: }
2246: mutex_unlock(&nbd->config_lock);
2247:
2248: nbd_config_put(nbd);
2249: if (put_dev)
2250: nbd_put(nbd);
2251: return ret;
2252: }
SourceFile:drivers/block/nbd.c]
|
| 20/2 |
2026/05/16 04:46 |
llm |
expert |
0m
Model:
Tokens:
input: 29919
output: 44
thoughts: 193
Thoughts: **My Analysis of NBD and Namespace Capabilities**
Okay, so I'm looking at `nbd_genl_connect`, and it seems like setting up an NBD device *requires* `CAP_SYS_ADMIN`, checked via `netlink_capable(skb, CAP_SYS_ADMIN)`. That makes sense; these things tend to need high-level privileges. My initial thought is that this requirement gets enforced in the initial user namespace, since `netlink_capable` typically checks the socket's namespace, which is usually `init_net`. But wait... let me double-check the code. Ah, right, `netlink_capable` isn't *quite* that simple. It checks the *user* namespace associated with the network namespace of the netlink socket, using `ns_capable(sock_net(skb->sk)->user_ns, cap)`. So it's the user namespace, not the init namespace per se.
This has interesting implications if NBD is registered within a network namespace. Because if NBD is registered within a network namespace, it might be possible to access it somehow. However, NBD is, fundamentally, a block device, and block devices are, historically at least, not network namespace aware.
Therefore, it looks like the next step is to examine whether the NBD netlink family is registered per netns. This would clarify precisely how this connectivity functions in terms of the network namespaces.
|
| 21/2 |
2026/05/16 04:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_genl_family]
Results: map[SourceCode:2476: static struct genl_family nbd_genl_family __ro_after_init = {
2477: .hdrsize = 0,
2478: .name = NBD_GENL_FAMILY_NAME,
2479: .version = NBD_GENL_VERSION,
2480: .module = THIS_MODULE,
2481: .small_ops = nbd_connect_genl_ops,
2482: .n_small_ops = ARRAY_SIZE(nbd_connect_genl_ops),
2483: .resv_start_op = NBD_CMD_STATUS + 1,
2484: .maxattr = NBD_ATTR_MAX,
2485: .netnsok = 1,
2486: .policy = nbd_attr_policy,
2487: .mcgrps = nbd_mcast_grps,
2488: .n_mcgrps = ARRAY_SIZE(nbd_mcast_grps),
2489: };
SourceFile:drivers/block/nbd.c]
|
| 22/2 |
2026/05/16 04:46 |
llm |
expert |
0m
Model:
Tokens:
input: 30778
output: 41
thoughts: 87
Thoughts: **Netlink Family Access in Non-Init Namespaces**
Okay, so I'm seeing `.netnsok = 1` - that's interesting! That tells me the netlink family is accessible even in network namespaces that aren't the initial namespace. Right, so if someone crafts a setup where they have a new user namespace *and* a new network namespace, they'll automatically have `CAP_SYS_ADMIN` in that user namespace. Which means, hypothetically, that when we check using `netlink_capable(skb, CAP_SYS_ADMIN)`, the result should be true. Time to verify that assumption. Let's dig into `netlink_capable` and make sure my understanding here is spot-on.
|
| 23/2 |
2026/05/16 04:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/netlink.h IncludeLines:true Name:netlink_capable]
Results: map[SourceCode: 873: /**
874: * netlink_capable - Netlink global message capability test
875: * @skb: socket buffer holding a netlink command from userspace
876: * @cap: The capability to use
877: *
878: * Test to see if the opener of the socket we received the message
879: * from had when the netlink socket was created and the sender of the
880: * message has the capability @cap in all user namespaces.
881: */
882: bool netlink_capable(const struct sk_buff *skb, int cap)
883: {
884: return netlink_ns_capable(skb, &init_user_ns, cap);
885: }
SourceFile:net/netlink/af_netlink.c]
|
| 24/2 |
2026/05/16 04:46 |
llm |
expert |
0m
Model:
Tokens:
input: 31306
output: 46
thoughts: 90
Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing:
**Delving into the `netlink_capable` Verification**
Hang on a minute! That `netlink_capable` function seems to be checking something against `&init_user_ns`. Now, that's interesting; I need to drill down and see exactly how it works. Let's dig into the implementation of `netlink_capable` itself.
Alright, so it calls `netlink_ns_capable(skb, &init_user_ns, cap)`. Aha! It's calling `netlink_ns_capable` *with* `&init_user_ns`. So, that must mean that effectively, the function is *requiring* `CAP_SYS_ADMIN` capability within the context of the `init_user_ns` namespace. That's a key observation. Now I need to understand what `netlink_ns_capable` is specifically doing and where it's deriving that requirement. Time to explore that next function.
|
| 25/2 |
2026/05/16 04:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netlink/af_netlink.c IncludeLines:true Name:netlink_ns_capable]
Results: map[SourceCode: 856: /**
857: * netlink_ns_capable - General netlink message capability test
858: * @skb: socket buffer holding a netlink command from userspace
859: * @user_ns: The user namespace of the capability to use
860: * @cap: The capability to use
861: *
862: * Test to see if the opener of the socket we received the message
863: * from had when the netlink socket was created and the sender of the
864: * message has the capability @cap in the user namespace @user_ns.
865: */
866: bool netlink_ns_capable(const struct sk_buff *skb,
867: struct user_namespace *user_ns, int cap)
868: {
869: return __netlink_ns_capable(&NETLINK_CB(skb), user_ns, cap);
870: }
SourceFile:net/netlink/af_netlink.c]
|
| 26/2 |
2026/05/16 04:46 |
llm |
expert |
0m
Model:
Tokens:
input: 31959
output: 35
thoughts: 118
Thoughts: **NBD Configuration: A Deep Dive into Privileges**
Okay, so it's becoming clear that configuring Network Block Devices (NBD) is more locked down than I initially thought. I was looking at `netlink_capable` and realizing it's dependent on that `init_user_ns` capability. This means, as expected, an unprivileged user, even within a new user or network namespace, can't just jump in and configure NBD through netlink.
But wait, I need to be thorough. What about the older `nbd_ioctl` method? Ah, right, that too relies on `capable(CAP_SYS_ADMIN)`. And guess what? `CAP_SYS_ADMIN` *also* ties back to `init_user_ns`.
So, it seems NBD configuration is entirely limited to global root; only the full `CAP_SYS_ADMIN` privilege at the very top level can do it. This isn't surprising, really, considering the potential impact on the system. Itβs important to remember that `capable(CAP_SYS_ADMIN)` is, in effect, the gatekeeper.
|
| 27/2 |
2026/05/16 04:46 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:kernel/capability.c IncludeLines:true Name:capable]
Results: map[SourceCode: 404: /**
405: * capable - Determine if the current task has a superior capability in effect
406: * @cap: The capability to be tested for
407: *
408: * Return true if the current task has the given superior capability currently
409: * available for use, false if not.
410: *
411: * This sets PF_SUPERPRIV on the task if the capability is available on the
412: * assumption that it's about to be used.
413: */
414: bool capable(int cap)
415: {
416: return ns_capable(&init_user_ns, cap);
417: }
SourceFile:kernel/capability.c]
|
| 28/2 |
2026/05/16 04:46 |
llm |
expert |
0m
Model:
Tokens:
input: 32579
output: 46
thoughts: 2944
Thoughts: **Analysis of the NBD Deadlock Vulnerability**
Okay, so here's what I've dissected about this NBD issue. It looks like the core problem is a potential circular locking dependency, a deadlock, involving `fs_reclaim`, `nsock->tx_lock` (related to NBD sockets), and `sk_lock-AF_INET6` (the lock protecting IPv6 sockets). But after thinking through it, it's not actually a *real* deadlock under normal circumstances, mostly a false positive from lockdep.
Initially, I considered the scenario where an unprivileged user or a VM guest might be able to trigger it. However, this appears impossible. `capable()` checks and `netlink_capable()` in `init_user_ns` and elsewhere prevent unprivileged processes and user namespaces from configuring NBD. VM guests can't directly configure NBD on the host; they interact via virtio-blk, and this interaction doesn't force this issue either. I went through the trigger conditions: `tcp_recvmsg` needing to cause direct reclaim (`fs_reclaim`), which submits an IO, which then needs `nsock->tx_lock`. Another thread needs to hold `nsock->tx_lock` while wanting `sk_lock-AF_INET6`. This needs a specific host configuration.
The vulnerability stems from the host's NBD configuration combined with memory pressure on the host. An attacker could potentially send network traffic to cause the host to enter a state where this deadlock *might* occur. However, the attacker needs to trigger the scenario.
I checked how the sockets get the `SOCK_MEMALLOC` flag, via `sk_set_memalloc`. Even if they do, this doesn't prevent user processes calling `recvmsg`. However, NBD sockets are *usually* dedicated, so this isn't an issue in normal operations, however. The syzkaller reproducer probably passes a socket to NBD and calls `recvmsg` at the same time, which is something that would not normally be done in a secure deployment.
The critical piece here is the difference between lock classes and lock instances. Lockdep sees the *classes* of the locks involved, not the specific instances. So if thread A is holding `sk_lock` for socket A and thread B is holding `nsock->tx_lock` for socket B, and we have a situation where a memory fault and IO occurs, the kernel might see a cyclical dependency and generate a warning. However, if A and B are different sockets, there's no *real* deadlock. Thread B can get `sk_lock B`, and there will be no global deadlock. This is a lockdep false positive.
However, the real key is, is it the *same* socket? If they are the same socket, then it's a real deadlock, triggered by a root user. But because of access controls on the NBD socket, a standard user could not cause this issue.
I went over several attack vectors:
* **Exploitable**: No. It's a lockdep warning or a potential deadlock, leading to a hang.
* **Denial of Service**: Yes, *potentially*, but only if the same socket is used, and in that case, the user needs root. A lockdep warning is disabled in production systems.
* **Access from Unprivileged Processes/User Namespaces/VM Guests**: No, due to the need for `CAP_SYS_ADMIN` in `init_user_ns`.
I then looked for other possible paths to `nbd_ioctl` and `nbd_genl_connect`, but these both explicitly check `CAP_SYS_ADMIN`. No way in!
Essentially, this is a lockdep false positive in normal operation because the locking classes are visible, not socket instances. To actually exploit this, root is needed, which means it doesn't represent a new security problem. It's a DoS, but a root user can DoS the system already.
|
| 29/2 |
2026/05/16 04:47 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_connect_genl_ops]
Results: map[SourceCode:2449: static const struct genl_small_ops nbd_connect_genl_ops[] = {
2450: {
2451: .cmd = NBD_CMD_CONNECT,
2452: .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2453: .doit = nbd_genl_connect,
2454: },
2455: {
2456: .cmd = NBD_CMD_DISCONNECT,
2457: .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2458: .doit = nbd_genl_disconnect,
2459: },
2460: {
2461: .cmd = NBD_CMD_RECONFIGURE,
2462: .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2463: .doit = nbd_genl_reconfigure,
2464: },
2465: {
2466: .cmd = NBD_CMD_STATUS,
2467: .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
2468: .doit = nbd_genl_status,
2469: },
2470: };
SourceFile:drivers/block/nbd.c]
|
| 30/2 |
2026/05/16 04:47 |
llm |
expert |
0m
Model:
Tokens:
input: 36836
output: 45
thoughts: 14
Thoughts: Okay, let's dive into this. Here's my thought process on this:
**Analyzing `nbd_genl_reconfigure`**
Right, let's take a look at `nbd_genl_reconfigure`. It's time to refresh my memory on what exactly this function does within the Network Block Device (NBD) kernel module. I need to understand its role in the overall re-configuration process. Is it dealing with general netlink messages? Does it handle a specific command or type of reconfiguration? Is this a crucial point to understand? I wonder how this impacts other components? My initial guess is that it's probably related to allowing dynamic adjustments to the NBD setup, perhaps modifying connection parameters, exporting/unexporting devices, or even controlling access permissions. Let's see what's actually under the hood. Time to dig in and clarify all of this!
|
| 31/2 |
2026/05/16 04:47 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_genl_reconfigure]
Results: map[SourceCode:2310: static int nbd_genl_reconfigure(struct sk_buff *skb, struct genl_info *info)
2311: {
2312: struct nbd_device *nbd = NULL;
2313: struct nbd_config *config;
2314: int index;
2315: int ret = 0;
2316: bool put_dev = false;
2317:
2318: if (!netlink_capable(skb, CAP_SYS_ADMIN))
2319: return -EPERM;
2320:
2321: if (GENL_REQ_ATTR_CHECK(info, NBD_ATTR_INDEX)) {
2322: pr_err("must specify a device to reconfigure\n");
2323: return -EINVAL;
2324: }
2325: index = nla_get_u32(info->attrs[NBD_ATTR_INDEX]);
2326: mutex_lock(&nbd_index_mutex);
2327: nbd = idr_find(&nbd_index_idr, index);
2328: if (!nbd) {
2329: mutex_unlock(&nbd_index_mutex);
2330: pr_err("couldn't find a device at index %d\n", index);
2331: return -EINVAL;
2332: }
2333: if (nbd->backend) {
2334: if (info->attrs[NBD_ATTR_BACKEND_IDENTIFIER]) {
2335: if (nla_strcmp(info->attrs[NBD_ATTR_BACKEND_IDENTIFIER],
2336: nbd->backend)) {
2337: mutex_unlock(&nbd_index_mutex);
2338: dev_err(nbd_to_dev(nbd),
2339: "backend image doesn't match with %s\n",
2340: nbd->backend);
2341: return -EINVAL;
2342: }
2343: } else {
2344: mutex_unlock(&nbd_index_mutex);
2345: dev_err(nbd_to_dev(nbd), "must specify backend\n");
2346: return -EINVAL;
2347: }
2348: }
2349: if (!refcount_inc_not_zero(&nbd->refs)) {
2350: mutex_unlock(&nbd_index_mutex);
2351: pr_err("device at index %d is going down\n", index);
2352: return -EINVAL;
2353: }
2354: mutex_unlock(&nbd_index_mutex);
2355:
2356: config = nbd_get_config_unlocked(nbd);
2357: if (!config) {
2358: dev_err(nbd_to_dev(nbd),
2359: "not configured, cannot reconfigure\n");
2360: nbd_put(nbd);
2361: return -EINVAL;
2362: }
2363:
2364: mutex_lock(&nbd->config_lock);
2365: if (!test_bit(NBD_RT_BOUND, &config->runtime_flags) ||
2366: !nbd->pid) {
2367: dev_err(nbd_to_dev(nbd),
2368: "not configured, cannot reconfigure\n");
2369: ret = -EINVAL;
2370: goto out;
2371: }
2372:
2373: ret = nbd_genl_size_set(info, nbd);
2374: if (ret)
2375: goto out;
2376:
2377: if (info->attrs[NBD_ATTR_TIMEOUT])
2378: nbd_set_cmd_timeout(nbd,
2379: nla_get_u64(info->attrs[NBD_ATTR_TIMEOUT]));
2380: if (info->attrs[NBD_ATTR_DEAD_CONN_TIMEOUT]) {
2381: config->dead_conn_timeout =
2382: nla_get_u64(info->attrs[NBD_ATTR_DEAD_CONN_TIMEOUT]);
2383: config->dead_conn_timeout *= HZ;
2384: }
2385: if (info->attrs[NBD_ATTR_CLIENT_FLAGS]) {
2386: u64 flags = nla_get_u64(info->attrs[NBD_ATTR_CLIENT_FLAGS]);
2387: if (flags & NBD_CFLAG_DESTROY_ON_DISCONNECT) {
2388: if (!test_and_set_bit(NBD_DESTROY_ON_DISCONNECT,
2389: &nbd->flags))
2390: put_dev = true;
2391: } else {
2392: if (test_and_clear_bit(NBD_DESTROY_ON_DISCONNECT,
2393: &nbd->flags))
2394: refcount_inc(&nbd->refs);
2395: }
2396:
2397: if (flags & NBD_CFLAG_DISCONNECT_ON_CLOSE) {
2398: set_bit(NBD_RT_DISCONNECT_ON_CLOSE,
2399: &config->runtime_flags);
2400: } else {
2401: clear_bit(NBD_RT_DISCONNECT_ON_CLOSE,
2402: &config->runtime_flags);
2403: }
2404: }
2405:
2406: if (info->attrs[NBD_ATTR_SOCKETS]) {
2407: struct nlattr *attr;
2408: int rem, fd;
2409:
2410: nla_for_each_nested(attr, info->attrs[NBD_ATTR_SOCKETS],
2411: rem) {
2412: struct nlattr *socks[NBD_SOCK_MAX+1];
2413:
2414: if (nla_type(attr) != NBD_SOCK_ITEM) {
2415: pr_err("socks must be embedded in a SOCK_ITEM attr\n");
2416: ret = -EINVAL;
2417: goto out;
2418: }
2419: ret = nla_parse_nested_deprecated(socks, NBD_SOCK_MAX,
2420: attr,
2421: nbd_sock_policy,
2422: info->extack);
2423: if (ret != 0) {
2424: pr_err("error processing sock list\n");
2425: ret = -EINVAL;
2426: goto out;
2427: }
2428: if (!socks[NBD_SOCK_FD])
2429: continue;
2430: fd = (int)nla_get_u32(socks[NBD_SOCK_FD]);
2431: ret = nbd_reconnect_socket(nbd, fd);
2432: if (ret) {
2433: if (ret == -ENOSPC)
2434: ret = 0;
2435: goto out;
2436: }
2437: dev_info(nbd_to_dev(nbd), "reconnected socket\n");
2438: }
2439: }
2440: out:
2441: mutex_unlock(&nbd->config_lock);
2442: nbd_config_put(nbd);
2443: nbd_put(nbd);
2444: if (put_dev)
2445: nbd_put(nbd);
2446: return ret;
2447: }
SourceFile:drivers/block/nbd.c]
|
| 32/2 |
2026/05/16 04:47 |
llm |
expert |
0m
Model:
Tokens:
input: 39302
output: 66
thoughts: 429
Thoughts: **My Analysis of the Lockdep Warning**
Okay, so I've looked closely at this and it's pretty clear: Every single one of the relevant components requires `netlink_capable(skb, CAP_SYS_ADMIN)`. That means this is categorically *not* something an unprivileged process or a user namespace can access. Definitely a key point.
Let's break down the whole thing for clarity. We have a circular locking dependency warning, a classic lockdep scenario. It specifically involves `fs_reclaim`, `nsock->tx_lock`, and `sk_lock-AF_INET6`. The core issue is that `tcp_recvmsg` holds `sk_lock` and can kick off memory reclaim (`fs_reclaim`). This memory reclaim can then lead to a bio being submitted to an NBD device. Now, the NBD device tries to grab `nsock->tx_lock`. Meanwhile, the NBD's `recv_work` holds the `nsock->tx_lock` and *also* tries to grab `sk_lock` to shut down the socket. It's an AB-BA deadlock, plain and simple.
However, the deadlock *only* happens if the socket being used by `tcp_recvmsg` is the same one used by the NBD device. Alternatively, it can occur if there's a circular dependency involving different sockets. This is really interesting because normally NBD sockets are dedicated to the NBD driver. They're not concurrently being read by user space.
Syzkaller managed to trigger this by doing exactly that: passing a socket to the NBD and concurrently calling `recvmsg` on it.
Now, because configuring an NBD device needs `CAP_SYS_ADMIN` in the initial user namespace, enforced by `capable(CAP_SYS_ADMIN)` in `nbd_ioctl` *and* the `netlink_capable` checks in the netlink operations, unprivileged users are blocked. They simply can't trigger this, even within a user namespace. The security model is holding firm here.
The bottom line is that while this is a deadlock, and therefore a denial-of-service, it isn't exploitable for privilege escalation or memory corruption. It needs local root to configure the NBD and execute the concurrent socket operations. You can't reach this from a VM guest, from network traffic, from any peripheral or by using a malicious filesystem. Excellent.
|
| 33/2 |
2026/05/16 04:47 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 34/2 |
2026/05/16 04:47 |
llm |
expert |
0m
Model:
Tokens:
input: 40377
output: 682
thoughts: 344
Thoughts: **Final Response: Bug Analysis**
Okay, the results are in, and it's time to craft the final response. I've got a good handle on this.
First, let's nail down the bug itself. It's a classic: a circular locking dependency, a deadlock, to be precise. The culprits are three locks: `sk_lock`, `fs_reclaim`, and `nsock->tx_lock`. The way it happens is as follows: A process, perhaps within `tcp_recvmsg`, is merrily holding onto `sk_lock`. Then, a page fault hits. Boom! That triggers memory reclaim, and `fs_reclaim` comes into play. Reclaim, in turn, decides it needs to submit a bio to an NBD device. This is where the fun begins. Submitting the bio requires the NBD device to acquire `nsock->tx_lock`. But, hereβs the kicker: concurrently, the NBD driver's `recv_work` routine is already holding `nsock->tx_lock` and trying to grab `sk_lock` in an attempt to shut down the socket. This results in the deadlock.
Next, we need to clarify the impact. This is a denial-of-service, a hang. It's a deadlock, not some nasty memory corruption or a privilege escalation exploit. That's good from a security perspective, but still frustrating for system reliability.
Now, for the critical point: the exploitability. Why isn't it easily exploited? It's rooted in permissions. Configuring an NBD device requires `CAP_SYS_ADMIN` in the *initial* user namespace. That's enforced by `nbd_ioctl` and `nbd_genl_connect`. Unprivileged users, even inside user namespaces, are locked out of setting up the NBD device necessary to trigger this mess.
Finally, we address the improbable scenario, which further reduces its practical threat. The real deadlock occurs only if a user-space process *concurrently* calls `recvmsg` on the *exact* same socket that was passed to the NBD device. This is highly abnormal; a trusted root user or admin is unlikely to perform such an odd operation. Lockdep, as always, correctly flags this issue, as it diligently tracks lock classes, not individual lock instances.
I think this covers everything concisely and provides a clear and reasoned explanation of the issue, its nature, triggers, and impact.
|
| 35/1 |
2026/05/16 04:47 |
action |
format-explanation |
0m
Results: map[Explanation:**Bug Analysis:**
The bug report indicates a circular locking dependency (potential deadlock)
detected by lockdep. The dependency chain involves three lock classes:
1. `sk_lock-AF_INET6` (Socket lock)
2. `fs_reclaim` (Memory reclaim pseudo-lock)
3. `nsock->tx_lock` (NBD socket transmission lock)
**Trigger Mechanism:**
The deadlock scenario occurs as follows:
- **CPU 0:** A user process calls `tcp_recvmsg` on a socket, acquiring
`sk_lock`. During the receive operation, it faults on a user-space buffer
(`copy_to_user`), triggering memory allocation. Under memory pressure, this
enters direct memory reclaim (`fs_reclaim`), which submits a block I/O request
(bio) to an NBD (Network Block Device). The NBD driver then attempts to acquire
`nsock->tx_lock` to transmit the request.
- **CPU 1:** Concurrently, the NBD driver's receive worker thread (`recv_work`)
holds `nsock->tx_lock` and encounters an error or disconnect. It then calls
`nbd_mark_nsock_dead`, which attempts to acquire `sk_lock` to shut down the
socket.
This creates an AB-BA deadlock if both operations happen on the exact same
socket, or a lockdep warning (due to lock classes) if they happen on different
sockets. Syzkaller triggered this by passing a socket to the NBD driver and then
intentionally calling `recvmsg` on that same socket concurrently from user
space.
**Security Impact Assessment:**
* **Exploitable:** **No.** This is a circular locking dependency that results in
a thread deadlock (hang). It does not cause memory corruption, use-after-free,
or out-of-bounds accesses, and therefore cannot be exploited for privilege
escalation or arbitrary code execution.
* **Denial Of Service:** **Yes.** If successfully triggered, the involved
threads will deadlock, potentially hanging the NBD device and any processes
attempting to perform I/O on it or use the involved sockets.
* **Accessible From Unprivileged Processes & User Namespaces:** **No.** To
trigger this bug, an attacker must configure an NBD device and pass a socket to
it. Both the `ioctl` interface (`nbd_ioctl`) and the Netlink interface
(`nbd_genl_connect`) for configuring NBD strictly require `CAP_SYS_ADMIN` in the
initial user namespace (`init_user_ns`). Unprivileged users, even those who have
created a new user namespace, cannot bypass this check.
* **Other Triggers (VM Guest, Network, Peripheral, Filesystem):** **No.** The
bug is a local host-side issue requiring explicit configuration of an NBD device
via privileged administrative interfaces. It cannot be triggered remotely, by a
VM guest, or by plugging in a malicious device/filesystem.
**Conclusion:**
This is a local Denial of Service (deadlock) that is strictly limited to the
global root user (`CAP_SYS_ADMIN`). Since root already has full control over the
system and can cause a DoS through numerous legitimate means, this bug presents
no meaningful security boundary crossing or risk to production environments.]
|