| 0/0 |
2026/05/17 04:47 |
flow |
assessment-security |
51m
Results: map[DenialOfService:false Explanation:**Analysis:**
The bug report is a `lockdep` warning indicating a possible circular locking
dependency. The reported dependency chain is:
`fs_reclaim` -> `q_usage_counter` -> `elevator_lock` -> `set->srcu` ->
`cmd->lock` -> `nsock->tx_lock` -> `sk_lock-AF_INET6` -> `mmap_lock` ->
`fs_reclaim`.
This is a classic lockdep false positive caused by lock class merging, rather
than a real deadlock:
1. **`sk_lock-AF_INET6` -> `mmap_lock`**: This dependency is established when a
user-space process calls `sendmsg` on a standard IPv6 socket. The kernel
acquires the socket lock (`sk_lock`) and then performs `copy_from_user`, which
can trigger a page fault and acquire the process's `mmap_lock`.
2. **`mmap_lock` -> `fs_reclaim`**: This is established when a process takes a
page fault (holding `mmap_lock`) and needs to allocate memory, thus entering the
memory reclaim path (`fs_reclaim`).
3. **`fs_reclaim` -> ... -> `sk_lock-AF_INET6`**: This is established when the
system is under memory pressure and direct reclaim submits a bio to a Network
Block Device (NBD) configured over IPv6. The NBD driver processes the request
and acquires the NBD socket's lock (`sk_lock`) to transmit the data.
Lockdep reports a cycle because it groups all IPv6 socket locks into a single
lock class (`sk_lock-AF_INET6`) and all memory map locks into another
(`mmap_lock`). However, in reality, no deadlock can occur because:
* The socket used by NBD is a different instance from the socket used by the
user-space process.
* The NBD kernel thread transmits data using kernel vectors (`kvec` or `bvec`),
which do not fault. Therefore, the NBD socket's `sk_lock` is never held while
waiting for an `mmap_lock`.
* The `mmap_lock` instances belong to different processes.
Furthermore, the NBD device setup (which establishes the reclaim-to-socket
dependency) is strictly privileged. The `nbd_genl_connect` and `nbd_ioctl`
interfaces explicitly check for `CAP_SYS_ADMIN` in the initial user namespace
(`init_user_ns`), meaning unprivileged users and users inside user namespaces
cannot configure NBD devices.
Since this is a false positive lockdep warning, and lockdep is a debugging
feature that is disabled in production builds, this bug has no security impact,
cannot be exploited, and does not cause a denial of service.
**Conclusion:**
The issue is a non-exploitable false positive in a debug tool (lockdep) that
requires global root privileges to even establish the necessary lock chains. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/17 04:47 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/05/17 04:48 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/53941eacc3a7f4e35f3bc670344ebe74facae2c5]
|
| 3/1 |
2026/05/17 04:49 |
action |
kernel-builder |
29m
Results: map[KernelObj:/app/workdir/cache/build/83d56c666707de33fd4c8e95194be797f643d9b6]
|
| 4/1 |
2026/05/17 05:19 |
action |
codesearch-prepare |
14m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/17 05:34 |
agent |
expert |
4m
Model:
Results: map[DenialOfService:false 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.2.4726/25180 is trying to acquire lock:
ffffffff8ea85520 (fs_reclaim){+.+.}-{0:0}, at: might_alloc include/linux/sched/mm.h:317 [inline]
ffffffff8ea85520 (fs_reclaim){+.+.}-{0:0}, at: prepare_alloc_pages+0x152/0x650 mm/page_alloc.c:4995
but task is already holding lock:
ffff888025b88338 (&mm->mmap_lock){++++}-{4:4}, at: mmap_read_lock_killable include/linux/mmap_lock.h:601 [inline]
ffff888025b88338 (&mm->mmap_lock){++++}-{4:4}, at: dump_user_range+0x1c5/0x12c0 fs/coredump.c:1360
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #7 (&mm->mmap_lock){++++}-{4:4}:
__might_fault+0xcb/0x130 mm/memory.c:7324
_inline_copy_from_user include/linux/uaccess.h:169 [inline]
_copy_from_user+0x28/0xb0 lib/usercopy.c:18
copy_from_user include/linux/uaccess.h:223 [inline]
csum_and_copy_from_user include/net/checksum.h:31 [inline]
copy_from_user_iter_csum net/core/skbuff.c:7402 [inline]
iterate_ubuf include/linux/iov_iter.h:30 [inline]
iterate_and_advance2 include/linux/iov_iter.h:302 [inline]
csum_and_copy_from_iter_full+0x1e7/0x1f00 net/core/skbuff.c:7414
ip_generic_getfrag+0x149/0x2d0 net/ipv4/ip_output.c:942
__ip6_append_data+0x39cd/0x3f60 net/ipv6/ip6_output.c:1736
ip6_append_data+0x10f/0x280 net/ipv6/ip6_output.c:1891
rawv6_sendmsg+0x12d3/0x18e0 net/ipv6/raw.c:913
sock_sendmsg_nosec net/socket.c:787 [inline]
__sock_sendmsg net/socket.c:802 [inline]
____sys_sendmsg+0x80a/0x9f0 net/socket.c:2698
___sys_sendmsg+0x2a5/0x360 net/socket.c:2752
__sys_sendmsg net/socket.c:2784 [inline]
__do_sys_sendmsg net/socket.c:2789 [inline]
__se_sys_sendmsg net/socket.c:2787 [inline]
__x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #6 (sk_lock-AF_INET6){+.+.}-{0:0}:
lock_sock_nested+0x41/0x100 net/core/sock.c:3783
lock_sock include/net/sock.h:1713 [inline]
inet_shutdown+0x6a/0x390 net/ipv4/af_inet.c:915
nbd_mark_nsock_dead+0x2e9/0x560 drivers/block/nbd.c:318
sock_shutdown+0x15e/0x260 drivers/block/nbd.c:411
nbd_clear_sock+0x24/0x170 drivers/block/nbd.c:1427
nbd_config_put+0x2dd/0x580 drivers/block/nbd.c:1451
nbd_genl_connect+0x19d5/0x1cf0 drivers/block/nbd.c:2248
genl_family_rcv_msg_doit+0x22a/0x330 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0x61c/0x7a0 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2551
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345
netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1895
sock_sendmsg_nosec net/socket.c:787 [inline]
__sock_sendmsg net/socket.c:802 [inline]
____sys_sendmsg+0x972/0x9f0 net/socket.c:2698
___sys_sendmsg+0x2a5/0x360 net/socket.c:2752
__sys_sendmsg net/socket.c:2784 [inline]
__do_sys_sendmsg net/socket.c:2789 [inline]
__se_sys_sendmsg net/socket.c:2787 [inline]
__x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #5 (&nsock->tx_lock){+.+.}-{4:4}:
__mutex_lock_common kernel/locking/mutex.c:646 [inline]
__mutex_lock+0x1a3/0x1550 kernel/locking/mutex.c:820
nbd_handle_cmd drivers/block/nbd.c:1143 [inline]
nbd_queue_rq+0x37b/0x1100 drivers/block/nbd.c:1207
blk_mq_dispatch_rq_list+0xa70/0x1910 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+0xdcc/0x1600 block/blk-mq-sched.c:307
blk_mq_sched_dispatch_requests+0xd7/0x190 block/blk-mq-sched.c:329
blk_mq_run_hw_queue+0x348/0x4f0 block/blk-mq.c:2386
blk_mq_dispatch_list+0xd16/0xe10 include/linux/spinlock.h:-1
blk_mq_flush_plug_list+0x48d/0x570 block/blk-mq.c:2997
__blk_flush_plug+0x3ed/0x4d0 block/blk-core.c:1230
blk_finish_plug block/blk-core.c:1257 [inline]
__submit_bio+0x28d/0x580 block/blk-core.c:649
__submit_bio_noacct_mq block/blk-core.c:722 [inline]
submit_bio_noacct_nocheck+0x2f4/0xa40 block/blk-core.c:753
submit_bh fs/buffer.c:2742 [inline]
block_read_full_folio+0x599/0x830 fs/buffer.c:2344
filemap_read_folio+0x137/0x3b0 mm/filemap.c:2502
do_read_cache_folio+0x358/0x590 mm/filemap.c:4107
read_mapping_folio include/linux/pagemap.h:1017 [inline]
read_part_sector+0xb6/0x2b0 block/partitions/core.c:724
adfspart_check_ICS+0xb1/0x960 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+0x817/0x1770 block/partitions/core.c:695
blkdev_get_whole+0x380/0x510 block/bdev.c:756
bdev_open+0x31e/0xd30 block/bdev.c:965
blkdev_open+0x470/0x610 block/fops.c:697
do_dentry_open+0x785/0x14e0 fs/open.c:947
vfs_open+0x3b/0x340 fs/open.c:1079
do_open fs/namei.c:4699 [inline]
path_openat+0x2e08/0x3860 fs/namei.c:4858
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 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+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/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+0x1a3/0x1550 kernel/locking/mutex.c:820
nbd_queue_rq+0xc6/0x1100 drivers/block/nbd.c:1199
blk_mq_dispatch_rq_list+0xa70/0x1910 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+0xdcc/0x1600 block/blk-mq-sched.c:307
blk_mq_sched_dispatch_requests+0xd7/0x190 block/blk-mq-sched.c:329
blk_mq_run_hw_queue+0x348/0x4f0 block/blk-mq.c:2386
blk_mq_dispatch_list+0xd16/0xe10 include/linux/spinlock.h:-1
blk_mq_flush_plug_list+0x48d/0x570 block/blk-mq.c:2997
__blk_flush_plug+0x3ed/0x4d0 block/blk-core.c:1230
blk_finish_plug block/blk-core.c:1257 [inline]
__submit_bio+0x28d/0x580 block/blk-core.c:649
__submit_bio_noacct_mq block/blk-core.c:722 [inline]
submit_bio_noacct_nocheck+0x2f4/0xa40 block/blk-core.c:753
submit_bh fs/buffer.c:2742 [inline]
block_read_full_folio+0x599/0x830 fs/buffer.c:2344
filemap_read_folio+0x137/0x3b0 mm/filemap.c:2502
do_read_cache_folio+0x358/0x590 mm/filemap.c:4107
read_mapping_folio include/linux/pagemap.h:1017 [inline]
read_part_sector+0xb6/0x2b0 block/partitions/core.c:724
adfspart_check_ICS+0xb1/0x960 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+0x817/0x1770 block/partitions/core.c:695
blkdev_get_whole+0x380/0x510 block/bdev.c:756
bdev_open+0x31e/0xd30 block/bdev.c:965
blkdev_open+0x470/0x610 block/fops.c:697
do_dentry_open+0x785/0x14e0 fs/open.c:947
vfs_open+0x3b/0x340 fs/open.c:1079
do_open fs/namei.c:4699 [inline]
path_openat+0x2e08/0x3860 fs/namei.c:4858
do_file_open+0x23e/0x4a0 fs/namei.c:4887
do_sys_openat2+0x113/0x200 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+0x138/0x170 fs/open.c:1381
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/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+0xca/0x300 kernel/rcu/srcutree.c:1481
elevator_switch+0x1e8/0x7a0 block/elevator.c:576
elevator_change+0x2cc/0x450 block/elevator.c:681
elevator_set_default+0x36c/0x430 block/elevator.c:754
blk_register_queue+0x3e9/0x4e0 block/blk-sysfs.c:987
__add_disk+0x677/0xd50 block/genhd.c:528
add_disk_fwnode+0xfb/0x480 block/genhd.c:597
add_disk include/linux/blkdev.h:794 [inline]
nbd_dev_add+0x72c/0xb50 drivers/block/nbd.c:1984
nbd_init+0x168/0x1f0 drivers/block/nbd.c:2692
do_one_initcall+0x250/0x870 init/main.c:1392
do_initcall_level+0x104/0x190 init/main.c:1454
do_initcalls+0x59/0xa0 init/main.c:1470
kernel_init_freeable+0x2a6/0x3e0 init/main.c:1703
kernel_init+0x1d/0x1d0 init/main.c:1593
ret_from_fork+0x514/0xb70 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+0x1a3/0x1550 kernel/locking/mutex.c:820
elevator_change+0x1b3/0x450 block/elevator.c:679
elevator_set_none+0xb5/0x140 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+0x5e7/0x1a60 block/blk-mq.c:5241
nbd_start_device+0x17f/0xb10 drivers/block/nbd.c:1489
nbd_genl_connect+0x165b/0x1cf0 drivers/block/nbd.c:2239
genl_family_rcv_msg_doit+0x22a/0x330 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0x61c/0x7a0 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x232/0x4b0 net/netlink/af_netlink.c:2551
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1319 [inline]
netlink_unicast+0x75c/0x8e0 net/netlink/af_netlink.c:1345
netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1895
sock_sendmsg_nosec net/socket.c:787 [inline]
__sock_sendmsg net/socket.c:802 [inline]
____sys_sendmsg+0x972/0x9f0 net/socket.c:2698
___sys_sendmsg+0x2a5/0x360 net/socket.c:2752
__sys_sendmsg net/socket.c:2784 [inline]
__do_sys_sendmsg net/socket.c:2789 [inline]
__se_sys_sendmsg net/socket.c:2787 [inline]
__x64_sys_sendmsg+0x1bd/0x2a0 net/socket.c:2787
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x15f/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
-> #1 (&q->q_usage_counter(io)#49){++++}-{0:0}:
blk_alloc_queue+0x546/0x680 block/blk-core.c:461
blk_mq_alloc_queue block/blk-mq.c:4450 [inline]
__blk_mq_alloc_disk+0x197/0x390 block/blk-mq.c:4497
nbd_dev_add+0x499/0xb50 drivers/block/nbd.c:1954
nbd_init+0x168/0x1f0 drivers/block/nbd.c:2692
do_one_initcall+0x250/0x870 init/main.c:1392
do_initcall_level+0x104/0x190 init/main.c:1454
do_initcalls+0x59/0xa0 init/main.c:1470
kernel_init_freeable+0x2a6/0x3e0 init/main.c:1703
kernel_init+0x1d/0x1d0 init/main.c:1593
ret_from_fork+0x514/0xb70 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+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
__fs_reclaim_acquire mm/page_alloc.c:4325 [inline]
fs_reclaim_acquire+0x71/0x100 mm/page_alloc.c:4339
might_alloc include/linux/sched/mm.h:317 [inline]
prepare_alloc_pages+0x152/0x650 mm/page_alloc.c:4995
__alloc_frozen_pages_noprof+0x12f/0x380 mm/page_alloc.c:5215
alloc_pages_mpol+0x235/0x490 mm/mempolicy.c:2490
alloc_frozen_pages_noprof mm/mempolicy.c:2561 [inline]
alloc_pages_noprof+0xac/0x2a0 mm/mempolicy.c:2581
pagetable_alloc_noprof include/linux/mm.h:3651 [inline]
pmd_alloc_one_noprof include/asm-generic/pgalloc.h:143 [inline]
__pmd_alloc+0x3a/0x5c0 mm/memory.c:6804
pmd_alloc include/linux/mm.h:3567 [inline]
__handle_mm_fault mm/memory.c:6501 [inline]
handle_mm_fault+0xe96/0x3170 mm/memory.c:6718
faultin_page mm/gup.c:1126 [inline]
__get_user_pages+0x1683/0x2720 mm/gup.c:1428
__get_user_pages_locked mm/gup.c:1692 [inline]
get_dump_page+0x1b5/0x410 mm/gup.c:2192
dump_user_range+0x20a/0x12c0 fs/coredump.c:1372
elf_core_dump+0x34c2/0x3ad0 fs/binfmt_elf.c:2109
coredump_write+0x1216/0x1910 fs/coredump.c:1053
do_coredump fs/coredump.c:1132 [inline]
vfs_coredump+0x3807/0x4530 fs/coredump.c:1206
get_signal+0x1107/0x1330 kernel/signal.c:3022
arch_do_signal_or_restart+0xbc/0x830 arch/x86/kernel/signal.c:337
__exit_to_user_mode_loop kernel/entry/common.c:64 [inline]
exit_to_user_mode_loop+0x86/0x480 kernel/entry/common.c:98
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:238 [inline]
syscall_exit_to_user_mode include/linux/entry-common.h:318 [inline]
do_syscall_64+0x33e/0xf80 arch/x86/entry/syscall_64.c:100
entry_SYSCALL_64_after_hwframe+0x77/0x7f
other info that might help us debug this:
Chain exists of:
fs_reclaim --> sk_lock-AF_INET6 --> &mm->mmap_lock
Possible unsafe locking scenario:
CPU0 CPU1
---- ----
rlock(&mm->mmap_lock);
lock(sk_lock-AF_INET6);
lock(&mm->mmap_lock);
lock(fs_reclaim);
*** DEADLOCK ***
2 locks held by syz.2.4726/25180:
#0: ffff88807db3a410 (sb_writers#5){.+.+}-{0:0}, at: do_coredump fs/coredump.c:1132 [inline]
#0: ffff88807db3a410 (sb_writers#5){.+.+}-{0:0}, at: vfs_coredump+0x3807/0x4530 fs/coredump.c:1206
#1: ffff888025b88338 (&mm->mmap_lock){++++}-{4:4}, at: mmap_read_lock_killable include/linux/mmap_lock.h:601 [inline]
#1: ffff888025b88338 (&mm->mmap_lock){++++}-{4:4}, at: dump_user_range+0x1c5/0x12c0 fs/coredump.c:1360
stack backtrace:
CPU: 1 UID: 0 PID: 25180 Comm: syz.2.4726 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/18/2026
Call Trace:
<TASK>
dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120
print_circular_bug+0x2e1/0x300 kernel/locking/lockdep.c:2043
check_noncircular+0x12e/0x150 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+0x15a5/0x2cf0 kernel/locking/lockdep.c:5237
lock_acquire+0x106/0x350 kernel/locking/lockdep.c:5868
__fs_reclaim_acquire mm/page_alloc.c:4325 [inline]
fs_reclaim_acquire+0x71/0x100 mm/page_alloc.c:4339
might_alloc include/linux/sched/mm.h:317 [inline]
prepare_alloc_pages+0x152/0x650 mm/page_alloc.c:4995
__alloc_frozen_pages_noprof+0x12f/0x380 mm/page_alloc.c:5215
alloc_pages_mpol+0x235/0x490 mm/mempolicy.c:2490
alloc_frozen_pages_noprof mm/mempolicy.c:2561 [inline]
alloc_pages_noprof+0xac/0x2a0 mm/mempolicy.c:2581
pagetable_alloc_noprof include/linux/mm.h:3651 [inline]
pmd_alloc_one_noprof include/asm-generic/pgalloc.h:143 [inline]
__pmd_alloc+0x3a/0x5c0 mm/memory.c:6804
pmd_alloc include/linux/mm.h:3567 [inline]
__handle_mm_fault mm/memory.c:6501 [inline]
handle_mm_fault+0xe96/0x3170 mm/memory.c:6718
faultin_page mm/gup.c:1126 [inline]
__get_user_pages+0x1683/0x2720 mm/gup.c:1428
__get_user_pages_locked mm/gup.c:1692 [inline]
get_dump_page+0x1b5/0x410 mm/gup.c:2192
dump_user_range+0x20a/0x12c0 fs/coredump.c:1372
elf_core_dump+0x34c2/0x3ad0 fs/binfmt_elf.c:2109
coredump_write+0x1216/0x1910 fs/coredump.c:1053
do_coredump fs/coredump.c:1132 [inline]
vfs_coredump+0x3807/0x4530 fs/coredump.c:1206
get_signal+0x1107/0x1330 kernel/signal.c:3022
arch_do_signal_or_restart+0xbc/0x830 arch/x86/kernel/signal.c:337
__exit_to_user_mode_loop kernel/entry/common.c:64 [inline]
exit_to_user_mode_loop+0x86/0x480 kernel/entry/common.c:98
__exit_to_user_mode_prepare include/linux/irq-entry-common.h:207 [inline]
syscall_exit_to_user_mode_prepare include/linux/irq-entry-common.h:238 [inline]
syscall_exit_to_user_mode include/linux/entry-common.h:318 [inline]
do_syscall_64+0x33e/0xf80 arch/x86/entry/syscall_64.c:100
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f71b9b9cdd9
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f71bab36028 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: 0000000000000000 RBX: 00007f71b9e15fa0 RCX: 00007f71b9b9cdd9
RDX: 0000000000000048 RSI: 0000200000000500 RDI: 000000000000000a
RBP: 00007f71b9c32d69 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f71b9e16038 R14: 00007f71b9e15fa0 R15: 00007ffd0ce6f698
</TASK>
Reply: **Analysis:**
The bug report is a `lockdep` warning indicating a possible circular locking dependency. The reported dependency chain is:
`fs_reclaim` -> `q_usage_counter` -> `elevator_lock` -> `set->srcu` -> `cmd->lock` -> `nsock->tx_lock` -> `sk_lock-AF_INET6` -> `mmap_lock` -> `fs_reclaim`.
This is a classic lockdep false positive caused by lock class merging, rather than a real deadlock:
1. **`sk_lock-AF_INET6` -> `mmap_lock`**: This dependency is established when a user-space process calls `sendmsg` on a standard IPv6 socket. The kernel acquires the socket lock (`sk_lock`) and then performs `copy_from_user`, which can trigger a page fault and acquire the process's `mmap_lock`.
2. **`mmap_lock` -> `fs_reclaim`**: This is established when a process takes a page fault (holding `mmap_lock`) and needs to allocate memory, thus entering the memory reclaim path (`fs_reclaim`).
3. **`fs_reclaim` -> ... -> `sk_lock-AF_INET6`**: This is established when the system is under memory pressure and direct reclaim submits a bio to a Network Block Device (NBD) configured over IPv6. The NBD driver processes the request and acquires the NBD socket's lock (`sk_lock`) to transmit the data.
Lockdep reports a cycle because it groups all IPv6 socket locks into a single lock class (`sk_lock-AF_INET6`) and all memory map locks into another (`mmap_lock`). However, in reality, no deadlock can occur because:
* The socket used by NBD is a different instance from the socket used by the user-space process.
* The NBD kernel thread transmits data using kernel vectors (`kvec` or `bvec`), which do not fault. Therefore, the NBD socket's `sk_lock` is never held while waiting for an `mmap_lock`.
* The `mmap_lock` instances belong to different processes.
Furthermore, the NBD device setup (which establishes the reclaim-to-socket dependency) is strictly privileged. The `nbd_genl_connect` and `nbd_ioctl` interfaces explicitly check for `CAP_SYS_ADMIN` in the initial user namespace (`init_user_ns`), meaning unprivileged users and users inside user namespaces cannot configure NBD devices.
Since this is a false positive lockdep warning, and lockdep is a debugging feature that is disabled in production builds, this bug has no security impact, cannot be exploited, and does not cause a denial of service.
**Conclusion:**
The issue is a non-exploitable false positive in a debug tool (lockdep) that requires global root privileges to even establish the necessary lock chains.
|
| 6/2 |
2026/05/17 05:34 |
llm |
expert |
0m
Model:
Tokens:
input: 13533
output: 44
thoughts: 1342
Thoughts: **Analyzing a Lockdep Warning: A Deep Dive**
Okay, so I've got this lockdep warning: "possible circular locking dependency detected". The report says it involves `fs_reclaim`, `sk_lock-AF_INET6`, and `&mm->mmap_lock`. My initial thought is that this needs immediate investigation, even though lockdep warnings aren't fatal unless explicitly configured to be. The potential impact here is a Denial of Service, if this leads to a deadlock. Let's trace this dependency chain and see what's really going on here.
First, I see that `fs_reclaim` is acquired way down the line in `dump_user_range`, which calls `get_dump_page`, which eventually calls `__get_user_pages`, and eventually the `fs_reclaim_acquire` function. Crucially, `&mm->mmap_lock` is *already* held at that point because of how `dump_user_range` works. So, we've got `&mm->mmap_lock` "before" `fs_reclaim` in this part of the chain.
Now, let's look at the existing chain. The report says it goes something like this: `&mm->mmap_lock` -> `sk_lock-AF_INET6`. I see `rawv6_sendmsg` involved which calls `ip6_append_data`, which eventually involves `copy_from_user` and `__might_fault`, which checks `mmap_lock`. Wait, does `rawv6_sendmsg` *hold* `sk_lock` directly? No, it's calling `lock_sock`. Okay, so `sk_lock` is handled *within* `rawv6_sendmsg`. Then I check `nbd_genl_connect` and the netlink aspect and it doesn't hold `sk_lock` directly. Then I go down the chain of locks: `tx_lock`, `cmd->lock`, `srcu`, `elevator_lock`, and finally `q_usage_counter`.
So, the dependency chain seems to be:
`fs_reclaim` -> `q_usage_counter(io)` -> `elevator_lock` -> `srcu` -> `cmd->lock` -> `tx_lock` -> `sk_lock-AF_INET6` -> `&mm->mmap_lock` -> `fs_reclaim`
That's definitely a circular dependency! I'm worried about that.
Now, I'm thinking about the implications. A deadlock would hang the system. Can an unprivileged user trigger this? I'm remembering that NBD (Network Block Device) uses netlink, so I need to check the `drivers/block/nbd.c` code to confirm if `nbd_genl_connect` requires any privileges. I've got to find out if this is something that a normal user can set off or if it's restricted. I'll need to check the code to be sure.
|
| 7/2 |
2026/05/17 05:34 |
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]
|
| 8/2 |
2026/05/17 05:34 |
llm |
expert |
0m
Model:
Tokens:
input: 18470
output: 41
thoughts: 80
Thoughts: **Analyzing the Network Block Device Connect Function**
Okay, so I'm looking at this `nbd_genl_connect` function and immediately I see this `if` statement: `if (!netlink_capable(skb, CAP_SYS_ADMIN)) return -EPERM;`. Right, so it's demanding `CAP_SYS_ADMIN` for execution. That's standard for a function of this type. Now, I'm just quickly trying to clarify something in my head... is this capability check using `ns_capable` or just `capable`? Let me just double-check the definition of `netlink_capable` to be absolutely sure. Gotta be precise here.
|
| 9/2 |
2026/05/17 05:34 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/netlink.h IncludeLines:true Name:netlink_capable]
Results: map[SourceCode: 874: /**
875: * netlink_capable - Netlink global message capability test
876: * @skb: socket buffer holding a netlink command from userspace
877: * @cap: The capability to use
878: *
879: * Test to see if the opener of the socket we received the message
880: * from had when the netlink socket was created and the sender of the
881: * message has the capability @cap in all user namespaces.
882: */
883: bool netlink_capable(const struct sk_buff *skb, int cap)
884: {
885: return netlink_ns_capable(skb, &init_user_ns, cap);
886: }
SourceFile:net/netlink/af_netlink.c]
|
| 10/2 |
2026/05/17 05:34 |
llm |
expert |
0m
Model:
Tokens:
input: 18983
output: 43
thoughts: 764
Thoughts: **Analyzing a Potential Circular Locking Dependency**
Okay, so I'm looking at this bug report and it's flagged with a lockdep warning, specifically a possible circular locking dependency. My first thought is to understand the context. It seems that triggering `nbd_genl_connect`, the point of entry for this issue, requires `CAP_SYS_ADMIN` in the initial user namespace. This immediately means it's inaccessible to unprivileged processes and user namespaces, which drastically reduces the attack surface. That's good.
But, I need to dig deeper. I need to understand if there are any other ways to reach this state. Let's trace the lock dependency chain to see if it's even a real deadlock that could be exploited:
1. `fs_reclaim` -> `&q->q_usage_counter(io)`
2. `&q->q_usage_counter(io)` -> `&q->elevator_lock`
3. `&q->elevator_lock` -> `set->srcu`
4. `set->srcu` -> `&cmd->lock`
5. `&cmd->lock` -> `&nsock->tx_lock`
6. `&nsock->tx_lock` -> `sk_lock-AF_INET6`
7. `sk_lock-AF_INET6` -> `&mm->mmap_lock`
8. `&mm->mmap_lock` -> `fs_reclaim`
Now, let's play this out in my mind. A process holds `mmap_lock` β this is a common situation during page faults or memory dumps. Then, it allocates memory, thus acquiring `fs_reclaim`. Another process might hold `sk_lock` and do a `copy_from_user` and would end up acquiring `mmap_lock`. So, this `sk_lock` to `mmap_lock` dependency seems like a potentially common pattern...
Let's break this down. If process A has `mmap_lock` and it calls a function that calls `fs_reclaim`, the chain goes like this: Process B holds `sk_lock`, which in turn leads to `tx_lock` acquisition. Process C holds `cmd->lock` which goes to `set->srcu`, leading to the acquisition of `elevator_lock` which acquires `q_usage_counter`.
Where does all of this start? The `fs_reclaim` -> `q_usage_counter` happens within `blk_alloc_queue` during `nbd_dev_add`. `nbd_dev_add` is triggered by `nbd_init` (module initialization) or `nbd_genl_connect`. Module init requires root, as does `nbd_genl_connect`.
Alright, let's explore that `sk_lock` to `mmap_lock` path. Ah, yes, `rawv6_sendmsg` can grab `sk_lock`, then call `ip6_append_data`, which eventually leads to `csum_and_copy_from_iter_full`. This calls `copy_from_user`, which in turn triggers `__might_fault`, and ultimately `mmap_lock`. Standard stuff. But wait⦠can we acquire a lock that can lead us back to `mmap_lock`?
But the critical part... where is the path from `tx_lock` to `sk_lock`? It seems to involve `nbd_genl_connect` -> `nbd_config_put` -> `nbd_clear_sock` -> `sock_shutdown` -> `inet_shutdown`, and the dreaded `lock_sock`. Okay, but wait a second... `nbd_genl_connect` doesn't *hold* `tx_lock` during that sequence! This needs to be double-checked by digging into `nbd_config_put`. I need to look into this more closely to see how the connection between the locks is made.
|
| 11/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_config_put]
Results: map[SourceCode:1432: static void nbd_config_put(struct nbd_device *nbd)
1433: {
1434: if (refcount_dec_and_mutex_lock(&nbd->config_refs,
1435: &nbd->config_lock)) {
1436: struct nbd_config *config = nbd->config;
1437: nbd_dev_dbg_close(nbd);
1438: invalidate_disk(nbd->disk);
1439: if (nbd->config->bytesize)
1440: kobject_uevent(&nbd_to_dev(nbd)->kobj, KOBJ_CHANGE);
1441: if (test_and_clear_bit(NBD_RT_HAS_PID_FILE,
1442: &config->runtime_flags))
1443: device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
1444: nbd->pid = 0;
1445: if (test_and_clear_bit(NBD_RT_HAS_BACKEND_FILE,
1446: &config->runtime_flags)) {
1447: device_remove_file(disk_to_dev(nbd->disk), &backend_attr);
1448: kfree(nbd->backend);
1449: nbd->backend = NULL;
1450: }
1451: nbd_clear_sock(nbd);
1452: if (config->num_connections) {
1453: int i;
1454: for (i = 0; i < config->num_connections; i++) {
1455: sockfd_put(config->socks[i]->sock);
1456: kfree(config->socks[i]);
1457: }
1458: kfree(config->socks);
1459: }
1460: kfree(nbd->config);
1461: nbd->config = NULL;
1462:
1463: nbd->tag_set.timeout = 0;
1464:
1465: mutex_unlock(&nbd->config_lock);
1466: nbd_put(nbd);
1467: module_put(THIS_MODULE);
1468: }
1469: }
SourceFile:drivers/block/nbd.c]
|
| 12/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 21333
output: 46
thoughts: 442
Thoughts: **Analyzing a Potential Locking Issue in the NBD Driver**
Okay, first things first, let's look at this stack trace for issue #6. It involves `sk_lock-AF_INET6` and, critically, `&nsock->tx_lock`. I see a clear path here: `lock_sock_nested`, `inet_shutdown`, and the NBD driver functions `nbd_mark_nsock_dead` and beyond. My initial thought is, this seems straightforward, right? But something feels off... where's `tx_lock`?
Then I realize the lockdep report confirms the relevant function: `nbd_genl_connect`. Ah ha! The dependency is `&nsock->tx_lock` *before* `sk_lock-AF_INET6`. Okay, so `sk_lock` is being acquired *while* already holding `tx_lock`. That's a classic reverse locking order, a potential recipe for deadlock if we're not careful. I need to dig into `nbd_mark_nsock_dead` now. Let's see how that lock acquisition is actually occurring. I'll need to confirm that this is indeed what's happening.
|
| 13/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_mark_nsock_dead]
Results: map[SourceCode: 305: static void nbd_mark_nsock_dead(struct nbd_device *nbd, struct nbd_sock *nsock,
306: int notify)
307: {
308: if (!nsock->dead && notify && !nbd_disconnected(nbd->config)) {
309: struct link_dead_args *args;
310: args = kmalloc_obj(struct link_dead_args, GFP_NOIO);
311: if (args) {
312: INIT_WORK(&args->work, nbd_dead_link_work);
313: args->index = nbd->index;
314: queue_work(system_percpu_wq, &args->work);
315: }
316: }
317: if (!nsock->dead) {
318: kernel_sock_shutdown(nsock->sock, SHUT_RDWR);
319: if (atomic_dec_return(&nbd->config->live_connections) == 0) {
320: if (test_and_clear_bit(NBD_RT_DISCONNECT_REQUESTED,
321: &nbd->config->runtime_flags)) {
322: set_bit(NBD_RT_DISCONNECTED,
323: &nbd->config->runtime_flags);
324: dev_info(nbd_to_dev(nbd),
325: "Disconnected due to user request.\n");
326: }
327: }
328: }
329: nsock->dead = true;
330: nsock->pending = NULL;
331: nsock->sent = 0;
332: }
SourceFile:drivers/block/nbd.c]
|
| 14/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 22590
output: 40
thoughts: 35
Thoughts: Okay, let me think this through.
**Analyzing Potential Concurrency Issues with Socket Shutdown**
Right, so `kernel_sock_shutdown` β that function grabs the `sk_lock`. I need to figure out how this interacts with other locks, particularly anything that might touch the transmit path. Specifically, I'm concerned about where the `tx_lock` is acquired. Is there a potential for deadlock? A race condition? I need to understand the locking order here to ensure thread safety. Let's see... the most logical next step is to examine the `sock_shutdown` function. That should give me the context I need and hopefully expose how those locks are used and when. I'll focus on the places where `tx_lock` is touched and compare to where `sk_lock` is touched.
|
| 15/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:sock_shutdown]
Results: map[SourceCode: 395: /*
396: * Forcibly shutdown the socket causing all listeners to error
397: */
398: static void sock_shutdown(struct nbd_device *nbd)
399: {
400: struct nbd_config *config = nbd->config;
401: int i;
402:
403: if (config->num_connections == 0)
404: return;
405: if (test_and_set_bit(NBD_RT_DISCONNECTED, &config->runtime_flags))
406: return;
407:
408: for (i = 0; i < config->num_connections; i++) {
409: struct nbd_sock *nsock = config->socks[i];
410: mutex_lock(&nsock->tx_lock);
411: nbd_mark_nsock_dead(nbd, nsock, 0);
412: mutex_unlock(&nsock->tx_lock);
413: }
414: dev_warn(disk_to_dev(nbd->disk), "shutting down sockets\n");
415: }
SourceFile:drivers/block/nbd.c]
|
| 16/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 23198
output: 41
thoughts: 194
Thoughts: **Lock Dependency Discovery**
Okay, let's break this down. My analysis indicates a potential lock dependency issue, specifically related to the `sock_shutdown` function within the NBD (Network Block Device) driver. Here's what I've traced:
`sock_shutdown` acquires the `nsock->tx_lock` first. Then, it calls `nbd_mark_nsock_dead`, which in turn, calls `kernel_sock_shutdown`. And that routine is the problem, as it tries to acquire the `sk_lock`. So, we have a clear lock ordering: `tx_lock` before `sk_lock`.
Now, the interesting part is where `sock_shutdown` gets invoked. It's called from `nbd_clear_sock`, which is itself called from `nbd_config_put`. Digging further, `nbd_config_put` is called by `nbd_genl_connect`. This means the problematic lock dependency arises during the failure or cleanup of `nbd_genl_connect`.
Given that `nbd_genl_connect` requires `CAP_SYS_ADMIN` in the initial user namespace, this entire lock dependency chain, at least in the initial setup, can *only* be established by root.
But, before I conclude too quickly, I should make sure there aren't other entry points to `sock_shutdown`. Let me go ahead and check the references to `sock_shutdown` to confirm. It's best to be thorough.
|
| 17/2 |
2026/05/17 05:35 |
tool |
codesearch-find-references |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeSnippetLines:0 Name:sock_shutdown]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nbd_clear_sock SourceFile:drivers/block/nbd.c SourceLine:1427] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nbd_disconnect_and_put SourceFile:drivers/block/nbd.c SourceLine:2258] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nbd_handle_cmd SourceFile:drivers/block/nbd.c SourceLine:1159] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nbd_start_device SourceFile:drivers/block/nbd.c SourceLine:1515] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nbd_start_device_ioctl SourceFile:drivers/block/nbd.c SourceLine:1558] map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nbd_xmit_timeout SourceFile:drivers/block/nbd.c SourceLine:544]] TruncatedOutput:false]
|
| 18/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 24094
output: 41
thoughts: 73
Thoughts: Here's my analysis of the code, presented as if it were my thought process:
**Tracing the Callers of `nbd_start_device_ioctl`**
Okay, so I need to understand where `nbd_start_device_ioctl` is being called from. I'm seeing it's being invoked from a few different places, specifically `nbd_xmit_timeout`, `nbd_handle_cmd`, `nbd_disconnect_and_put`, and, importantly, `nbd_start_device_ioctl` is called from `nbd_ioctl`. Alright, so `nbd_ioctl` seems like a critical entry point to investigate further, since it seems to be the one that likely triggers `nbd_start_device_ioctl`. Let's dig into `nbd_ioctl` and see what's happening there, to get the full picture.
|
| 19/2 |
2026/05/17 05:35 |
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]
|
| 20/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 24929
output: 41
thoughts: 791
Thoughts: **Analyzing a Potential Kernel Deadlock in the NBD Driver**
Okay, so I'm digging into this `nbd_ioctl` issue, and the need for `CAP_SYS_ADMIN` in the initial namespace immediately jumps out. But then, my mind shifts gears β what about `nbd_xmit_timeout`? The block layer calls that when a request times out. Now, can an unprivileged user even *trigger* a timeout? If they can get access to `/dev/nbd0` and read/write to it, they can definitely submit requests. If the NBD server goes silent, timeout! The catch is, setting up the NBD device itself *requires* `CAP_SYS_ADMIN`β¦ so, root.
So the initial setup is privileged. But *after* setup, can an unprivileged user get in? Typically, `/dev/nbd0` is root:disk, 0660 permissions. Meaning they can't touch it unless they're in the `disk` group. But even if they *could*, the lock dependency is established during setup or a timeout, not inherently exploitable.
Now, the lockdep warning... ah, circular dependency! Can a deadlock actually *happen*? Let's map it out. A possible deadlock scenario would be:
* CPU0:
* `rlock(&mm->mmap_lock)` (e.g., page fault)
* `lock(fs_reclaim)` (e.g., memory allocation during the page fault)
* CPU1:
* `lock(sk_lock-AF_INET6)` (e.g., `rawv6_sendmsg`)
* `lock(&mm->mmap_lock)` (e.g., `copy_from_user` in `rawv6_sendmsg`)
CPU1 is holding `sk_lock` and waiting for `mmap_lock`. CPU0 has `mmap_lock` and waits for `fs_reclaim`. The key question is: Where does `fs_reclaim` connect back to `sk_lock`?
Alright, let's trace this back: `fs_reclaim` -> `&q->q_usage_counter(io)` -> `&q->elevator_lock` -> `set->srcu` -> `&cmd->lock` -> `&nsock->tx_lock` -> `sk_lock-AF_INET6`. Okay, I see the chain now.
So, could CPU2 be holding `fs_reclaim` and waiting for `q_usage_counter`? Not quite, `fs_reclaim` acts as a pseudo-lock. It's really acquired during memory allocation. If a process is doing memory allocation, it "holds" `fs_reclaim`, so does it then block on `q_usage_counter`? Where does `fs_reclaim` -> `q_usage_counter` happen?
Looks like we are talking about `blk_alloc_queue`.
-> #1 (&q->q_usage_counter(io)#49){++++}-{0:0}:
blk_alloc_queue+0x546/0x680 block/blk-core.c:461
blk_mq_alloc_queue block/blk-mq.c:4450 [inline]
__blk_mq_alloc_disk+0x197/0x390 block/blk-mq.c:4497
nbd_dev_add+0x499/0xb50 drivers/block/nbd.c:1954
But wait... `blk_alloc_queue` just *initializes* `q_usage_counter`. It doesn't acquire it *while holding* `fs_reclaim`. Okay, time to check `blk_alloc_queue` to confirm this.
|
| 21/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-core.c IncludeLines:true Name:blk_alloc_queue]
Results: map[SourceCode: 393: struct request_queue *blk_alloc_queue(struct queue_limits *lim, int node_id)
394: {
395: struct request_queue *q;
396: int error;
397:
398: q = kmem_cache_alloc_node(blk_requestq_cachep, GFP_KERNEL | __GFP_ZERO,
399: node_id);
400: if (!q)
401: return ERR_PTR(-ENOMEM);
402:
403: q->last_merge = NULL;
404:
405: q->id = ida_alloc(&blk_queue_ida, GFP_KERNEL);
406: if (q->id < 0) {
407: error = q->id;
408: goto fail_q;
409: }
410:
411: q->stats = blk_alloc_queue_stats();
412: if (!q->stats) {
413: error = -ENOMEM;
414: goto fail_id;
415: }
416:
417: error = blk_set_default_limits(lim);
418: if (error)
419: goto fail_stats;
420: q->limits = *lim;
421:
422: q->node = node_id;
423:
424: atomic_set(&q->nr_active_requests_shared_tags, 0);
425:
426: timer_setup(&q->timeout, blk_rq_timed_out_timer, 0);
427: INIT_WORK(&q->timeout_work, blk_timeout_work);
428: INIT_LIST_HEAD(&q->icq_list);
429:
430: refcount_set(&q->refs, 1);
431: mutex_init(&q->debugfs_mutex);
432: mutex_init(&q->elevator_lock);
433: mutex_init(&q->sysfs_lock);
434: mutex_init(&q->limits_lock);
435: mutex_init(&q->rq_qos_mutex);
436: spin_lock_init(&q->queue_lock);
437:
438: init_waitqueue_head(&q->mq_freeze_wq);
439: mutex_init(&q->mq_freeze_lock);
440:
441: blkg_init_queue(q);
442:
443: /*
444: * Init percpu_ref in atomic mode so that it's faster to shutdown.
445: * See blk_register_queue() for details.
446: */
447: error = percpu_ref_init(&q->q_usage_counter,
448: blk_queue_usage_counter_release,
449: PERCPU_REF_INIT_ATOMIC, GFP_KERNEL);
450: if (error)
451: goto fail_stats;
452: lockdep_register_key(&q->io_lock_cls_key);
453: lockdep_register_key(&q->q_lock_cls_key);
454: lockdep_init_map(&q->io_lockdep_map, "&q->q_usage_counter(io)",
455: &q->io_lock_cls_key, 0);
456: lockdep_init_map(&q->q_lockdep_map, "&q->q_usage_counter(queue)",
457: &q->q_lock_cls_key, 0);
458:
459: /* Teach lockdep about lock ordering (reclaim WRT queue freeze lock). */
460: fs_reclaim_acquire(GFP_KERNEL);
461: rwsem_acquire_read(&q->io_lockdep_map, 0, 0, _RET_IP_);
462: rwsem_release(&q->io_lockdep_map, _RET_IP_);
463: fs_reclaim_release(GFP_KERNEL);
464:
465: q->nr_requests = BLKDEV_DEFAULT_RQ;
466: q->async_depth = BLKDEV_DEFAULT_RQ;
467:
468: return q;
469:
470: fail_stats:
471: blk_free_queue_stats(q->stats);
472: fail_id:
473: ida_free(&blk_queue_ida, q->id);
474: fail_q:
475: kmem_cache_free(blk_requestq_cachep, q);
476: return ERR_PTR(error);
477: }
SourceFile:block/blk-core.c]
|
| 22/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 28001
output: 48
thoughts: 739
Thoughts: **Analyzing Lock Ordering in `blk_alloc_queue` and its Implications**
Okay, let's break this down. `blk_alloc_queue` explicitly uses `fs_reclaim` and `q->io_lockdep_map`, which acts as a read-write semaphore for queue freezing, to teach lockdep about the correct lock ordering. Specifically, this code snippet:
```c
/* Teach lockdep about lock ordering (reclaim WRT queue freeze lock). */
fs_reclaim_acquire(GFP_KERNEL);
rwsem_acquire_read(&q->io_lockdep_map, 0, 0, _RET_IP_);
rwsem_release(&q->io_lockdep_map, _RET_IP_);
fs_reclaim_release(GFP_KERNEL);
```
means `fs_reclaim` -> `q_usage_counter` - or at least, that's my initial interpretation. It's an explicit annotation. So, I can acquire `q_usage_counter` (which is what I'm calling the io_lockdep_map) while *holding* `fs_reclaim`. Wait, am I misinterpreting this? Yes, `rwsem_acquire_read` is called *while* holding `fs_reclaim`. Right, so `fs_reclaim` *happens before* `q_usage_counter`.
This implies that any code paths acquiring `q_usage_counter` could potentially be holding `fs_reclaim`. So, if I'm doing memory reclaim, I might need to write to a block device, and that *requires* `q_usage_counter`. Yes, the annotation makes sense. `fs_reclaim` -> `q_usage_counter` is the correct order.
Now, let's consider the next ordering: `q_usage_counter` -> `elevator_lock`. The second snippet shows a path to the `elevator_lock` via `blk_mq_update_nr_hw_queues`. I need to examine `blk_mq_update_nr_hw_queues` to understand this relationship completely.
|
| 23/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-mq.c IncludeLines:true Name:blk_mq_update_nr_hw_queues]
Results: map[SourceCode:5237: void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues)
5238: {
5239: down_write(&set->update_nr_hwq_lock);
5240: mutex_lock(&set->tag_list_lock);
5241: __blk_mq_update_nr_hw_queues(set, nr_hw_queues);
5242: mutex_unlock(&set->tag_list_lock);
5243: up_write(&set->update_nr_hwq_lock);
5244: }
SourceFile:block/blk-mq.c]
|
| 24/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 29456
output: 43
thoughts: 164
Thoughts: **Analyzing the Hardware Queue Update Process**
Okay, so I'm diving into this `__blk_mq_update_nr_hw_queues` function. It looks like it's connected to a chain: it calls `blk_mq_elv_switch_none`, which then calls `elevator_set_none`, and finally that calls `elevator_change`. That makes sense in terms of how the block layer handles hardware queue updates with the elevator.
But now I'm curious about something fundamental: where does `q_usage_counter` come into play in all of this? I'm missing the full picture of the locking involved.
Right, so in `__blk_mq_update_nr_hw_queues`, it freezes the queue using `blk_mq_freeze_queue(q)`. That's where it has to be! I need to be sure that it is acquired for *write*.
Ah, here it is. `blk_mq_freeze_queue` is where `q_usage_counter` is being manipulated. But the more I think about it, it looks like `blk_mq_freeze_queue` is waiting for `q_usage_counter` to drop to zero! That seems to imply it's *not* acquiring it in the typical lockdep sense, but rather a mechanism to ensure no activity on the queue before it's changed.
Alright, let's go check the source for `blk_mq_freeze_queue` and confirm my assumptions.
|
| 25/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-mq.c IncludeLines:true Name:blk_mq_freeze_queue]
Results: map[SourceCode: 951: static inline unsigned int __must_check
952: blk_mq_freeze_queue(struct request_queue *q)
953: {
954: unsigned int memflags = memalloc_noio_save();
955:
956: blk_mq_freeze_queue_nomemsave(q);
957: return memflags;
958: }
SourceFile:include/linux/blk-mq.h]
|
| 26/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 30128
output: 47
thoughts: 17
Thoughts: Okay, let's dive into this. Here's my take on those thoughts, as an expert in the field:
**Diving into `blk_mq_freeze_queue_nomemsave`**
Alright, time to get my hands dirty. I need to take a look at `blk_mq_freeze_queue_nomemsave`. Seems like a critical part of the block layer's queue management, particularly when dealing with memory constraints. I suspect this function plays a vital role in ensuring data integrity and responsiveness under pressure. I need to understand its exact purpose, how it interacts with the other queue management functions, and especially, how it handles situations where memory is scarce. I'll likely need to dissect its implementation, step-by-step, paying close attention to any locking mechanisms or atomics it employs. Gotta see how this interacts with other layers too, like the request handling and IO path. Specifically, I'm interested in how it affects the drivers. I'll need to know whether it's safe to call it from any context, and what implications it has for the rest of the system. Let's see if this is an efficient way of handling memory constraints for queue freezing, or if there's room for improvement.
|
| 27/2 |
2026/05/17 05:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-mq.c IncludeLines:true Name:blk_mq_freeze_queue_nomemsave]
Results: map[SourceCode: 204: void blk_mq_freeze_queue_nomemsave(struct request_queue *q)
205: {
206: blk_freeze_queue_start(q);
207: blk_mq_freeze_queue_wait(q);
208: }
SourceFile:block/blk-mq.c]
|
| 28/2 |
2026/05/17 05:35 |
llm |
expert |
0m
Model:
Tokens:
input: 30562
output: 43
thoughts: 13
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Investigating `blk_freeze_queue_start`**
Right, let's dive into this. The initial thought is to take a look at `blk_freeze_queue_start`. Seems like a sensible starting point when consideringβ¦ well, whatever problem or analysis we're currently focused on. I'm assuming that function plays a critical role in the queue freezing process, probably in the initiation stage. Itβs likely a good entry point to understand how things work at a low level, and it can help figure out the context of potential issues or areas for optimization. Gotta get my hands dirty and examine the internals here. Let's see whatβs going on...
|
| 29/2 |
2026/05/17 05:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-mq.c IncludeLines:true Name:blk_freeze_queue_start]
Results: map[SourceCode: 182: void blk_freeze_queue_start(struct request_queue *q)
183: {
184: if (__blk_freeze_queue_start(q, current))
185: blk_freeze_acquire_lock(q);
186: }
SourceFile:block/blk-mq.c]
|
| 30/2 |
2026/05/17 05:36 |
llm |
expert |
0m
Model:
Tokens:
input: 30893
output: 45
thoughts: 527
Thoughts: **Analyzing Lock Dependencies in the Block Layer**
Okay, let's break this down. My initial observation is that `blk_freeze_acquire_lock(q)` takes the lockdep map for `q_usage_counter` for write access. This means that when `blk_mq_freeze_queue` is called, it acquires `q_usage_counter` for write, and then `elevator_change` then acquires `elevator_lock`. Thus, we have the dependency `q_usage_counter` -> `elevator_lock`. That's the starting point.
Now, the interesting bit: From the call stack in #3, it's evident that `elevator_change`, while holding `elevator_lock`, calls `elevator_switch`, which then calls `synchronize_srcu(set->srcu)`. This function, in turn, acquires the lockdep map for `set->srcu`. So, we get the dependency `elevator_lock` -> `set->srcu`. Makes sense β you're syncing against srcu while protected by the elevator lock.
The next step is where things get a bit more involved. The call stack in #4 shows that `blk_mq_dispatch_rq_list` acquires `&cmd->lock` after the call to `synchronize_srcu`. This suggests we're seeing `set->srcu` -> `&cmd->lock`. However, it's not immediately clear where `set->srcu` is acquired in relation to `blk_mq_dispatch_rq_list`. Is `set->srcu` acquired *before* the call to `blk_mq_dispatch_rq_list`, or is it acquired inside that function? We need to look at the surrounding code. My gut tells me we'll find the answer in `blk_mq_run_hw_queue`, but let's confirm the flow. We need to trace where the `set->srcu` comes from, to verify the lock acquisition order.
|
| 31/2 |
2026/05/17 05:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-mq.c IncludeLines:true Name:blk_mq_run_hw_queue]
Results: map[SourceCode:2343: /**
2344: * blk_mq_run_hw_queue - Start to run a hardware queue.
2345: * @hctx: Pointer to the hardware queue to run.
2346: * @async: If we want to run the queue asynchronously.
2347: *
2348: * Check if the request queue is not in a quiesced state and if there are
2349: * pending requests to be sent. If this is true, run the queue to send requests
2350: * to hardware.
2351: */
2352: void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
2353: {
2354: bool need_run;
2355:
2356: /*
2357: * We can't run the queue inline with interrupts disabled.
2358: */
2359: WARN_ON_ONCE(!async && in_interrupt());
2360:
2361: might_sleep_if(!async && hctx->flags & BLK_MQ_F_BLOCKING);
2362:
2363: need_run = blk_mq_hw_queue_need_run(hctx);
2364: if (!need_run) {
2365: unsigned long flags;
2366:
2367: /*
2368: * Synchronize with blk_mq_unquiesce_queue(), because we check
2369: * if hw queue is quiesced locklessly above, we need the use
2370: * ->queue_lock to make sure we see the up-to-date status to
2371: * not miss rerunning the hw queue.
2372: */
2373: spin_lock_irqsave(&hctx->queue->queue_lock, flags);
2374: need_run = blk_mq_hw_queue_need_run(hctx);
2375: spin_unlock_irqrestore(&hctx->queue->queue_lock, flags);
2376:
2377: if (!need_run)
2378: return;
2379: }
2380:
2381: if (async || !cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask)) {
2382: blk_mq_delay_run_hw_queue(hctx, 0);
2383: return;
2384: }
2385:
2386: blk_mq_run_dispatch_ops(hctx->queue,
2387: blk_mq_sched_dispatch_requests(hctx));
2388: }
SourceFile:block/blk-mq.c]
|
| 32/2 |
2026/05/17 05:36 |
llm |
expert |
0m
Model:
Tokens:
input: 32652
output: 45
thoughts: 37
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating a Potential Locking Issue in blk-mq Dispatch**
Hmm, hold on a second. I'm seeing a reference to `blk_mq_run_dispatch_ops` acquiring `set->srcu`? That doesn't immediately jump out as expected. Given the potential for concurrency and the intricacies of the block layer, I need to verify that interaction. My immediate next step is to drill down into the implementation of `blk_mq_run_dispatch_ops`. I need to confirm *why* and *how* `set->srcu` is being acquired there. Is it for read-side protection, for write-side updates, or something else entirely? And crucially, what is the scope of that lock, and what critical sections are being protected? Understanding that context is vital to ensuring correctness and avoiding potential deadlocks or performance bottlenecks in the IO path. This requires a deeper dive to understand the nuances of the memory management and concurrency mechanisms employed within `blk-mq`.
|
| 33/2 |
2026/05/17 05:36 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:block/blk-mq.c IncludeLines:true Name:blk_mq_run_dispatch_ops]
Results: map[SourceCode: SourceFile:]
|
| 34/2 |
2026/05/17 05:36 |
llm |
expert |
0m
Model:
Tokens:
input: 32982
output: 25
thoughts: 31
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing the Macro**
Alright, this is a macro. My initial instinct is to pinpoint its definition within the kernel's block layer, specifically. I'm going to jump straight into the likely candidates for the header file containing it. Given the context of a macro related to the block layer, my first targets are `include/linux/blk-mq.h` or, perhaps, `block/blk-mq.h`. I'll start with those and see what I can find. No need to waste time scanning unrelated headers - let's go straight to the block multi-queue implementation files.
|
| 35/2 |
2026/05/17 05:36 |
tool |
grepper |
0m
Args: map[Expression:define blk_mq_run_dispatch_ops]
Results: map[Output:block/blk-mq.h=440=do { \
--
block/blk-mq.h-455-
block/blk-mq.h:456:#define blk_mq_run_dispatch_ops(q, dispatch_ops) \
block/blk-mq.h-457- __blk_mq_run_dispatch_ops(q, true, dispatch_ops) \
]
|
| 36/2 |
2026/05/17 05:36 |
llm |
expert |
0m
Model:
Tokens:
input: 33294
output: 25
thoughts: 16
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Diving into `__blk_mq_run_dispatch_ops`**
Alright, time to dig into this. I see the starting point is `__blk_mq_run_dispatch_ops`. That's where the magic happens, or at least, a significant part of it. I'm immediately thinking, "What's the context here? What are we trying to achieve?". This function is the core of dispatching operations. I'm keen to understand how it's orchestrating those interactions within the block layer, and, how the queues are working at this level. This function is likely crucial for performance and understanding where bottlenecks might arise. Let's see what we find.
|
| 37/2 |
2026/05/17 05:36 |
tool |
grepper |
0m
Args: map[Expression:define __blk_mq_run_dispatch_ops]
Results: map[Output:block/blk-mq.h=403=static inline bool hctx_may_queue(struct blk_mq_hw_ctx *hctx,
--
block/blk-mq.h-438-/* run the code block in @dispatch_ops with rcu/srcu read lock held */
block/blk-mq.h:439:#define __blk_mq_run_dispatch_ops(q, check_sleep, dispatch_ops) \
block/blk-mq.h-440-do { \
]
|
| 38/2 |
2026/05/17 05:36 |
llm |
expert |
0m
Model:
Tokens:
input: 33644
output: 43
thoughts: 3265
Thoughts: **Analyzing a Potential Deadlock in the NBD Driver**
My initial thought process began with tracing lock acquisition sequences within the NBD (Network Block Device) driver and related subsystems, focusing on a potential deadlock scenario. I started by following the execution path from `__blk_mq_run_dispatch_ops`, which involves acquiring an SRCU read lock (`set->srcu`) before calling `blk_mq_sched_dispatch_requests(hctx)`. This then led me to `nbd_queue_rq` within the NBD driver, which acquires `cmd->lock` and ultimately `nsock->tx_lock`. From there, the dependency chain continues: `nsock->tx_lock` to `sk_lock-AF_INET6` (the socket lock) through functions like `sock_shutdown` and finally to `&mm->mmap_lock` via `rawv6_sendmsg` and operations that can trigger page faults and subsequently memory allocation, potentially calling functions like `dump_user_range` which ends up acquiring `mmap_lock` which then is dependent on `fs_reclaim`. I see a complete cycle: `fs_reclaim` -> `q_usage_counter` -> `elevator_lock` -> `set->srcu` -> `cmd->lock` -> `nsock->tx_lock` -> `sk_lock` -> `mmap_lock` -> `fs_reclaim`.
My concern was whether this seemingly cyclical locking order could lead to a deadlock. I carefully analyzed the nature of each lock involved: `fs_reclaim` represents memory allocation, `q_usage_counter` is a percpu_ref that acts as a read-write lock, `elevator_lock` is a mutex, `set->srcu` is an SRCU, `cmd->lock` and `nsock->tx_lock` are mutexes, `sk_lock` is a mutex (socket lock), and `mmap_lock` is a reader-writer semaphore (rwsem).
To determine the likelihood of a deadlock, I considered a scenario where `dump_user_range` on one CPU holds `mmap_lock` (read) and initiates memory allocation, which then might lead to direct memory reclaim, submitting I/O requests. This reclaim path could then involve the NBD device. In this path, the direct memory reclaim could acquire the other locks: `q_usage_counter`, `set->srcu`, `cmd->lock` and `nsock->tx_lock`. I analyzed how the memory reclaim path interacted with the NBD driver and considered that direct memory reclaim does not acquire `elevator_lock`, however it can acquire the other locks previously mentioned, and thus there might be a chain of I/O submit that eventually involves the I/O path.
I then considered what if, on a separate CPU, `sock_shutdown` acquires `nsock->tx_lock` and then the socket lock `sk_lock`. It is at this point that a 3-way deadlock condition emerges. I am specifically interested in how the socket lock is utilized, and the potential conflict.
Specifically, if a user passes a raw IPv6 socket, and if another thread calls `rawv6_sendmsg` on this socket, a deadlock can occur. `rawv6_sendmsg` acquires `sk_lock` which is needed during direct memory reclaim via an NBD I/O path. In this path, there are three threads: The first that runs `rawv6_sendmsg` and which acquires `sk_lock`, the second that runs direct reclaim and submits I/O to the NBD driver and acquires `mmap_lock`, and the third that runs `sock_shutdown` and tries to acquire `nsock->tx_lock`. So the deadlock occurs: CPU0 holds `sk_lock` and waits for `mmap_lock`, CPU1 holds `mmap_lock` and waits for `nsock->tx_lock`, CPU2 holds `nsock->tx_lock` and waits for `sk_lock`.
In summary, the crux of the deadlock revolves around the shared usage of a socket by the NBD driver and another process that can directly communicate with the socket, potentially through `rawv6_sendmsg`, coupled with the interactions of direct memory reclaim and socket operation.
|
| 39/2 |
2026/05/17 05:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:nbd_send_cmd]
Results: map[SourceCode: 641: /*
642: * Returns BLK_STS_RESOURCE if the caller should retry after a delay.
643: * Returns BLK_STS_IOERR if sending failed.
644: */
645: static blk_status_t nbd_send_cmd(struct nbd_device *nbd, struct nbd_cmd *cmd,
646: int index)
647: {
648: struct request *req = blk_mq_rq_from_pdu(cmd);
649: struct nbd_config *config = nbd->config;
650: struct nbd_sock *nsock = config->socks[index];
651: int result;
652: struct nbd_request request = {.magic = htonl(NBD_REQUEST_MAGIC)};
653: struct kvec iov = {.iov_base = &request, .iov_len = sizeof(request)};
654: struct iov_iter from;
655: struct bio *bio;
656: u64 handle;
657: u32 type;
658: u32 nbd_cmd_flags = 0;
659: int sent = nsock->sent, skip = 0;
660:
661: lockdep_assert_held(&cmd->lock);
662: lockdep_assert_held(&nsock->tx_lock);
663:
664: iov_iter_kvec(&from, ITER_SOURCE, &iov, 1, sizeof(request));
665:
666: type = req_to_nbd_cmd_type(req);
667: if (type == U32_MAX)
668: return BLK_STS_IOERR;
669:
670: if (rq_data_dir(req) == WRITE &&
671: (config->flags & NBD_FLAG_READ_ONLY)) {
672: dev_err_ratelimited(disk_to_dev(nbd->disk),
673: "Write on read-only\n");
674: return BLK_STS_IOERR;
675: }
676:
677: if (req->cmd_flags & REQ_FUA)
678: nbd_cmd_flags |= NBD_CMD_FLAG_FUA;
679: if ((req->cmd_flags & REQ_NOUNMAP) && (type == NBD_CMD_WRITE_ZEROES))
680: nbd_cmd_flags |= NBD_CMD_FLAG_NO_HOLE;
681:
682: /* We did a partial send previously, and we at least sent the whole
683: * request struct, so just go and send the rest of the pages in the
684: * request.
685: */
686: if (sent) {
687: if (sent >= sizeof(request)) {
688: skip = sent - sizeof(request);
689:
690: /* initialize handle for tracing purposes */
691: handle = nbd_cmd_handle(cmd);
692:
693: goto send_pages;
694: }
695: iov_iter_advance(&from, sent);
696: } else {
697: cmd->cmd_cookie++;
698: }
699: cmd->index = index;
700: cmd->cookie = nsock->cookie;
701: cmd->retries = 0;
702: request.type = htonl(type | nbd_cmd_flags);
703: if (type != NBD_CMD_FLUSH) {
704: request.from = cpu_to_be64((u64)blk_rq_pos(req) << 9);
705: request.len = htonl(blk_rq_bytes(req));
706: }
707: handle = nbd_cmd_handle(cmd);
708: request.cookie = cpu_to_be64(handle);
709:
710: trace_nbd_send_request(&request, nbd->index, blk_mq_rq_from_pdu(cmd));
711:
712: dev_dbg(nbd_to_dev(nbd), "request %p: sending control (%s@%llu,%uB)\n",
713: req, nbdcmd_to_ascii(type),
714: (unsigned long long)blk_rq_pos(req) << 9, blk_rq_bytes(req));
715: result = sock_xmit(nbd, index, 1, &from,
716: (type == NBD_CMD_WRITE) ? MSG_MORE : 0, &sent);
717: trace_nbd_header_sent(req, handle);
718: if (result < 0) {
719: if (was_interrupted(result)) {
720: /* If we haven't sent anything we can just return BUSY,
721: * however if we have sent something we need to make
722: * sure we only allow this req to be sent until we are
723: * completely done.
724: */
725: if (sent) {
726: nbd_sched_pending_work(nbd, nsock, cmd, sent);
727: return BLK_STS_OK;
728: }
729: set_bit(NBD_CMD_REQUEUED, &cmd->flags);
730: return BLK_STS_RESOURCE;
731: }
732: dev_err_ratelimited(disk_to_dev(nbd->disk),
733: "Send control failed (result %d)\n", result);
734: goto requeue;
735: }
736: send_pages:
737: if (type != NBD_CMD_WRITE)
738: goto out;
739:
740: bio = req->bio;
741: while (bio) {
742: struct bio *next = bio->bi_next;
743: struct bvec_iter iter;
744: struct bio_vec bvec;
745:
746: bio_for_each_segment(bvec, bio, iter) {
747: bool is_last = !next && bio_iter_last(bvec, iter);
748: int flags = is_last ? 0 : MSG_MORE;
749:
750: dev_dbg(nbd_to_dev(nbd), "request %p: sending %d bytes data\n",
751: req, bvec.bv_len);
752: iov_iter_bvec(&from, ITER_SOURCE, &bvec, 1, bvec.bv_len);
753: if (skip) {
754: if (skip >= iov_iter_count(&from)) {
755: skip -= iov_iter_count(&from);
756: continue;
757: }
758: iov_iter_advance(&from, skip);
759: skip = 0;
760: }
761: result = sock_xmit(nbd, index, 1, &from, flags, &sent);
762: if (result < 0) {
763: if (was_interrupted(result)) {
764: nbd_sched_pending_work(nbd, nsock, cmd, sent);
765: return BLK_STS_OK;
766: }
767: dev_err(disk_to_dev(nbd->disk),
768: "Send data failed (result %d)\n",
769: result);
770: goto requeue;
771: }
772: /*
773: * The completion might already have come in,
774: * so break for the last one instead of letting
775: * the iterator do it. This prevents use-after-free
776: * of the bio.
777: */
778: if (is_last)
779: break;
780: }
781: bio = next;
782: }
783: out:
784: trace_nbd_payload_sent(req, handle);
785: nsock->pending = NULL;
786: nsock->sent = 0;
787: __set_bit(NBD_CMD_INFLIGHT, &cmd->flags);
788: return BLK_STS_OK;
789:
790: requeue:
791: /*
792: * Can't requeue in case we are dealing with partial send
793: *
794: * We must run from pending work function.
795: * */
796: if (test_bit(NBD_CMD_PARTIAL_SEND, &cmd->flags))
797: return BLK_STS_OK;
798:
799: /* retry on a different socket */
800: dev_err_ratelimited(disk_to_dev(nbd->disk),
801: "Request send failed, requeueing\n");
802: nbd_mark_nsock_dead(nbd, nsock, 1);
803: nbd_requeue_cmd(cmd);
804: return BLK_STS_OK;
805: }
SourceFile:drivers/block/nbd.c]
|
| 40/2 |
2026/05/17 05:36 |
llm |
expert |
0m
Model:
Tokens:
input: 40589
output: 41
thoughts: 91
Thoughts: **My Line of Inquiry: Data Transmission and Lock Acquisition**
Okay, let's break this down. My initial thought process is centered around how data transmission occurs, specifically within the kernel. The code shows `sock_xmit` calling `sock_sendmsg`. Now, my immediate question, as always, is about locking. Does `sock_sendmsg` itself handle the acquisition of the `sk_lock`?
Generally, `sock_sendmsg` seems to delegate the heavy lifting to protocol-specific functions. Think `tcp_sendmsg` for TCP or `unix_stream_sendmsg` for Unix domain sockets. And, aha, it appears that `tcp_sendmsg` *does* take care of acquiring that `sk_lock`.
Wait a minute, I have a different use case. Now, I should be thinking about the `sock_xmit` function within the NBD context. I need to trace my steps back to see how the processes are handled differently. I'll need to figure out how `sock_xmit` in the NBD context deals with its locking to avoid any potential concurrency issues.
|
| 41/2 |
2026/05/17 05:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:sock_xmit]
Results: map[SourceCode: 595: /*
596: * Send or receive packet. Return a positive value on success and
597: * negtive value on failure, and never return 0.
598: */
599: static int sock_xmit(struct nbd_device *nbd, int index, int send,
600: struct iov_iter *iter, int msg_flags, int *sent)
601: {
602: struct nbd_config *config = nbd->config;
603: struct socket *sock = config->socks[index]->sock;
604:
605: return __sock_xmit(nbd, sock, send, iter, msg_flags, sent);
606: }
SourceFile:drivers/block/nbd.c]
|
| 42/2 |
2026/05/17 05:37 |
llm |
expert |
0m
Model:
Tokens:
input: 41194
output: 42
thoughts: 8
Thoughts: Okay, here's my summary, in the first person, as if these were my thoughts, and tailored for an expert audience:
**Analyzing the `__sock_xmit` Function**
Alright, let's break down this `__sock_xmit` situation. From my understanding, this is a critical low-level function, right? It's the lynchpin for pushing data out of a socket, and it's essential for performance, especially in high-throughput network applications. My primary concern is always around how it interacts with the underlying network interface card (NIC) and, of course, the interrupt handling.
I'm focusing on these key aspects:
* **Data Aggregation & Packetization:** I immediately start pondering the buffering strategies within `__sock_xmit`. Are we talking about scatter-gather I/O? What are the limitations in terms of Maximum Transmission Unit (MTU) considerations and fragmentation/reassembly overhead? I'm trying to see if it efficiently handles coalescing smaller writes into larger packets where possible, without introducing excessive latency. I am also thinking about the interplay with the TCP segmentation offload (TSO) or UDP fragmentation offload (UFO) capabilities, which would have a significant impact on CPU utilization.
* **Locking & Concurrency:** The use of locks is a critical point. Is this function designed to handle multiple threads or processes writing to the same socket? If so, what locking mechanisms are being employed (spinlocks, mutexes, RCU, etc.) and what potential bottlenecks or contention issues might be present? I'm always looking for opportunities to improve the efficiency of concurrency control here.
* **Hardware Interaction:** This is where things get really interesting. How does `__sock_xmit` interface with the NIC's transmit descriptors or queues? Is DMA being used effectively, or is there unnecessary CPU involvement in data copying? I will also evaluate how the function handles the interrupt signaling upon transmission completion. Is there interrupt coalescing happening to reduce interrupt overhead, or is it a source of excessive interrupts? In the context of modern NICs, are there any interactions with features like checksum offloading, TCP segmentation offload, or receive-side scaling?
* **Error Handling:** It will be important to analyze how `__sock_xmit` handles various error conditions. What happens if the transmit queue is full? What's the recovery strategy for transient network errors? I am especially interested in understanding how the function communicates errors back to the application layer. Are errors reported synchronously, or asynchronously through callbacks or socket options?
* **Performance Metrics:** Finally, I'm always thinking about the performance implications. What metrics are being tracked (bytes transmitted, packets transmitted, queue length, etc.)? Are there any hooks or tracing capabilities to help diagnose performance bottlenecks in the send path? I'd want to use these metrics to optimize the send path further.
|
| 43/2 |
2026/05/17 05:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/nbd.c IncludeLines:true Name:__sock_xmit]
Results: map[SourceCode: 551: static int __sock_xmit(struct nbd_device *nbd, struct socket *sock, int send,
552: struct iov_iter *iter, int msg_flags, int *sent)
553: {
554: int result;
555: struct msghdr msg = {} ;
556: unsigned int noreclaim_flag;
557:
558: if (unlikely(!sock)) {
559: dev_err_ratelimited(disk_to_dev(nbd->disk),
560: "Attempted %s on closed socket in sock_xmit\n",
561: (send ? "send" : "recv"));
562: return -EINVAL;
563: }
564:
565: msg.msg_iter = *iter;
566:
567: noreclaim_flag = memalloc_noreclaim_save();
568:
569: scoped_with_kernel_creds() {
570: do {
571: sock->sk->sk_allocation = GFP_NOIO | __GFP_MEMALLOC;
572: sock->sk->sk_use_task_frag = false;
573: msg.msg_flags = msg_flags | MSG_NOSIGNAL;
574:
575: if (send)
576: result = sock_sendmsg(sock, &msg);
577: else
578: result = sock_recvmsg(sock, &msg, msg.msg_flags);
579:
580: if (result <= 0) {
581: if (result == 0)
582: result = -EPIPE; /* short read */
583: break;
584: }
585: if (sent)
586: *sent += result;
587: } while (msg_data_left(&msg));
588: }
589:
590: memalloc_noreclaim_restore(noreclaim_flag);
591:
592: return result;
593: }
SourceFile:drivers/block/nbd.c]
|
| 44/2 |
2026/05/17 05:37 |
llm |
expert |
0m
Model:
Tokens:
input: 42490
output: 44
thoughts: 5171
Thoughts: **Analysis of Potential Deadlock in NBD over IPv6 with Lockdep**
Okay, so I've been tracing the execution path of `sock_sendmsg` and how it interacts with the NBD (Network Block Device) driver, specifically in the context of IPv6. My initial thought was that a direct call from userspace to `rawv6_sendmsg` might be problematic, and it turns out, I was right. I'm seeing a potential for lock contention between the NBD driver and another process that might be using the *same* IPv6 socket.
The core of the problem lies in the locking order. The NBD path, from `nbd_queue_rq` through `sock_sendmsg` eventually ends up calling `rawv6_sendmsg`, which grabs `sk_lock`. Now, lockdep reports that `sk_lock` could be acquired while holding the `nsock->tx_lock`. So, the worry is that if another process calls `rawv6_sendmsg` directly on the same socket, it'll acquire `sk_lock`, and if it then blocks waiting on `mmap_lock` (because it's doing something like `copy_from_user` to send data), this will get messy.
The real concern is that if a process acquires `sk_lock` then waits for `mmap_lock`, and another thread is submitting an NBD request that needs `nsock->tx_lock` *and* the `sk_lock`, it is a deadlock. I realized that a process can acquire a lock on an AF_INET6 socket (i.e. `sk_lock-AF_INET6`), then trigger a page fault, and then get into memory reclaim and submit a bio to NBD.
This is a potential deadlock!
I kept thinking, can an unprivileged user trigger this? After going through it and checking the code, it looks like only root can set up the NBD device using `nbd_genl_connect`, right? If root creates the NBD device, passes the socket to it, and then some unprivileged process tries to send something on that same socket, it is possible for a deadlock to happen. However, it's a privileged user "shooting themselves in the foot" type of thing; root has the power to cause a deadlock if they *want* to.
I then considered what happens if the root sets up the device, but the socket is accessible to the unprivileged process. And then what if a privileged process drops privileges? This raised another concern if the process that set up NBD does not drop privileges, but a second thread starts sending data on the device, as that may cause an issue.
Then I realized that `nbd-client` typically creates the socket and passes it to the kernel via netlink, which the unprivileged user should not have access to, and `nbd-client` usually does not call `sendmsg` on that socket and so it's not likely to happen. However, a page fault could occur from an unprivileged user with access to the socket and trigger the chain.
It then became clear, based on the lockdep report, that itβs all about the *same* socket, or at least the same lock class. Lockdep doesn't distinguish between different sockets if they belong to the same lock class. So the lockdep report is complaining about the potential for a deadlock involving *any* AF_INET6 socket.
And this brought me back around. I was wrong about it being the *same* socket and the result depends on how the sockets are being used! It is a *potential* deadlock, not a *real* deadlock unless two threads hold the *same* socket lock and wait for the lock.
It looks like the 4-way deadlock is not likely, because `nbd-client` (root-level privilege) does not call `sendmsg` on the socket that is being used by the kernel, but if a process does, and it faults, then there may be an issue.
However, a lockdep warning itself is dangerous in some cases. Since lockdep is enabled in debug builds, if the system is configured to panic on warnings, there is a Denial of Service. Also, debug tools may be used by an attacker. However, this is a debug tool that is disabled in production builds. Since a real deadlock is very unlikely, the result is that the vulnerability is of low priority.
Okay, let's step back, and re-check, is it truly a false positive? No real deadlock, or maybe. Itβs a lockdep false positive if the socket and the NBD socket are different.
What if there's a loopback TCP connection for the NBD server? The server is unprivileged, reading from a *different* socket, the client and server sockets being different.
|
| 45/2 |
2026/05/17 05:37 |
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]
|
| 46/2 |
2026/05/17 05:37 |
llm |
expert |
1m
Model:
Tokens:
input: 51617
output: 66
thoughts: 1554
Thoughts: **Analysis of the NBD Lockdep Warning**
Okay, let's break this down systematically. First, I checked how the Network Block Device (NBD) setup is handled β it requires `CAP_SYS_ADMIN` through `netlink_capable` and `nbd_ioctl`, which means initial user namespace root is the only one who can touch it. So, that immediately rules out unprivileged processes and user namespaces.
The core of the issue is a lockdep warning, which is just a debugging tool. It's not a real deadlock, so no exploitable denial-of-service here. Let's fill out the results based on this: Exploitable: False, DenialOfService: False, Unprivileged: False, UserNamespace: False. Given it's a block device, not some VM feature, VMGuestTrigger and VMHostTrigger are also False. NetworkTrigger is False as setup is required, RemoteTrigger, PeripheralTrigger, and FilesystemTrigger are all False based on the above information.
However, a quick thought about a malicious filesystem came to mind. Even if root mounted a malicious filesystem on an NBD device and it somehow triggered memory reclaim, the lockdep warning is specifically about the NBD device itself, not the filesystem. So, FilesystemTrigger is False.
Now, let's dive back into the lockdep warning itself. Could there be a different path to the deadlock of `sk_lock` and `mmap_lock`? If a process holds `mmap_lock` and calls `sendmsg`, no. `sendmsg` is a syscall and locks aren't held across syscalls unless an ioctl is involved, but that's not the case here. Conversely, if a process holds `sk_lock` and triggers a page fault... ah, yes, `rawv6_sendmsg` can do that with `copy_from_user`, where a page fault acquires `mmap_lock`. This matches the classic "reclaim depends on network" issue.
The usual order: `sk_lock` (held by `rawv6_sendmsg`) -> `copy_from_user` -> page fault -> `mmap_lock`.
The reverse order: reclaim acquires `mmap_lock` via `fs_reclaim` which submits a bio to NBD which acquires `sk_lock`.
The common mitigation is setting `sk_allocation` to `GFP_NOIO` or `__GFP_MEMALLOC` on the socket, and it seems NBD sockets *do* have this. But lockdep is about the locks, not memory flags. It doesn't know about `GFP_NOIO`.
Lockdep *does* know about `fs_reclaim`. It sees that when a lock is acquired during direct reclaim, then the lock is recorded as `fs_reclaim` -> `lock`. If a lock can be acquired during reclaim, but isn't actually held, lockdep will complain about the cycle.
So we have: `fs_reclaim` -> ... -> `sk_lock` (via NBD calling `sock_sendmsg` during reclaim). Then, `rawv6_sendmsg` grabs `sk_lock`, then `copy_from_user` might fault and acquire `mmap_lock`. So `sk_lock` -> `mmap_lock`. And `mmap_lock` can be held during `fs_reclaim`. This gives the cycle: `fs_reclaim` -> `sk_lock` -> `mmap_lock` -> `fs_reclaim`.
But is this a real deadlock? Process A holds its `mmap_lock`, enters reclaim, waits for the NBD socket's `sk_lock`. Process B holds the NBD socket's `sk_lock`, does `copy_from_user`, and waits for *its own* `mmap_lock`. Hey! Process B is waiting for *its own* `mmap_lock`. They are different! So Process B can proceed and will eventually release the `sk_lock`. No deadlock.
The problem is lockdep merges instances of `mmap_lock` and `sk_lock` into single lock classes. This is a known limitation that leads to false positives when there are multiple instances, but no actual cycle between *specific* instances. The fix? Kernel can use different lock classes for NBD sockets, different `mmap_lock` lock classes for different processes (which is not doable), or just ignore it.
A possible fix could be that if NBD sockets are not exposed to user space while in use, which means `sk_lock` isn't ever held while waiting for `mmap_lock`.
Wait, does the NBD kernel thread do `copy_from_user`? No, it uses `sock_xmit` with `
|
| 47/2 |
2026/05/17 05:39 |
tool |
set-results |
0m
Args: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:false Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 48/2 |
2026/05/17 05:39 |
llm |
expert |
0m
Model:
Tokens:
input: 54326
output: 635
thoughts: 505
Thoughts: **Final Response: Lockdep False Positive Analysis**
Okay, the analysis is done, and it's time to craft the final response. This lockdep warning is about a potential circular locking dependency, and after digging into it, I've got a pretty good handle on what's going on.
The cycle, as the warning flags, is this: `fs_reclaim` -> `q_usage_counter` -> `elevator_lock` -> `set->srcu` -> `cmd->lock` -> `nsock->tx_lock` -> `sk_lock-AF_INET6` -> `mmap_lock` -> back to `fs_reclaim`. Clearly, a nasty looking chain! But, it's a false positive, and here's why.
The crux of the issue boils down to how lockdep handles lock classes. It's merging things it shouldn't be. Specifically:
1. We've got a user-space process calling `sendmsg` on an IPv6 socket. This acquires the socket lock (`sk_lock-AF_INET6`) and then triggers a page fault when it's doing `copy_from_user`, so it acquires `mmap_lock`.
2. Now, the page fault allocates memory, which goes through memory reclaim, and this ends up taking `fs_reclaim`. This establishes the cycle through an `mmap_lock` to `fs_reclaim` dependency.
3. On the other side, we've got memory reclaim, which needs to submit a bio to a Network Block Device (NBD) over IPv6. To do that, it needs to use the NBD socket lock (`sk_lock-AF_INET6`). And boom, the cycle is complete.
The problem, though, is that lockdep thinks these `sk_lock-AF_INET6` instances are the *same* lock, and similarly for the `mmap_lock`s. In reality:
* The NBD socket is *only* used by the kernel via `sock_xmit` and kernel vectors/bvecs. It *never* triggers user-space page faults, so that `sk_lock` never waits on `mmap_lock`. The sendmsg use case is *user* space.
* The socket that triggers the user-space page fault for the original `sendmsg` call is *different* from the NBD socket. Distinct instance, and the locks are separate.
* The `mmap_lock` used during memory reclaim belongs to the *reclaiming process*, and it is completely independent of the process that called `sendmsg`.
Therefore, there's no actual deadlock possible because the locks involved are distinct instances, not the same one as lockdep is inferring. Further, setting up an NBD device requires `CAP_SYS_ADMIN` in the initial user namespace. This makes the NBD part of the chain impossible to establish by unprivileged users or from inside user namespaces. So, even if the locks *were* the same, the sequence couldn't happen under normal circumstances. Finally, and this is important, lockdep is a debugging tool. It's *disabled* in production builds, so this warning has zero impact on real-world systems.
With this understanding, I can now craft a solid response that explains this and provides the appropriate context to understand why this is a non-issue.
|
| 49/1 |
2026/05/17 05:39 |
action |
format-explanation |
0m
Results: map[Explanation:**Analysis:**
The bug report is a `lockdep` warning indicating a possible circular locking
dependency. The reported dependency chain is:
`fs_reclaim` -> `q_usage_counter` -> `elevator_lock` -> `set->srcu` ->
`cmd->lock` -> `nsock->tx_lock` -> `sk_lock-AF_INET6` -> `mmap_lock` ->
`fs_reclaim`.
This is a classic lockdep false positive caused by lock class merging, rather
than a real deadlock:
1. **`sk_lock-AF_INET6` -> `mmap_lock`**: This dependency is established when a
user-space process calls `sendmsg` on a standard IPv6 socket. The kernel
acquires the socket lock (`sk_lock`) and then performs `copy_from_user`, which
can trigger a page fault and acquire the process's `mmap_lock`.
2. **`mmap_lock` -> `fs_reclaim`**: This is established when a process takes a
page fault (holding `mmap_lock`) and needs to allocate memory, thus entering the
memory reclaim path (`fs_reclaim`).
3. **`fs_reclaim` -> ... -> `sk_lock-AF_INET6`**: This is established when the
system is under memory pressure and direct reclaim submits a bio to a Network
Block Device (NBD) configured over IPv6. The NBD driver processes the request
and acquires the NBD socket's lock (`sk_lock`) to transmit the data.
Lockdep reports a cycle because it groups all IPv6 socket locks into a single
lock class (`sk_lock-AF_INET6`) and all memory map locks into another
(`mmap_lock`). However, in reality, no deadlock can occur because:
* The socket used by NBD is a different instance from the socket used by the
user-space process.
* The NBD kernel thread transmits data using kernel vectors (`kvec` or `bvec`),
which do not fault. Therefore, the NBD socket's `sk_lock` is never held while
waiting for an `mmap_lock`.
* The `mmap_lock` instances belong to different processes.
Furthermore, the NBD device setup (which establishes the reclaim-to-socket
dependency) is strictly privileged. The `nbd_genl_connect` and `nbd_ioctl`
interfaces explicitly check for `CAP_SYS_ADMIN` in the initial user namespace
(`init_user_ns`), meaning unprivileged users and users inside user namespaces
cannot configure NBD devices.
Since this is a false positive lockdep warning, and lockdep is a debugging
feature that is disabled in production builds, this bug has no security impact,
cannot be exploited, and does not cause a denial of service.
**Conclusion:**
The issue is a non-exploitable false positive in a debug tool (lockdep) that
requires global root privileges to even establish the necessary lock chains.]
|