| 0/0 |
2026/09/02 01:02 |
flow |
assessment-security |
36m
Results: map[DenialOfService:true Explanation:The bug report describes a "sleeping function called from invalid context" in
the `null_blk` block device driver.
### Root Cause Analysis
The `null_blk` driver is a test block driver that can be configured to simulate
various storage device behaviors. It can be configured to store data in memory
by setting the `memory_backed` option. When `memory_backed` is enabled, the
driver allocates memory pages during request processing using `kmalloc_obj(...,
GFP_NOIO)` and `alloc_pages(GFP_NOIO, ...)`, which can sleep.
To safely sleep during request processing, the block layer must be informed that
the driver's queue operations may block. This is done by setting the
`BLK_MQ_F_BLOCKING` flag on the device's tag set. If this flag is set, the block
layer's dispatch loop (`blk_mq_run_dispatch_ops`) uses `srcu_read_lock()`, which
allows sleeping. If the flag is not set, it uses `rcu_read_lock()`, which
disables preemption and creates an atomic context where sleeping is invalid.
The bug occurs due to a mismatch in configuration when using **shared tags**
(`shared_tags=1`). When shared tags are enabled, the driver uses a single global
tag set (`tag_set`) for all devices. This global tag set is initialized based on
the global module parameter `g_blocking` (which defaults to `false`).
If a user creates a `null_blk` device via `configfs` with `memory_backed=1` and
`shared_tags=1`, the device requires blocking operations (because it allocates
memory), but the global tag set it uses does not have the `BLK_MQ_F_BLOCKING`
flag set (because `g_blocking` was false).
As a result, the block layer dispatches requests to the driver under an RCU read
lock. When the driver attempts to allocate memory in `null_alloc_page()`, it
sleeps while holding the RCU lock, triggering the `BUG: sleeping function called
from invalid context`.
### Security Impact
* **Exploitable:** No. This is a context violation (sleeping in atomic context)
that triggers a kernel warning or panic. It does not cause memory corruption,
use-after-free, or out-of-bounds accesses that could be leveraged for privilege
escalation or information leaks.
* **Denial of Service:** Yes. Depending on the kernel configuration (e.g.,
`CONFIG_PANIC_ON_WARN`), this can crash the system or lead to RCU stalls.
* **Accessible From Unprivileged Processes / User Namespaces:** No. The
`null_blk` driver is configured either via module parameters at load time or via
`configfs` (typically mounted at `/sys/kernel/config`). Both actions require
root privileges (`CAP_SYS_MODULE` or root access to `configfs`). `configfs`
cannot be mounted inside unprivileged user namespaces.
* **Other Triggers:** This bug is not triggerable via network, remote,
peripheral, or malicious filesystem vectors. It is strictly a local
configuration issue in a test driver.
In conclusion, this is a local Denial of Service bug that can only be triggered
by a privileged user (root) misconfiguring a test driver. It poses no security
risk to production systems from unprivileged attackers. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/09/02 01:02 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/09/02 01:02 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/99ca6cb848fa347342812aa5a34fe8ede7bb9369]
|
| 3/1 |
2026/09/02 01:03 |
action |
kernel-builder |
17m
Results: map[KernelObj:/app/workdir/cache/build/dfeb84b79567b54c62bbe8dfa7bdb7c5d51d27a9]
|
| 4/1 |
2026/09/02 01:20 |
action |
codesearch-prepare |
12m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/09/02 01:33 |
agent |
expert |
4m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".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).
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, elevated privileges, or an information leak.
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 completely 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 transfers, that 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 exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
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 Confidential 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.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
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:
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 8860, name: syz.2.940
preempt_count: 0, expected: 0
RCU nest depth: 1, expected: 0
1 lock held by syz.2.940/8860:
#0: ffff800088d271a0 (rcu_read_lock){....}-{1:3}, at: rcu_lock_acquire include/linux/rcupdate.h:300 [inline]
#0: ffff800088d271a0 (rcu_read_lock){....}-{1:3}, at: rcu_read_lock include/linux/rcupdate.h:840 [inline]
#0: ffff800088d271a0 (rcu_read_lock){....}-{1:3}, at: blk_mq_dispatch_queue_requests+0x110/0x6d4 block/blk-mq.c:2872
CPU: 0 UID: 0 PID: 8860 Comm: syz.2.940 Tainted: G L syzkaller #0 PREEMPT
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/07/2026
Call trace:
show_stack+0x2c/0x3c arch/arm64/kernel/stacktrace.c:499 (C)
__dump_stack+0x30/0x40 lib/dump_stack.c:94
dump_stack_lvl+0xd8/0x12c lib/dump_stack.c:120
dump_stack+0x1c/0x28 lib/dump_stack.c:129
__might_resched+0x354/0x4c0 kernel/sched/core.c:9197
__might_sleep+0x84/0xdc kernel/sched/core.c:9126
might_alloc include/linux/sched/mm.h:323 [inline]
slab_pre_alloc_hook mm/slub.c:4537 [inline]
slab_alloc_node mm/slub.c:4897 [inline]
__kmalloc_cache_noprof+0x88/0x5ec mm/slub.c:5485
_kmalloc_noprof include/linux/slab.h:988 [inline]
null_alloc_page drivers/block/null_blk/main.c:870 [inline]
null_insert_page+0x94/0x4e8 drivers/block/null_blk/main.c:1019
copy_to_nullb drivers/block/null_blk/main.c:1157 [inline]
null_transfer drivers/block/null_blk/main.c:1271 [inline]
null_handle_data_transfer drivers/block/null_blk/main.c:1300 [inline]
null_handle_memory_backed+0x474/0x9d8 drivers/block/null_blk/main.c:1380
null_process_cmd+0x118/0x1b0 drivers/block/null_blk/main.c:1434
null_handle_cmd drivers/block/null_blk/main.c:1457 [inline]
null_queue_rq+0x788/0xa88 drivers/block/null_blk/main.c:1703
null_queue_rqs+0x108/0x204 drivers/block/null_blk/main.c:1717
__blk_mq_flush_list block/blk-mq.c:2827 [inline]
blk_mq_dispatch_queue_requests+0x33c/0x6d4 block/blk-mq.c:2872
blk_mq_flush_plug_list+0x37c/0x494 block/blk-mq.c:2960
__blk_flush_plug+0x364/0x440 block/blk-core.c:1266
blk_finish_plug+0x68/0x90 block/blk-core.c:1293
blkdev_writepages+0x128/0x184 block/fops.c:486
do_writepages+0x284/0x47c mm/page-writeback.c:2571
filemap_writeback+0x230/0x2bc mm/filemap.c:387
filemap_fdatawrite_range mm/filemap.c:412 [inline]
filemap_write_and_wait_range+0x90/0x114 mm/filemap.c:684
filemap_write_and_wait include/linux/pagemap.h:65 [inline]
sync_blockdev block/bdev.c:276 [inline]
bdev_release+0x114/0x328 block/bdev.c:1129
blkdev_release+0x20/0x34 block/fops.c:680
__fput+0x338/0x74c fs/file_table.c:512
fput_close_sync+0x10c/0x278 fs/file_table.c:617
__do_sys_close fs/open.c:1511 [inline]
__se_sys_close fs/open.c:1496 [inline]
__arm64_sys_close+0x80/0x110 fs/open.c:1496
__invoke_syscall arch/arm64/kernel/syscall.c:35 [inline]
invoke_syscall+0x98/0x244 arch/arm64/kernel/syscall.c:49
el0_svc_common+0xec/0x23c arch/arm64/kernel/syscall.c:121
do_el0_svc+0x4c/0x5c arch/arm64/kernel/syscall.c:140
el0_svc+0x64/0x260 arch/arm64/kernel/entry-common.c:758
el0t_64_sync_handler+0x44/0x104 arch/arm64/kernel/entry-common.c:777
el0t_64_sync+0x198/0x19c arch/arm64/kernel/entry.S:590
Reply: The bug report describes a "sleeping function called from invalid context" in the `null_blk` block device driver.
### Root Cause Analysis
The `null_blk` driver is a test block driver that can be configured to simulate various storage device behaviors. It can be configured to store data in memory by setting the `memory_backed` option. When `memory_backed` is enabled, the driver allocates memory pages during request processing using `kmalloc_obj(..., GFP_NOIO)` and `alloc_pages(GFP_NOIO, ...)`, which can sleep.
To safely sleep during request processing, the block layer must be informed that the driver's queue operations may block. This is done by setting the `BLK_MQ_F_BLOCKING` flag on the device's tag set. If this flag is set, the block layer's dispatch loop (`blk_mq_run_dispatch_ops`) uses `srcu_read_lock()`, which allows sleeping. If the flag is not set, it uses `rcu_read_lock()`, which disables preemption and creates an atomic context where sleeping is invalid.
The bug occurs due to a mismatch in configuration when using **shared tags** (`shared_tags=1`). When shared tags are enabled, the driver uses a single global tag set (`tag_set`) for all devices. This global tag set is initialized based on the global module parameter `g_blocking` (which defaults to `false`).
If a user creates a `null_blk` device via `configfs` with `memory_backed=1` and `shared_tags=1`, the device requires blocking operations (because it allocates memory), but the global tag set it uses does not have the `BLK_MQ_F_BLOCKING` flag set (because `g_blocking` was false).
As a result, the block layer dispatches requests to the driver under an RCU read lock. When the driver attempts to allocate memory in `null_alloc_page()`, it sleeps while holding the RCU lock, triggering the `BUG: sleeping function called from invalid context`.
### Security Impact
* **Exploitable:** No. This is a context violation (sleeping in atomic context) that triggers a kernel warning or panic. It does not cause memory corruption, use-after-free, or out-of-bounds accesses that could be leveraged for privilege escalation or information leaks.
* **Denial of Service:** Yes. Depending on the kernel configuration (e.g., `CONFIG_PANIC_ON_WARN`), this can crash the system or lead to RCU stalls.
* **Accessible From Unprivileged Processes / User Namespaces:** No. The `null_blk` driver is configured either via module parameters at load time or via `configfs` (typically mounted at `/sys/kernel/config`). Both actions require root privileges (`CAP_SYS_MODULE` or root access to `configfs`). `configfs` cannot be mounted inside unprivileged user namespaces.
* **Other Triggers:** This bug is not triggerable via network, remote, peripheral, or malicious filesystem vectors. It is strictly a local configuration issue in a test driver.
In conclusion, this is a local Denial of Service bug that can only be triggered by a privileged user (root) misconfiguring a test driver. It poses no security risk to production systems from unprivileged attackers.
|
| 6/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 7533
output: 40
thoughts: 493
Thoughts: **Debugging a `null_blk` Driver Sleeping Issue**
Alright, a new bug report has landed: "sleeping function called from invalid context" in `mm.h`. The stack trace, which looks like this (pasted the trace here), points directly at the `null_blk` driver. Specifically, it seems to be originating from the `null_alloc_page` function, which is being called from several places within the driver.
Okay, let's think. `null_blk`... that's the test block device driver, right? A driver that is mostly used in testing and rarely, if ever, in a production environment. So, first question is, why is it even running in this context? Is this even running on a production system, or a dev system? Even if it is running, let's see if this `null_blk` device is accessible to unprivileged users. I need to figure out how this is configured. Usually, devices like this are created through configfs or module parameters.
I need to dive into the source code, specifically `drivers/block/null_blk/main.c`, and see what's going on. This smells like a classic locking issue or a context issue within a driver meant to be simple. Let's see if we can get a minimal, reproducible example too.
|
| 7/2 |
2026/09/02 01:33 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_alloc_page]
Results: map[SourceCode: 866: static struct nullb_page *null_alloc_page(void)
867: {
868: struct nullb_page *t_page;
869:
870: t_page = kmalloc_obj(struct nullb_page, GFP_NOIO);
871: if (!t_page)
872: return NULL;
873:
874: t_page->page = alloc_pages(GFP_NOIO, 0);
875: if (!t_page->page) {
876: kfree(t_page);
877: return NULL;
878: }
879:
880: memset(t_page->bitmap, 0, sizeof(t_page->bitmap));
881: return t_page;
882: }
SourceFile:drivers/block/null_blk/main.c]
|
| 8/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 8124
output: 40
thoughts: 126
Thoughts: **Analyzing a Tricky Kernel Bug**
Okay, so I've got this bug: "BUG: sleeping function called from invalid context." Interesting. It seems to be rearing its ugly head in `null_alloc_page`. Right, that function calls `kmalloc_obj` with a `struct nullb_page` and the `GFP_NOIO` flag. Ah, there's the catch! `GFP_NOIO` indirectly implies `__GFP_WAIT`, or potentially `__GFP_DIRECT_RECLAIM`. Which means it *can* sleep. That's usually fine, but... the context is the problem. It's happening inside `blk_mq_dispatch_queue_requests`. And that function, I seem to recall, holds an `rcu_read_lock`. Sleepy functions and RCU locks... that's a classic no-no. Time to dig into `blk_mq_dispatch_queue_requests` in `block/blk-mq.c` and see what's actually going on in that context. Let's see if we can trace the flow of execution and confirm my initial suspicion.
|
| 9/2 |
2026/09/02 01:33 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:block/blk-mq.c Name:blk_mq_dispatch_queue_requests]
Results: map[SourceCode:2859: static void blk_mq_dispatch_queue_requests(struct rq_list *rqs, unsigned depth)
2860: {
2861: struct request_queue *q = rq_list_peek(rqs)->q;
2862:
2863: trace_block_unplug(q, depth, true);
2864:
2865: /*
2866: * Peek first request and see if we have a ->queue_rqs() hook.
2867: * If we do, we can dispatch the whole list in one go.
2868: * We already know at this point that all requests belong to the
2869: * same queue, caller must ensure that's the case.
2870: */
2871: if (q->mq_ops->queue_rqs) {
2872: blk_mq_run_dispatch_ops(q, __blk_mq_flush_list(q, rqs));
2873: if (rq_list_empty(rqs))
2874: return;
2875: }
2876:
2877: blk_mq_run_dispatch_ops(q, blk_mq_issue_direct(rqs));
2878: }
SourceFile:block/blk-mq.c]
|
| 10/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 8770
output: 40
thoughts: 253
Thoughts: **Debugging a Tricky Kernel Bug**
Okay, so I've got this nasty bug: "sleeping function called from invalid context" deep down in `null_alloc_page`. The call stack is pretty clear, leading me through the block layer functions, right down to the null block driver. It's: `blk_mq_dispatch_queue_requests` -> `__blk_mq_flush_list` -> `null_queue_rqs` -> `null_queue_rq` -> `null_handle_cmd` -> `null_process_cmd` -> `null_handle_memory_backed` -> `null_handle_data_transfer` -> `null_transfer` -> `copy_to_nullb` -> `null_insert_page` -> and finally, `null_alloc_page`.
Now, inside `null_alloc_page`, I see the culprit: it's calling `kmalloc_obj` to allocate a `nullb_page`. That's essentially just a `kmalloc` with `GFP_NOIO`. And here's where the alarm bells go off. `GFP_NOIO` implies `__GFP_DIRECT_RECLAIM`. Right, that's the one. That flag *allows* the allocation to sleep, which is exactly what we *can't* do in this context.
The context itself, `blk_mq_dispatch_queue_requests`, is holding an `rcu_read_lock`. Sleepy allocations and RCU locks... that's a recipe for disaster. I need to make sure this `kmalloc` can't sleep in this code path. I might need to check `blk_mq_run_dispatch_ops` to understand why this code is running with an `rcu_read_lock` and see if this call to `kmalloc` can be altered or avoided in this code path. I know that if I don't I'll see this issue again and again.
|
| 11/2 |
2026/09/02 01:33 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:block/blk-mq.c Name:blk_mq_run_dispatch_ops]
Results: map[SourceCode: SourceFile:]
|
| 12/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 10123
output: 23
thoughts: 16
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience and written in the first person:
**Analyzing Block Layer Dispatch Operations**
Okay, so I'm diving into the block layer, and the immediate thought is to zero in on the core dispatch mechanism. My instinct, honed over years of working with the kernel, screams " `blk_mq_run_dispatch_ops` ". That function name just *feels* like the heart of how requests get handled. It's the point where work transitions from being queued to actually *doing* something – likely calling into the device driver itself. I'm imagining how requests are batched and what the critical path through this function is. Are there any obvious bottlenecks, locks, or potential contention points that jump out? Time to see how things are flowing. Let's start the search and see what we can find!
|
| 13/2 |
2026/09/02 01:33 |
tool |
grepper |
0m
Args: map[Expression:blk_mq_run_dispatch_ops]
Results: map[Output:block/blk-mq.c=2294=static inline bool blk_mq_hw_queue_need_run(struct blk_mq_hw_ctx *hctx)
--
block/blk-mq.c-2305- */
block/blk-mq.c:2306: __blk_mq_run_dispatch_ops(hctx->queue, false,
block/blk-mq.c-2307- need_run = !blk_queue_quiesced(hctx->queue) &&
--
block/blk-mq.c=2321=void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
--
block/blk-mq.c-2354-
block/blk-mq.c:2355: blk_mq_run_dispatch_ops(hctx->queue,
block/blk-mq.c-2356- blk_mq_sched_dispatch_requests(hctx));
--
block/blk-mq.c=2526=static void blk_mq_run_work_fn(struct work_struct *work)
--
block/blk-mq.c-2530-
block/blk-mq.c:2531: blk_mq_run_dispatch_ops(hctx->queue,
block/blk-mq.c-2532- blk_mq_sched_dispatch_requests(hctx));
--
block/blk-mq.c=2555=static void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx,
--
block/blk-mq.c-2566- if (!hctx->dispatch_busy && !run_queue_async) {
block/blk-mq.c:2567: blk_mq_run_dispatch_ops(hctx->queue,
block/blk-mq.c-2568- blk_mq_try_issue_list_directly(hctx, list));
--
block/blk-mq.c=2859=static void blk_mq_dispatch_queue_requests(struct rq_list *rqs, unsigned depth)
--
block/blk-mq.c-2871- if (q->mq_ops->queue_rqs) {
block/blk-mq.c:2872: blk_mq_run_dispatch_ops(q, __blk_mq_flush_list(q, rqs));
block/blk-mq.c-2873- if (rq_list_empty(rqs))
--
block/blk-mq.c-2876-
block/blk-mq.c:2877: blk_mq_run_dispatch_ops(q, blk_mq_issue_direct(rqs));
block/blk-mq.c-2878-}
--
block/blk-mq.c=3093=void blk_mq_submit_bio(struct bio *bio)
--
block/blk-mq.c-3207- } else {
block/blk-mq.c:3208: blk_mq_run_dispatch_ops(q, blk_mq_try_issue_directly(hctx, rq));
block/blk-mq.c-3209- }
--
block/blk-mq.c=3224=blk_status_t blk_insert_cloned_request(struct request *rq)
--
block/blk-mq.c-3293- */
block/blk-mq.c:3294: blk_mq_run_dispatch_ops(q,
block/blk-mq.c-3295- ret = blk_mq_request_issue_directly(rq, true));
--
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 { \
--
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) \
block/blk-mq.h-458-
]
|
| 14/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 10614
output: 41
thoughts: 129
Thoughts: **Debugging a Sleeping Function in an Invalid Context**
Okay, so I've got a problem. The dreaded "sleeping function called from invalid context" error is popping up. Digging in, the offending function is `kmalloc_obj(struct nullb_page, GFP_NOIO)`, which is being called within `null_alloc_page`. Right, `GFP_NOIO` can absolutely sleep, which makes this interesting.
Now, the "invalid context" part is crucial. Let's see... it looks like `rcu_read_lock` is being held when this happens. Okay, that's not good. Where's this lock coming from? Tracing the call stack, I see it's held within `blk_mq_dispatch_queue_requests`, which then calls `blk_mq_run_dispatch_ops`, which in turn calls `__blk_mq_run_dispatch_ops`. That's where I need to focus. I'll need to scrutinize `__blk_mq_run_dispatch_ops` to understand exactly why a potentially sleeping function is being invoked while under an RCU read lock. Time to dive into that code and figure out the sequence of events.
|
| 15/2 |
2026/09/02 01:33 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:block/blk-mq.h Name:__blk_mq_run_dispatch_ops]
Results: map[SourceCode: SourceFile:]
|
| 16/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 11950
output: 35
thoughts: 26
Thoughts: Here's my summary, as though I'm thinking through this:
**Analyzing the Macro in blk-mq.h**
Okay, so we're dealing with a macro. My first instinct is to dive into the code and get a real understanding of what's going on. Let's start by looking at `block/blk-mq.h`, specifically around line 439. That's usually where the main definitions and structures for the block multi-queue stuff reside, so it's a good starting point to contextualize this macro. From there, I'll need to see how it's used and what it expands to, because understanding its context within the broader blk-mq architecture will be key to deciphering its purpose.
|
| 17/2 |
2026/09/02 01:33 |
tool |
read-file |
0m
Args: map[File:block/blk-mq.h FirstLine:430 LineCount:30]
Results: map[Contents: 430:
431: /*
432: * Allow at least some tags
433: */
434: depth = max((bt->sb.depth + users - 1) / users, 4U);
435: return __blk_mq_active_requests(hctx) < depth;
436: }
437:
438: /* run the code block in @dispatch_ops with rcu/srcu read lock held */
439: #define __blk_mq_run_dispatch_ops(q, check_sleep, dispatch_ops) \
440: do { \
441: if ((q)->tag_set->flags & BLK_MQ_F_BLOCKING) { \
442: struct blk_mq_tag_set *__tag_set = (q)->tag_set; \
443: int srcu_idx; \
444: \
445: might_sleep_if(check_sleep); \
446: srcu_idx = srcu_read_lock(__tag_set->srcu); \
447: (dispatch_ops); \
448: srcu_read_unlock(__tag_set->srcu, srcu_idx); \
449: } else { \
450: rcu_read_lock(); \
451: (dispatch_ops); \
452: rcu_read_unlock(); \
453: } \
454: } while (0)
455:
456: #define blk_mq_run_dispatch_ops(q, dispatch_ops) \
457: __blk_mq_run_dispatch_ops(q, true, dispatch_ops) \
458:
459: static inline bool blk_mq_can_poll(struct request_queue *q)
]
|
| 18/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 11662
output: 40
thoughts: 268
Thoughts: **Debugging a Tricky Kernel Bug**
Okay, so I've got this crash. The error message is screaming "sleeping function called from invalid context," which immediately flags a potential concurrency issue. The trace points me to `might_alloc`, specifically within `slab_pre_alloc_hook`. Digging deeper, it goes through `slab_alloc_node`, then `__kmalloc_cache_noprof`, down to `_kmalloc_noprof`, and finally lands at `null_alloc_page`. My intuition tells me this is where the problem lies.
Now, `null_alloc_page` is calling `kmalloc_obj` with `GFP_NOIO`, and also `alloc_pages` with `GFP_NOIO`. I know `GFP_NOIO` *can* sleep. That's the red flag. Concurrently, `blk_mq_run_dispatch_ops` calls it. From experience I know that `blk_mq_run_dispatch_ops` holds an `rcu_read_lock()` if a specific flag isn't set, specifically if `!((q)->tag_set->flags & BLK_MQ_F_BLOCKING)`. Holding `rcu_read_lock()` means we're in an atomic context, so sleeping is forbidden. This is a classic violation!
Since `null_blk` is a test block driver, I'm now curious about whether the `null_blk` driver sets that crucial `BLK_MQ_F_BLOCKING` flag. That's the next avenue to explore. I need to understand whether this is a configuration issue in the driver or a deeper, more subtle, interaction.
|
| 19/2 |
2026/09/02 01:33 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_add_dev]
Results: map[SourceCode:1955: static int null_add_dev(struct nullb_device *dev)
1956: {
1957: struct queue_limits lim = {
1958: .logical_block_size = dev->blocksize,
1959: .physical_block_size = dev->blocksize,
1960: .max_hw_sectors = dev->max_sectors,
1961: .dma_alignment = 1,
1962: };
1963:
1964: struct nullb *nullb;
1965: int rv;
1966:
1967: rv = null_validate_conf(dev);
1968: if (rv)
1969: return rv;
1970:
1971: nullb = kzalloc_node(sizeof(*nullb), GFP_KERNEL, dev->home_node);
1972: if (!nullb) {
1973: rv = -ENOMEM;
1974: goto out;
1975: }
1976: nullb->dev = dev;
1977: dev->nullb = nullb;
1978:
1979: spin_lock_init(&nullb->lock);
1980:
1981: rv = setup_queues(nullb);
1982: if (rv)
1983: goto out_free_nullb;
1984:
1985: rv = null_setup_tagset(nullb);
1986: if (rv)
1987: goto out_cleanup_queues;
1988:
1989: if (dev->virt_boundary)
1990: lim.virt_boundary_mask = PAGE_SIZE - 1;
1991: null_config_discard(nullb, &lim);
1992: if (dev->zoned) {
1993: rv = null_init_zoned_dev(dev, &lim);
1994: if (rv)
1995: goto out_cleanup_tags;
1996: }
1997:
1998: if (dev->cache_size > 0) {
1999: set_bit(NULLB_DEV_FL_CACHE, &nullb->dev->flags);
2000: lim.features |= BLK_FEAT_WRITE_CACHE;
2001: if (dev->fua)
2002: lim.features |= BLK_FEAT_FUA;
2003: }
2004:
2005: if (dev->rotational)
2006: lim.features |= BLK_FEAT_ROTATIONAL;
2007:
2008: nullb->disk = blk_mq_alloc_disk(nullb->tag_set, &lim, nullb);
2009: if (IS_ERR(nullb->disk)) {
2010: rv = PTR_ERR(nullb->disk);
2011: goto out_cleanup_zone;
2012: }
2013: nullb->q = nullb->disk->queue;
2014:
2015: if (dev->mbps) {
2016: set_bit(NULLB_DEV_FL_THROTTLED, &dev->flags);
2017: nullb_setup_bwtimer(nullb);
2018: }
2019:
2020: nullb->q->queuedata = nullb;
2021:
2022: rv = ida_alloc(&nullb_indexes, GFP_KERNEL);
2023: if (rv < 0)
2024: goto out_cleanup_disk;
2025:
2026: nullb->index = rv;
2027: dev->index = rv;
2028:
2029: if (config_item_name(&dev->group.cg_item)) {
2030: /* Use configfs dir name as the device name */
2031: snprintf(nullb->disk_name, sizeof(nullb->disk_name),
2032: "%s", config_item_name(&dev->group.cg_item));
2033: } else {
2034: sprintf(nullb->disk_name, "nullb%d", nullb->index);
2035: }
2036:
2037: set_capacity(nullb->disk,
2038: ((sector_t)nullb->dev->size * SZ_1M) >> SECTOR_SHIFT);
2039: nullb->disk->major = null_major;
2040: nullb->disk->first_minor = nullb->index;
2041: nullb->disk->minors = 1;
2042: nullb->disk->fops = &null_ops;
2043: nullb->disk->private_data = nullb;
2044: strscpy(nullb->disk->disk_name, nullb->disk_name);
2045:
2046: if (nullb->dev->zoned) {
2047: rv = null_register_zoned_dev(nullb);
2048: if (rv)
2049: goto out_ida_free;
2050: }
2051:
2052: rv = add_disk(nullb->disk);
2053: if (rv)
2054: goto out_ida_free;
2055:
2056: list_add_tail(&nullb->list, &nullb_list);
2057:
2058: pr_info("disk %s created\n", nullb->disk_name);
2059:
2060: return 0;
2061:
2062: out_ida_free:
2063: ida_free(&nullb_indexes, nullb->index);
2064: out_cleanup_disk:
2065: put_disk(nullb->disk);
2066: out_cleanup_zone:
2067: null_free_zoned_dev(dev);
2068: out_cleanup_tags:
2069: if (nullb->tag_set == &nullb->__tag_set)
2070: blk_mq_free_tag_set(nullb->tag_set);
2071: out_cleanup_queues:
2072: kfree(nullb->queues);
2073: out_free_nullb:
2074: kfree(nullb);
2075: dev->nullb = NULL;
2076: out:
2077: return rv;
2078: }
SourceFile:drivers/block/null_blk/main.c]
|
| 20/2 |
2026/09/02 01:33 |
llm |
expert |
0m
Model:
Tokens:
input: 15239
output: 41
thoughts: 12
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as a first-person summary:
**Checking `null_setup_tagset`**
Alright, time to get started. Let's dig into this `null_setup_tagset` thing. I've got a hunch about what's going on, but before I go off on any tangents, I need to confirm the basics. I'm going to run through the code and documentation – maybe I can quickly grasp it. There are a few things I'm thinking about: edge cases to consider; which data points are included? I should make sure there are no obvious oversights or gotchas in how it's defined and used. It's often the small, seemingly insignificant details in these setups that bite you later. Then, I can start looking for areas of possible optimization. There could be some interesting interactions, depending on its specific implementation, that I can use or improve. Let's see if this `null_setup_tagset` behaves as expected.
|
| 21/2 |
2026/09/02 01:34 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_setup_tagset]
Results: map[SourceCode:1864: static int null_setup_tagset(struct nullb *nullb)
1865: {
1866: if (nullb->dev->shared_tags) {
1867: nullb->tag_set = &tag_set;
1868: return null_init_global_tag_set();
1869: }
1870:
1871: nullb->tag_set = &nullb->__tag_set;
1872: nullb->tag_set->driver_data = nullb;
1873: nullb->tag_set->nr_hw_queues = nullb->dev->submit_queues;
1874: nullb->tag_set->queue_depth = nullb->dev->hw_queue_depth;
1875: nullb->tag_set->numa_node = nullb->dev->home_node;
1876: if (nullb->dev->no_sched)
1877: nullb->tag_set->flags |= BLK_MQ_F_NO_SCHED_BY_DEFAULT;
1878: if (nullb->dev->shared_tag_bitmap)
1879: nullb->tag_set->flags |= BLK_MQ_F_TAG_HCTX_SHARED;
1880: if (nullb->dev->blocking)
1881: nullb->tag_set->flags |= BLK_MQ_F_BLOCKING;
1882: return null_init_tag_set(nullb->tag_set, nullb->dev->poll_queues);
1883: }
SourceFile:drivers/block/null_blk/main.c]
|
| 22/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 15965
output: 35
thoughts: 361
Thoughts: **Analyzing a Potential Sleep-in-Atomic Context Bug in the `null_blk` Driver**
Okay, so I'm looking at this bit of code: `nullb->tag_set->flags |= BLK_MQ_F_BLOCKING;` It seems like the `BLK_MQ_F_BLOCKING` flag gets set based on the `nullb->dev->blocking` value. If blocking is enabled, no problem. However, if `nullb->dev->blocking` is *false*, then `BLK_MQ_F_BLOCKING` isn't set, and `blk_mq_run_dispatch_ops` uses `rcu_read_lock()`. And *then*, `null_alloc_page` is called, which, annoyingly, uses `GFP_NOIO` and *sleeps*!
This is screaming "bug" to me in the `null_blk` driver. Allocating memory with `GFP_NOIO` inside the request processing path, when it could be called in atomic context (because we're under an `rcu_read_lock()`), is a classic no-no.
But, is it exploitable? It's definitely a "sleeping function called from invalid context" bug. It'll trigger a `BUG` or `WARNING`, depending on the kernel configuration; probably just a warning from `might_sleep()`. And the good news is, it's *probably* not a memory corruption vulnerability.
At first glance, it might only lead to a denial of service if the warning causes the kernel to panic (because of `panic_on_warn`). But `panic_on_warn` is rarely set in production. So, if it doesn't panic, it's likely just a warning in the logs.
Wait a second... if that `null_alloc_page` is sleeping while holding an `rcu_read_lock()`, that *could* lead to RCU stalls! And *that* could definitely cause a system crash or hang. This is starting to look more serious.
The only remaining question is: is this even remotely accessible? Remember, `null_blk` is a *test* driver. Is an unprivileged user even able to trigger this? How are `null_blk` devices created in the first place? Time to investigate... usually it's module parameters at load time, or configfs. I'll need to figure out the access control to the module parameters, or see if configfs is properly sandboxed.
|
| 23/2 |
2026/09/02 01:34 |
tool |
grepper |
0m
Args: map[Expression:configfs_register_subsystem PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=2125=static int __init null_init(void)
--
drivers/block/null_blk/main.c-2164-
drivers/block/null_blk/main.c:2165: ret = configfs_register_subsystem(&nullb_subsys);
drivers/block/null_blk/main.c-2166- if (ret)
]
|
| 24/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 15334
output: 38
thoughts: 0
|
| 25/2 |
2026/09/02 01:34 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_init]
Results: map[SourceCode:2125: static int __init null_init(void)
2126: {
2127: int ret = 0;
2128: unsigned int i;
2129: struct nullb *nullb;
2130:
2131: if (g_bs > PAGE_SIZE) {
2132: pr_warn("invalid block size\n");
2133: pr_warn("defaults block size to %lu\n", PAGE_SIZE);
2134: g_bs = PAGE_SIZE;
2135: }
2136:
2137: if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) {
2138: pr_err("invalid home_node value\n");
2139: g_home_node = NUMA_NO_NODE;
2140: }
2141:
2142: if (!null_setup_fault())
2143: return -EINVAL;
2144:
2145: if (g_queue_mode == NULL_Q_RQ) {
2146: pr_err("legacy IO path is no longer available\n");
2147: return -EINVAL;
2148: }
2149:
2150: if (g_use_per_node_hctx) {
2151: if (g_submit_queues != nr_online_nodes) {
2152: pr_warn("submit_queues param is set to %u.\n",
2153: nr_online_nodes);
2154: g_submit_queues = nr_online_nodes;
2155: }
2156: } else if (g_submit_queues > nr_cpu_ids) {
2157: g_submit_queues = nr_cpu_ids;
2158: } else if (g_submit_queues <= 0) {
2159: g_submit_queues = 1;
2160: }
2161:
2162: config_group_init(&nullb_subsys.su_group);
2163: mutex_init(&nullb_subsys.su_mutex);
2164:
2165: ret = configfs_register_subsystem(&nullb_subsys);
2166: if (ret)
2167: return ret;
2168:
2169: mutex_init(&lock);
2170:
2171: null_major = register_blkdev(0, "nullb");
2172: if (null_major < 0) {
2173: ret = null_major;
2174: goto err_conf;
2175: }
2176:
2177: for (i = 0; i < nr_devices; i++) {
2178: ret = null_create_dev();
2179: if (ret)
2180: goto err_dev;
2181: }
2182:
2183: pr_info("module loaded\n");
2184: return 0;
2185:
2186: err_dev:
2187: while (!list_empty(&nullb_list)) {
2188: nullb = list_entry(nullb_list.next, struct nullb, list);
2189: null_destroy_dev(nullb);
2190: }
2191: unregister_blkdev(null_major, "nullb");
2192: err_conf:
2193: configfs_unregister_subsystem(&nullb_subsys);
2194: return ret;
2195: }
SourceFile:drivers/block/null_blk/main.c]
|
| 26/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 18112
output: 32
thoughts: 54
Thoughts: **My Assessment of Configfs Accessibility**
Okay, so configfs generally lives at `/sys/kernel/config`. My immediate thought is, "Can a regular, non-root user actually mess with it?" Nope, that's not how it works, as expected. Root access is the gatekeeper. Alright, next question - does this change if we're dealing with user namespaces? This is where things get interesting. Let's see if the kernel allows a degree of configfs access within a user namespace. I need to investigate that angle.
|
| 27/2 |
2026/09/02 01:34 |
tool |
grepper |
0m
Error:
Args: map[Expression:FS_USERNS_MOUNT PathPrefix:fs/configfs/]
Results:
|
| 28/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 18326
output: 31
thoughts: 162
Thoughts: **Analyzing the null_blk Module's Behavior**
Okay, so configfs is a dead end for my purposes here – it doesn't support `FS_USERNS_MOUNT`, meaning it's inherently restricted to the host's namespace. And, given that, if it *is* mounted, root permissions are almost certainly the name of the game. That makes user-space exploitation incredibly difficult to achieve. Time to shift focus.
Alright, let's see if we can trigger something interesting with `null_blk` from an unprivileged context. The default is `nr_devices > 0`, so it makes the `nullb0` device when the module is loaded. The current module settings are:
`g_blocking = false`
`g_memory_backed = false`
Wait a minute... the bug report I'm looking at, the one that's got my attention, is buried inside `null_handle_memory_backed`. That strongly suggests the `memory_backed` flag *must* be set to true for this exploit path to even be viable. I need to confirm the default state of `memory_backed` for that module. This is the crucial point right now.
|
| 29/2 |
2026/09/02 01:34 |
tool |
grepper |
0m
Args: map[Expression:memory_backed PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=214=MODULE_PARM_DESC(use_per_node_hctx, "Use per-node allocation for hardware context queues. Default: false");
drivers/block/null_blk/main.c-215-
drivers/block/null_blk/main.c:216:static bool g_memory_backed;
drivers/block/null_blk/main.c:217:module_param_named(memory_backed, g_memory_backed, bool, 0444);
drivers/block/null_blk/main.c:218:MODULE_PARM_DESC(memory_backed, "Create a memory-backed block device. Default: false");
drivers/block/null_blk/main.c-219-
--
drivers/block/null_blk/main.c=457=NULLB_DEVICE_ATTR(use_per_node_hctx, bool, NULL);
drivers/block/null_blk/main.c:458:NULLB_DEVICE_ATTR(memory_backed, bool, NULL);
drivers/block/null_blk/main.c-459-NULLB_DEVICE_ATTR(discard, bool, NULL);
--
drivers/block/null_blk/main.c=596=static struct configfs_attribute *nullb_device_attrs[] = {
--
drivers/block/null_blk/main.c-611- &nullb_device_attr_mbps,
drivers/block/null_blk/main.c:612: &nullb_device_attr_memory_backed,
drivers/block/null_blk/main.c-613- &nullb_device_attr_no_sched,
--
drivers/block/null_blk/main.c=777=static struct nullb_device *null_alloc_dev(void)
--
drivers/block/null_blk/main.c-810- dev->blocking = g_blocking;
drivers/block/null_blk/main.c:811: dev->memory_backed = g_memory_backed;
drivers/block/null_blk/main.c-812- dev->discard = g_discard;
--
drivers/block/null_blk/main.c=1346=blk_status_t null_handle_badblocks(struct nullb_cmd *cmd, sector_t sector,
--
drivers/block/null_blk/main.c-1371-
drivers/block/null_blk/main.c:1372:blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, enum req_op op,
drivers/block/null_blk/main.c-1373- sector_t sector, sector_t nr_sectors)
--
drivers/block/null_blk/main.c=1383=static void nullb_zero_read_cmd_buffer(struct nullb_cmd *cmd)
--
drivers/block/null_blk/main.c-1388-
drivers/block/null_blk/main.c:1389: if (!dev->memory_backed && req_op(rq) == REQ_OP_READ) {
drivers/block/null_blk/main.c-1390- __rq_for_each_bio(bio, rq)
--
drivers/block/null_blk/main.c=1423=blk_status_t null_process_cmd(struct nullb_cmd *cmd, enum req_op op,
--
drivers/block/null_blk/main.c-1432-
drivers/block/null_blk/main.c:1433: if (dev->memory_backed && nr_sectors) {
drivers/block/null_blk/main.c:1434: ret = null_handle_memory_backed(cmd, op, sector, nr_sectors);
drivers/block/null_blk/main.c-1435- if (ret != BLK_STS_OK)
--
drivers/block/null_blk/main.c=1789=static void null_config_discard(struct nullb *nullb, struct queue_limits *lim)
--
drivers/block/null_blk/main.c-1793-
drivers/block/null_blk/main.c:1794: if (!nullb->dev->memory_backed) {
drivers/block/null_blk/main.c-1795- nullb->dev->discard = false;
--
drivers/block/null_blk/main.c=1885=static int null_validate_conf(struct nullb_device *dev)
--
drivers/block/null_blk/main.c-1910- /* Do memory allocation, so set blocking */
drivers/block/null_blk/main.c:1911: if (dev->memory_backed)
drivers/block/null_blk/main.c-1912- dev->blocking = true;
--
drivers/block/null_blk/null_blk.h=53=struct nullb_device {
--
drivers/block/null_blk/null_blk.h-102- bool power; /* power on/off the device */
drivers/block/null_blk/null_blk.h:103: bool memory_backed; /* if data is stored in memory */
drivers/block/null_blk/null_blk.h-104- bool discard; /* if support discard */
--
drivers/block/null_blk/null_blk.h=136=blk_status_t null_handle_badblocks(struct nullb_cmd *cmd, sector_t sector,
drivers/block/null_blk/null_blk.h-137- unsigned int *nr_sectors);
drivers/block/null_blk/null_blk.h:138:blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, enum req_op op,
drivers/block/null_blk/null_blk.h-139- sector_t sector, sector_t nr_sectors);
--
drivers/block/null_blk/zoned.c=24=static inline void null_init_zone_lock(struct nullb_device *dev,
--
drivers/block/null_blk/zoned.c-26-{
drivers/block/null_blk/zoned.c:27: if (!dev->memory_backed)
drivers/block/null_blk/zoned.c-28- spin_lock_init(&zone->spinlock);
--
drivers/block/null_blk/zoned.c=33=static inline void null_lock_zone(struct nullb_device *dev,
--
drivers/block/null_blk/zoned.c-35-{
drivers/block/null_blk/zoned.c:36: if (!dev->memory_backed)
drivers/block/null_blk/zoned.c-37- spin_lock_irq(&zone->spinlock);
--
drivers/block/null_blk/zoned.c=42=static inline void null_unlock_zone(struct nullb_device *dev,
--
drivers/block/null_blk/zoned.c-44-{
drivers/block/null_blk/zoned.c:45: if (!dev->memory_backed)
drivers/block/null_blk/zoned.c-46- spin_unlock_irq(&zone->spinlock);
--
drivers/block/null_blk/zoned.c=350=static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
--
drivers/block/null_blk/zoned.c-423-
drivers/block/null_blk/zoned.c:424: if (dev->memory_backed) {
drivers/block/null_blk/zoned.c:425: ret = null_handle_memory_backed(cmd, REQ_OP_WRITE, sector,
drivers/block/null_blk/zoned.c-426- nr_sectors);
--
drivers/block/null_blk/zoned.c=607=static blk_status_t null_reset_zone(struct nullb_device *dev,
--
drivers/block/null_blk/zoned.c-639-
drivers/block/null_blk/zoned.c:640: if (dev->memory_backed)
drivers/block/null_blk/zoned.c-641- return null_handle_discard(dev, zone->start, zone->len);
--
drivers/block/null_blk/zoned.c=742=static void null_set_zone_cond(struct nullb_device *dev,
--
drivers/block/null_blk/zoned.c-760- zone->wp = zone->start;
drivers/block/null_blk/zoned.c:761: if (dev->memory_backed)
drivers/block/null_blk/zoned.c-762- null_handle_discard(dev, zone->start, zone->len);
]
|
| 30/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 20991
output: 40
thoughts: 619
Thoughts: **Debugging a Potential RCU Read Lock Issue in the Block Layer**
Okay, let's break this down. I'm looking at a bug report where a `rcu_read_lock` is being held when I *believe* it shouldn't be, given the device's configuration. Specifically, the trace shows the lock held within `blk_mq_dispatch_queue_requests`, which points to `blk_mq_run_dispatch_ops`. Now, my understanding is that the choice between `rcu_read_lock` and `srcu_read_lock` in `__blk_mq_run_dispatch_ops` hinges on the `BLK_MQ_F_BLOCKING` flag being set in the tagset. If `BLK_MQ_F_BLOCKING` is set, `srcu_read_lock` should be used, and this is associated with memory-backed devices.
The code in `null_validate_conf` is what sets this. If `dev->memory_backed` is true, then `dev->blocking` is set to true, and, consequently, `BLK_MQ_F_BLOCKING` should be set. This means `srcu_read_lock` should be in use, which then implies `might_sleep_if(check_sleep)` is being called. However, the trace explicitly shows an `rcu_read_lock`, so it seems `BLK_MQ_F_BLOCKING` *isn't* set.
Now, if `dev->memory_backed` *is* true, based on the bug report's details, that would seem to imply `null_handle_memory_backed` *was* called, which should lead to the `dev->blocking` flag being set. So, I need to figure out how `dev->memory_backed` can be true but `BLK_MQ_F_BLOCKING` be false, which means it isn't blocking. Something's not connecting here. I need to re-examine the `null_validate_conf` function to see if I am missing something obvious or if there is something else at play, related to what this specific device is doing.
|
| 31/2 |
2026/09/02 01:34 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_validate_conf]
Results: map[SourceCode:1885: static int null_validate_conf(struct nullb_device *dev)
1886: {
1887: if (dev->queue_mode == NULL_Q_RQ) {
1888: pr_err("legacy IO path is no longer available\n");
1889: return -EINVAL;
1890: }
1891: if (dev->queue_mode == NULL_Q_BIO) {
1892: pr_err("BIO-based IO path is no longer available, using blk-mq instead.\n");
1893: dev->queue_mode = NULL_Q_MQ;
1894: }
1895:
1896: if (dev->use_per_node_hctx) {
1897: if (dev->submit_queues != nr_online_nodes)
1898: dev->submit_queues = nr_online_nodes;
1899: } else if (dev->submit_queues > nr_cpu_ids)
1900: dev->submit_queues = nr_cpu_ids;
1901: else if (dev->submit_queues == 0)
1902: dev->submit_queues = 1;
1903: dev->prev_submit_queues = dev->submit_queues;
1904:
1905: if (dev->poll_queues > g_poll_queues)
1906: dev->poll_queues = g_poll_queues;
1907: dev->prev_poll_queues = dev->poll_queues;
1908: dev->irqmode = min_t(unsigned int, dev->irqmode, NULL_IRQ_TIMER);
1909:
1910: /* Do memory allocation, so set blocking */
1911: if (dev->memory_backed)
1912: dev->blocking = true;
1913: else /* cache is meaningless */
1914: dev->cache_size = 0;
1915: dev->cache_size = min_t(unsigned long, ULONG_MAX / 1024 / 1024,
1916: dev->cache_size);
1917: dev->mbps = min_t(unsigned int, 1024 * 40, dev->mbps);
1918:
1919: if (dev->zoned &&
1920: (!dev->zone_size || !is_power_of_2(dev->zone_size))) {
1921: pr_err("zone_size must be power-of-two\n");
1922: return -EINVAL;
1923: }
1924:
1925: return 0;
1926: }
SourceFile:drivers/block/null_blk/main.c]
|
| 32/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 22886
output: 45
thoughts: 55
Thoughts: **Examining the Interaction of `null_validate_conf`, `memory_backed`, and Blocking Behavior**
Okay, hold on a second. This `null_validate_conf` function sets `dev->blocking` to `true` under a very specific condition: when `dev->memory_backed` is also `true`. That makes intuitive sense, I get the connection there. But then I remembered ConfigFS. Doesn't ConfigFS give us the ability to dynamically tweak both `memory_backed` and `blocking` at runtime? That could introduce some interesting, and potentially dangerous, edge cases if we're not careful. I need to make sure I understand the interaction and the implications of those runtime changes. Time to dive into the ConfigFS attributes and see how this all hangs together to make sure that we're properly protecting against any race conditions or inconsistent states. I can't leave this to chance.
|
| 33/2 |
2026/09/02 01:34 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_device_attr_memory_backed]
Results: map[SourceCode: 458: NULLB_DEVICE_ATTR(memory_backed, bool, NULL);
SourceFile:drivers/block/null_blk/main.c]
|
| 34/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 23231
output: 36
thoughts: 16
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into the `NULLB_DEVICE_ATTR` Definition**
Alright, let's get down to brass tacks. I need to understand this `NULLB_DEVICE_ATTR` macro. It's usually the sign of a low-level device interaction, probably something fundamental in the kernel driver realm, or maybe even in a userspace library related to block devices. I'm guessing it's part of the standard attribute framework, potentially used for exposing device-specific information to sysfs. I want to see what this specific `NULLB_DEVICE_ATTR` is exposing. Is it handling read-only properties, read-write properties or some special device control features? Knowing the underlying structure, like `struct device_attribute`, is important. I need to trace this back to the relevant headers and source code to see how they've structured the attribute, the handler functions it invokes, and what data it's actually accessing. Is it a straightforward integer or string, or a more complex data structure? Any potential issues I need to be aware of? Security implications? Performance bottlenecks? Let's take a closer look...
|
| 35/2 |
2026/09/02 01:34 |
tool |
grepper |
0m
Args: map[Expression:#define NULLB_DEVICE_ATTR PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=329=static ssize_t nullb_device_bool_attr_store(bool *val, const char *page,
--
drivers/block/null_blk/main.c-343-/* The following macro should only be used with TYPE = {uint, ulong, bool}. */
drivers/block/null_blk/main.c:344:#define NULLB_DEVICE_ATTR(NAME, TYPE, APPLY) \
drivers/block/null_blk/main.c-345-static ssize_t \
]
|
| 36/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 21094
output: 41
thoughts: 0
|
| 37/2 |
2026/09/02 01:34 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:drivers/block/null_blk/main.c Name:NULLB_DEVICE_ATTR]
Results: map[SourceCode: SourceFile:]
|
| 38/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 23746
output: 39
thoughts: 8
Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:
**Analyzing the Macro Definition**
Alright, the instruction is clear: we need to dive into this macro definition. My initial thought process? It's all about precision and efficiency. I'm going to quickly parse the structure – keywords, arguments, body – looking for the core logic. My immediate goal is to understand what the macro *does*, not just what it *says*. We're looking for potential performance bottlenecks, areas of complexity that could be simplified, or maybe even clever optimizations I might have overlooked in similar contexts. I'll mentally map the macro's behavior to known patterns and potential edge cases. This isn't just about understanding the syntax; it's about evaluating its *impact* on the overall system. Time to get to work!
|
| 39/2 |
2026/09/02 01:34 |
tool |
read-file |
0m
Args: map[File:drivers/block/null_blk/main.c FirstLine:344 LineCount:20]
Results: map[Contents: 344: #define NULLB_DEVICE_ATTR(NAME, TYPE, APPLY) \
345: static ssize_t \
346: nullb_device_##NAME##_show(struct config_item *item, char *page) \
347: { \
348: return nullb_device_##TYPE##_attr_show( \
349: to_nullb_device(item)->NAME, page); \
350: } \
351: static ssize_t \
352: nullb_device_##NAME##_store(struct config_item *item, const char *page, \
353: size_t count) \
354: { \
355: int (*apply_fn)(struct nullb_device *dev, TYPE new_value) = APPLY;\
356: struct nullb_device *dev = to_nullb_device(item); \
357: TYPE new_value = 0; \
358: int ret; \
359: \
360: ret = nullb_device_##TYPE##_attr_store(&new_value, page, count);\
361: if (ret < 0) \
362: return ret; \
363: if (apply_fn) \
]
|
| 40/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 24357
output: 39
thoughts: 239
Thoughts: **Analyzing the Null Block Device Memory Backing**
Okay, let me break this down. I'm looking at how the `nullb_device_attr_memory_backed` attribute works. Right, so `APPLY` is `NULL`, which means it directly sets `dev->memory_backed`. Straightforward enough. But now I'm remembering that `null_validate_conf` is called within `null_add_dev`.
```c
rv = null_validate_conf(dev);
if (rv)
return rv;
```
So, the validation happens during device creation, presumably whenever the device is actually instantiated – like when the `power` attribute is written to. And, crucial point, `null_validate_conf` then sets `dev->blocking = true` *if* `dev->memory_backed` is true. Then `null_setup_tagset` is called, and `BLK_MQ_F_BLOCKING` is set based on `dev->blocking`. This sequence should guarantee that if memory is backed, we block as needed, right?
But that doesn't quite add up. How can `BLK_MQ_F_BLOCKING` possibly be false while `dev->memory_backed` *is* true? There's a contradiction here. The most likely scenario is that `dev->memory_backed` is changed *after* the initial device creation and validation. The state could diverge, depending on the sequencing.
I need to confirm if that is possible: I need to check if `memory_backed` can be modified while the device is "powered on."
|
| 41/2 |
2026/09/02 01:34 |
tool |
read-file |
0m
Args: map[File:drivers/block/null_blk/main.c FirstLine:364 LineCount:20]
Results: map[Contents: 364: ret = apply_fn(dev, new_value); \
365: else if (test_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags)) \
366: ret = -EBUSY; \
367: if (ret < 0) \
368: return ret; \
369: dev->NAME = new_value; \
370: return count; \
371: } \
372: CONFIGFS_ATTR(nullb_device_, NAME);
373:
374: static int nullb_update_nr_hw_queues(struct nullb_device *dev,
375: unsigned int submit_queues,
376: unsigned int poll_queues)
377:
378: {
379: struct blk_mq_tag_set *set;
380: int ret, nr_hw_queues;
381:
382: if (!dev->nullb)
383: return 0;
]
|
| 42/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 22459
output: 38
thoughts: 0
|
| 43/2 |
2026/09/02 01:34 |
tool |
grepper |
0m
Error:
Args: map[Expression:nullb_device_memory_backed_store PathPrefix:drivers/block/null_blk/]
Results:
|
| 44/2 |
2026/09/02 01:34 |
llm |
expert |
0m
Model:
Tokens:
input: 22511
output: 38
thoughts: 0
|
| 45/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_device_attr_memory_backed PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=596=static struct configfs_attribute *nullb_device_attrs[] = {
--
drivers/block/null_blk/main.c-611- &nullb_device_attr_mbps,
drivers/block/null_blk/main.c:612: &nullb_device_attr_memory_backed,
drivers/block/null_blk/main.c-613- &nullb_device_attr_no_sched,
]
|
| 46/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 22685
output: 34
thoughts: 0
|
| 47/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_device_attrs PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=594=CONFIGFS_ATTR_WO(nullb_device_, zone_offline);
drivers/block/null_blk/main.c-595-
drivers/block/null_blk/main.c:596:static struct configfs_attribute *nullb_device_attrs[] = {
drivers/block/null_blk/main.c-597- &nullb_device_attr_badblocks,
--
drivers/block/null_blk/main.c=649=static const struct config_item_type nullb_device_type = {
drivers/block/null_blk/main.c-650- .ct_item_ops = &nullb_device_ops,
drivers/block/null_blk/main.c:651: .ct_attrs = nullb_device_attrs,
drivers/block/null_blk/main.c-652- .ct_owner = THIS_MODULE,
--
drivers/block/null_blk/main.c=719=static ssize_t memb_group_features_show(struct config_item *item, char *page)
--
drivers/block/null_blk/main.c-727-
drivers/block/null_blk/main.c:728: for (entry = &nullb_device_attrs[0]; *entry && left > 0; entry++) {
drivers/block/null_blk/main.c-729- if (!*(entry + 1))
]
|
| 48/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 23101
output: 41
thoughts: 0
|
| 49/2 |
2026/09/02 01:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_device_type]
Results: map[SourceCode: 649: static const struct config_item_type nullb_device_type = {
650: .ct_item_ops = &nullb_device_ops,
651: .ct_attrs = nullb_device_attrs,
652: .ct_owner = THIS_MODULE,
653: };
SourceFile:drivers/block/null_blk/main.c]
|
| 50/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 23267
output: 41
thoughts: 0
|
| 51/2 |
2026/09/02 01:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_device_ops]
Results: map[SourceCode: 645: static const struct configfs_item_operations nullb_device_ops = {
646: .release = nullb_device_release,
647: };
SourceFile:drivers/block/null_blk/main.c]
|
| 52/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 23392
output: 34
thoughts: 0
|
| 53/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_device_type PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=645=static const struct configfs_item_operations nullb_device_ops = {
--
drivers/block/null_blk/main.c-648-
drivers/block/null_blk/main.c:649:static const struct config_item_type nullb_device_type = {
drivers/block/null_blk/main.c-650- .ct_item_ops = &nullb_device_ops,
--
drivers/block/null_blk/main.c=687=config_group *nullb_group_make_group(struct config_group *group, const char *name)
--
drivers/block/null_blk/main.c-697-
drivers/block/null_blk/main.c:698: config_group_init_type_name(&dev->group, name, &nullb_device_type);
drivers/block/null_blk/main.c-699- nullb_add_fault_config(dev);
]
|
| 54/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 23692
output: 43
thoughts: 0
|
| 55/2 |
2026/09/02 01:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_group_make_group]
Results: map[SourceCode: 686: static struct
687: config_group *nullb_group_make_group(struct config_group *group, const char *name)
688: {
689: struct nullb_device *dev;
690:
691: if (null_find_dev_by_name(name))
692: return ERR_PTR(-EEXIST);
693:
694: dev = null_alloc_dev();
695: if (!dev)
696: return ERR_PTR(-ENOMEM);
697:
698: config_group_init_type_name(&dev->group, name, &nullb_device_type);
699: nullb_add_fault_config(dev);
700:
701: return &dev->group;
702: }
SourceFile:drivers/block/null_blk/main.c]
|
| 56/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 26846
output: 36
thoughts: 238
Thoughts: **My Line of Reasoning**
Okay, so I'm thinking about how the `dev->memory_backed` and `dev->blocking` flags interact, specifically in relation to ConfigFS. It just hit me: `dev->memory_backed` can actually be modified through ConfigFS! And that's where things get interesting. I know that if `dev->memory_backed` is set to true, the `dev->blocking` flag isn't automatically updated. It only gets changed when `null_validate_conf` is called.
Now, where is `null_validate_conf` invoked? Ah, yes, it's called within `null_add_dev`, which gets triggered when the "power" attribute is set to 1. So, here's the sequence: if I set `memory_backed=1` through ConfigFS, and *then* set `power=1`, `null_validate_conf` will be executed, and `dev->blocking` will be set to 1. Good.
But wait, can `memory_backed=1` also be set via a module parameter? Let me check… Yes, `g_memory_backed` is a module parameter! If `g_memory_backed` is set to 1, then `dev->memory_backed` is initialized to 1 in `null_alloc_dev`. Then, just like before, `null_validate_conf` would be called, and `dev->blocking` would be set to 1.
So the million-dollar question: how can I get a scenario where `dev->memory_backed` is true but `dev->blocking` is false? I need to figure out what could cause `dev->blocking` to *not* be set to true when `memory_backed` is true. Is it possible to set `dev->blocking` to false through ConfigFS? That's the next avenue to explore.
|
| 57/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:NULLB_DEVICE_ATTR\(blocking PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=455=NULLB_DEVICE_ATTR(index, uint, NULL);
drivers/block/null_blk/main.c:456:NULLB_DEVICE_ATTR(blocking, bool, NULL);
drivers/block/null_blk/main.c-457-NULLB_DEVICE_ATTR(use_per_node_hctx, bool, NULL);
]
|
| 58/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 24562
output: 36
thoughts: 0
|
| 59/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_group_make_group PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=686=static struct
drivers/block/null_blk/main.c:687:config_group *nullb_group_make_group(struct config_group *group, const char *name)
drivers/block/null_blk/main.c-688-{
--
drivers/block/null_blk/main.c=752=static const struct configfs_group_operations nullb_group_ops = {
drivers/block/null_blk/main.c:753: .make_group = nullb_group_make_group,
drivers/block/null_blk/main.c-754- .drop_item = nullb_group_drop_item,
]
|
| 60/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 24790
output: 41
thoughts: 0
|
| 61/2 |
2026/09/02 01:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_group_ops]
Results: map[SourceCode: 752: static const struct configfs_group_operations nullb_group_ops = {
753: .make_group = nullb_group_make_group,
754: .drop_item = nullb_group_drop_item,
755: };
SourceFile:drivers/block/null_blk/main.c]
|
| 62/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 24941
output: 34
thoughts: 0
|
| 63/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_group_ops PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=747=static struct configfs_attribute *nullb_group_attrs[] = {
--
drivers/block/null_blk/main.c-751-
drivers/block/null_blk/main.c:752:static const struct configfs_group_operations nullb_group_ops = {
drivers/block/null_blk/main.c-753- .make_group = nullb_group_make_group,
--
drivers/block/null_blk/main.c=757=static const struct config_item_type nullb_group_type = {
drivers/block/null_blk/main.c:758: .ct_group_ops = &nullb_group_ops,
drivers/block/null_blk/main.c-759- .ct_attrs = nullb_group_attrs,
]
|
| 64/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 25206
output: 41
thoughts: 0
|
| 65/2 |
2026/09/02 01:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_group_type]
Results: map[SourceCode: 757: static const struct config_item_type nullb_group_type = {
758: .ct_group_ops = &nullb_group_ops,
759: .ct_attrs = nullb_group_attrs,
760: .ct_owner = THIS_MODULE,
761: };
SourceFile:drivers/block/null_blk/main.c]
|
| 66/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 25372
output: 34
thoughts: 0
|
| 67/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_group_type PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=752=static const struct configfs_group_operations nullb_group_ops = {
--
drivers/block/null_blk/main.c-756-
drivers/block/null_blk/main.c:757:static const struct config_item_type nullb_group_type = {
drivers/block/null_blk/main.c-758- .ct_group_ops = &nullb_group_ops,
--
drivers/block/null_blk/main.c=763=static struct configfs_subsystem nullb_subsys = {
--
drivers/block/null_blk/main.c-766- .ci_namebuf = "nullb",
drivers/block/null_blk/main.c:767: .ci_type = &nullb_group_type,
drivers/block/null_blk/main.c-768- },
]
|
| 68/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 25651
output: 40
thoughts: 0
|
| 69/2 |
2026/09/02 01:35 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_subsys]
Results: map[SourceCode: 763: static struct configfs_subsystem nullb_subsys = {
764: .su_group = {
765: .cg_item = {
766: .ci_namebuf = "nullb",
767: .ci_type = &nullb_group_type,
768: },
769: },
770: };
SourceFile:drivers/block/null_blk/main.c]
|
| 70/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 25833
output: 33
thoughts: 0
|
| 71/2 |
2026/09/02 01:35 |
tool |
grepper |
0m
Args: map[Expression:nullb_subsys PathPrefix:drivers/block/null_blk/]
Results: map[Output:drivers/block/null_blk/main.c=757=static const struct config_item_type nullb_group_type = {
--
drivers/block/null_blk/main.c-762-
drivers/block/null_blk/main.c:763:static struct configfs_subsystem nullb_subsys = {
drivers/block/null_blk/main.c-764- .su_group = {
--
drivers/block/null_blk/main.c=2125=static int __init null_init(void)
--
drivers/block/null_blk/main.c-2161-
drivers/block/null_blk/main.c:2162: config_group_init(&nullb_subsys.su_group);
drivers/block/null_blk/main.c:2163: mutex_init(&nullb_subsys.su_mutex);
drivers/block/null_blk/main.c-2164-
drivers/block/null_blk/main.c:2165: ret = configfs_register_subsystem(&nullb_subsys);
drivers/block/null_blk/main.c-2166- if (ret)
--
drivers/block/null_blk/main.c-2192-err_conf:
drivers/block/null_blk/main.c:2193: configfs_unregister_subsystem(&nullb_subsys);
drivers/block/null_blk/main.c-2194- return ret;
--
drivers/block/null_blk/main.c=2197=static void __exit null_exit(void)
--
drivers/block/null_blk/main.c-2200-
drivers/block/null_blk/main.c:2201: configfs_unregister_subsystem(&nullb_subsys);
drivers/block/null_blk/main.c-2202-
]
|
| 72/2 |
2026/09/02 01:35 |
llm |
expert |
0m
Model:
Tokens:
input: 26359
output: 32
thoughts: 0
|
| 73/2 |
2026/09/02 01:36 |
tool |
grepper |
0m
Args: map[Expression:configfs_register_subsystem PathPrefix:fs/configfs/]
Results: map[Output:fs/configfs/dir.c=992=static int configfs_dump(struct configfs_dirent *sd, int level)
--
fs/configfs/dir.c-1034- * subsystem isn't registered, or when configfs is loading or unloading.
fs/configfs/dir.c:1035: * Just like configfs_register_subsystem(). So we take the same
fs/configfs/dir.c-1036- * precautions. We pin the filesystem. We lock configfs_dirent_lock.
--
fs/configfs/dir.c=1870=EXPORT_SYMBOL(configfs_unregister_default_group);
fs/configfs/dir.c-1871-
fs/configfs/dir.c:1872:int configfs_register_subsystem(struct configfs_subsystem *subsys)
fs/configfs/dir.c-1873-{
--
fs/configfs/dir.c=1934=void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
--
fs/configfs/dir.c-1978-
fs/configfs/dir.c:1979:EXPORT_SYMBOL(configfs_register_subsystem);
fs/configfs/dir.c-1980-EXPORT_SYMBOL(configfs_unregister_subsystem);
]
|
| 74/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 26737
output: 39
thoughts: 0
|
| 75/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/configfs/dir.c Name:configfs_register_subsystem]
Results: map[SourceCode:1872: int configfs_register_subsystem(struct configfs_subsystem *subsys)
1873: {
1874: int err;
1875: struct config_group *group = &subsys->su_group;
1876: struct dentry *dentry;
1877: struct dentry *root;
1878: struct configfs_dirent *sd;
1879: struct configfs_fragment *frag;
1880:
1881: frag = new_fragment();
1882: if (!frag)
1883: return -ENOMEM;
1884:
1885: root = configfs_pin_fs();
1886: if (IS_ERR(root)) {
1887: put_fragment(frag);
1888: return PTR_ERR(root);
1889: }
1890:
1891: if (!group->cg_item.ci_name)
1892: group->cg_item.ci_name = group->cg_item.ci_namebuf;
1893:
1894: sd = root->d_fsdata;
1895: mutex_lock(&configfs_subsystem_mutex);
1896: link_group(to_config_group(sd->s_element), group);
1897: mutex_unlock(&configfs_subsystem_mutex);
1898:
1899: inode_lock_nested(d_inode(root), I_MUTEX_PARENT);
1900:
1901: err = -ENOMEM;
1902: dentry = d_alloc_name(root, group->cg_item.ci_name);
1903: if (dentry) {
1904: d_add(dentry, NULL);
1905:
1906: err = configfs_dirent_exists(dentry);
1907: if (!err)
1908: err = configfs_attach_group(&group->cg_item,
1909: dentry, frag);
1910: if (err) {
1911: BUG_ON(d_inode(dentry));
1912: d_drop(dentry);
1913: } else {
1914: spin_lock(&configfs_dirent_lock);
1915: configfs_dir_set_ready(dentry->d_fsdata);
1916: spin_unlock(&configfs_dirent_lock);
1917: }
1918: dput(dentry);
1919: }
1920:
1921: inode_unlock(d_inode(root));
1922:
1923: if (err) {
1924: mutex_lock(&configfs_subsystem_mutex);
1925: unlink_group(group);
1926: mutex_unlock(&configfs_subsystem_mutex);
1927: configfs_release_fs();
1928: }
1929: put_fragment(frag);
1930:
1931: return err;
1932: }
SourceFile:fs/configfs/dir.c]
|
| 76/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 27672
output: 31
thoughts: 0
|
| 77/2 |
2026/09/02 01:36 |
tool |
grepper |
0m
Args: map[Expression:configfs_pin_fs PathPrefix:fs/configfs/]
Results: map[Output:fs/configfs/configfs_internal.h=79=extern int configfs_setattr(struct mnt_idmap *idmap,
--
fs/configfs/configfs_internal.h-81-
fs/configfs/configfs_internal.h:82:extern struct dentry *configfs_pin_fs(void);
fs/configfs/configfs_internal.h-83-extern void configfs_release_fs(void);
--
fs/configfs/dir.c=1143=int configfs_depend_item(struct configfs_subsystem *subsys,
--
fs/configfs/dir.c-1154- */
fs/configfs/dir.c:1155: root = configfs_pin_fs();
fs/configfs/dir.c-1156- if (IS_ERR(root))
--
fs/configfs/dir.c=1872=int configfs_register_subsystem(struct configfs_subsystem *subsys)
--
fs/configfs/dir.c-1884-
fs/configfs/dir.c:1885: root = configfs_pin_fs();
fs/configfs/dir.c-1886- if (IS_ERR(root)) {
--
fs/configfs/mount.c=121=MODULE_ALIAS_FS("configfs");
fs/configfs/mount.c-122-
fs/configfs/mount.c:123:struct dentry *configfs_pin_fs(void)
fs/configfs/mount.c-124-{
]
|
| 78/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 31185
output: 38
thoughts: 0
|
| 79/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/configfs/mount.c Name:configfs_pin_fs]
Results: map[SourceCode: 123: struct dentry *configfs_pin_fs(void)
124: {
125: int err = simple_pin_fs(&configfs_fs_type, &configfs_mount,
126: &configfs_mnt_count);
127: return err ? ERR_PTR(err) : configfs_mount->mnt_root;
128: }
SourceFile:fs/configfs/mount.c]
|
| 80/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 31361
output: 43
thoughts: 445
Thoughts: **Analyzing a Potential Kernel Bug**
Okay, so configfs is mounted by root, which is the starting point. I need to figure out if I can trigger this bug without involving configfs. Looking at the code, `null_blk` seems promising. It creates block devices on module load using `nr_devices`, and that parameter is a global variable. For example, `g_memory_backed`.
If `g_memory_backed` is set to 1, then `dev->memory_backed` becomes 1, and consequently, `dev->blocking` becomes 1. This means `BLK_MQ_F_BLOCKING` gets set, which is interesting. Wait, looking closer, `dev->blocking` is set to 1 within `null_validate_conf` if `g_memory_backed=1`. So, it definitely sets `BLK_MQ_F_BLOCKING`!
Now, when `__blk_mq_run_dispatch_ops` is executed, it uses `srcu_read_lock` and `might_sleep_if(check_sleep)`. Crucially, it *doesn't* use `rcu_read_lock`. So the bug report claiming `rcu_read_lock` is held has me puzzled.
Let's re-examine `null_validate_conf`. Specifically, this section:
```c
/* Do memory allocation, so set blocking */
if (dev->memory_backed)
dev->blocking = true;
```
I'm starting to wonder, what if `dev->memory_backed` is modified via configfs *after* `null_validate_conf` is called? But, `null_validate_conf` is called inside `null_add_dev`, which is the function that actually creates the block device (by calling `add_disk`). So changing it *after* the device creation might not be possible, as `nullb_device_bool_attr_store` should check `test_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags)` and return an `-EBUSY` error.
Hang on. `NULLB_DEV_FL_CONFIGURED` is set when `power` is set to 1. That's a key detail! I need to check `nullb_device_power_store` to confirm my suspicion.
|
| 81/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_device_power_store]
Results: map[SourceCode: 484: static ssize_t nullb_device_power_store(struct config_item *item,
485: const char *page, size_t count)
486: {
487: struct nullb_device *dev = to_nullb_device(item);
488: bool newp = false;
489: ssize_t ret;
490:
491: ret = nullb_device_bool_attr_store(&newp, page, count);
492: if (ret < 0)
493: return ret;
494:
495: ret = count;
496: mutex_lock(&lock);
497: if (!dev->power && newp) {
498: if (test_and_set_bit(NULLB_DEV_FL_UP, &dev->flags))
499: goto out;
500:
501: ret = null_add_dev(dev);
502: if (ret) {
503: clear_bit(NULLB_DEV_FL_UP, &dev->flags);
504: goto out;
505: }
506:
507: set_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags);
508: dev->power = newp;
509: ret = count;
510: } else if (dev->power && !newp) {
511: if (test_and_clear_bit(NULLB_DEV_FL_UP, &dev->flags)) {
512: dev->power = newp;
513: null_del_dev(dev->nullb);
514: }
515: clear_bit(NULLB_DEV_FL_CONFIGURED, &dev->flags);
516: }
517:
518: out:
519: mutex_unlock(&lock);
520: return ret;
521: }
SourceFile:drivers/block/null_blk/main.c]
|
| 82/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 29431
output: 42
thoughts: 0
|
| 83/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_handle_memory_backed]
Results: map[SourceCode:1372: blk_status_t null_handle_memory_backed(struct nullb_cmd *cmd, enum req_op op,
1373: sector_t sector, sector_t nr_sectors)
1374: {
1375: struct nullb_device *dev = cmd->nq->dev;
1376:
1377: if (op == REQ_OP_DISCARD)
1378: return null_handle_discard(dev, sector, nr_sectors);
1379:
1380: return null_handle_data_transfer(cmd, nr_sectors);
1381: }
SourceFile:drivers/block/null_blk/main.c]
|
| 84/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 29675
output: 42
thoughts: 0
|
| 85/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_handle_data_transfer]
Results: map[SourceCode:1278: /*
1279: * Transfer data for the given request. The transfer size is capped with the
1280: * nr_sectors argument.
1281: */
1282: static blk_status_t null_handle_data_transfer(struct nullb_cmd *cmd,
1283: sector_t nr_sectors)
1284: {
1285: struct request *rq = blk_mq_rq_from_pdu(cmd);
1286: struct nullb *nullb = cmd->nq->dev->nullb;
1287: blk_status_t err = BLK_STS_OK;
1288: unsigned int len;
1289: loff_t pos = blk_rq_pos(rq) << SECTOR_SHIFT;
1290: unsigned int max_bytes = nr_sectors << SECTOR_SHIFT;
1291: unsigned int transferred_bytes = 0;
1292: struct req_iterator iter;
1293: struct bio_vec bvec;
1294:
1295: spin_lock_irq(&nullb->lock);
1296: rq_for_each_segment(bvec, rq, iter) {
1297: len = bvec.bv_len;
1298: if (transferred_bytes + len > max_bytes)
1299: len = max_bytes - transferred_bytes;
1300: err = null_transfer(nullb, bvec.bv_page, len, bvec.bv_offset,
1301: op_is_write(req_op(rq)), pos,
1302: rq->cmd_flags & REQ_FUA);
1303: if (err)
1304: break;
1305: pos += len;
1306: transferred_bytes += len;
1307: if (transferred_bytes >= max_bytes)
1308: break;
1309: }
1310: spin_unlock_irq(&nullb->lock);
1311:
1312: return err;
1313: }
SourceFile:drivers/block/null_blk/main.c]
|
| 86/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 30328
output: 38
thoughts: 0
|
| 87/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_transfer]
Results: map[SourceCode:1242: static blk_status_t null_transfer(struct nullb *nullb, struct page *page,
1243: unsigned int len, unsigned int off, bool is_write, loff_t pos,
1244: bool is_fua)
1245: {
1246: struct nullb_device *dev = nullb->dev;
1247: blk_status_t err = BLK_STS_OK;
1248: unsigned int valid_len = len;
1249: void *p;
1250:
1251: p = kmap_local_page(page) + off;
1252: if (!is_write) {
1253: if (dev->zoned) {
1254: valid_len = null_zone_valid_read_len(nullb,
1255: pos >> SECTOR_SHIFT, len);
1256: if (valid_len && valid_len != len)
1257: valid_len -= pos & (SECTOR_SIZE - 1);
1258: }
1259:
1260: if (valid_len) {
1261: copy_from_nullb(nullb, p, pos, valid_len);
1262: off += valid_len;
1263: len -= valid_len;
1264: }
1265:
1266: if (len)
1267: memset(p + valid_len, 0xff, len);
1268: flush_dcache_page(page);
1269: } else {
1270: flush_dcache_page(page);
1271: err = copy_to_nullb(nullb, p, pos, len, is_fua);
1272: }
1273:
1274: kunmap_local(p);
1275: return err;
1276: }
SourceFile:drivers/block/null_blk/main.c]
|
| 88/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 30927
output: 41
thoughts: 0
|
| 89/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:copy_to_nullb]
Results: map[SourceCode:1142: static blk_status_t copy_to_nullb(struct nullb *nullb, void *source,
1143: loff_t pos, size_t n, bool is_fua)
1144: {
1145: size_t temp, count = 0;
1146: struct nullb_page *t_page;
1147: sector_t sector;
1148:
1149: while (count < n) {
1150: temp = min3(nullb->dev->blocksize, n - count,
1151: PAGE_SIZE - offset_in_page(pos));
1152: sector = pos >> SECTOR_SHIFT;
1153:
1154: if (null_cache_active(nullb) && !is_fua)
1155: null_make_cache_space(nullb, PAGE_SIZE);
1156:
1157: t_page = null_insert_page(nullb, sector,
1158: !null_cache_active(nullb) || is_fua);
1159: if (!t_page)
1160: return BLK_STS_NOSPC;
1161:
1162: memcpy_to_page(t_page->page, offset_in_page(pos),
1163: source + count, temp);
1164:
1165: __set_bit(sector & SECTOR_MASK, t_page->bitmap);
1166:
1167: if (is_fua)
1168: null_free_sector(nullb, sector, true);
1169:
1170: count += temp;
1171: pos += temp;
1172: }
1173: return BLK_STS_OK;
1174: }
SourceFile:drivers/block/null_blk/main.c]
|
| 90/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 31509
output: 40
thoughts: 0
|
| 91/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_insert_page]
Results: map[SourceCode:1005: static struct nullb_page *null_insert_page(struct nullb *nullb,
1006: sector_t sector, bool ignore_cache)
1007: __releases(&nullb->lock)
1008: __acquires(&nullb->lock)
1009: {
1010: u64 idx;
1011: struct nullb_page *t_page;
1012:
1013: t_page = null_lookup_page(nullb, sector, true, ignore_cache);
1014: if (t_page)
1015: return t_page;
1016:
1017: spin_unlock_irq(&nullb->lock);
1018:
1019: t_page = null_alloc_page();
1020: if (!t_page)
1021: goto out_lock;
1022:
1023: if (radix_tree_preload(GFP_NOIO))
1024: goto out_freepage;
1025:
1026: spin_lock_irq(&nullb->lock);
1027: idx = sector >> PAGE_SECTORS_SHIFT;
1028: t_page->page->private = idx;
1029: t_page = null_radix_tree_insert(nullb, idx, t_page, !ignore_cache);
1030: radix_tree_preload_end();
1031:
1032: return t_page;
1033: out_freepage:
1034: null_free_page(t_page);
1035: out_lock:
1036: spin_lock_irq(&nullb->lock);
1037: return null_lookup_page(nullb, sector, true, ignore_cache);
1038: }
SourceFile:drivers/block/null_blk/main.c]
|
| 92/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 32095
output: 40
thoughts: 0
|
| 93/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_alloc_page]
Results: map[SourceCode: 866: static struct nullb_page *null_alloc_page(void)
867: {
868: struct nullb_page *t_page;
869:
870: t_page = kmalloc_obj(struct nullb_page, GFP_NOIO);
871: if (!t_page)
872: return NULL;
873:
874: t_page->page = alloc_pages(GFP_NOIO, 0);
875: if (!t_page->page) {
876: kfree(t_page);
877: return NULL;
878: }
879:
880: memset(t_page->bitmap, 0, sizeof(t_page->bitmap));
881: return t_page;
882: }
SourceFile:drivers/block/null_blk/main.c]
|
| 94/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 32406
output: 40
thoughts: 0
|
| 95/2 |
2026/09/02 01:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_handle_cmd]
Results: map[SourceCode:1442: static void null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
1443: sector_t nr_sectors, enum req_op op)
1444: {
1445: struct nullb_device *dev = cmd->nq->dev;
1446: struct nullb *nullb = dev->nullb;
1447: blk_status_t sts;
1448:
1449: if (op == REQ_OP_FLUSH) {
1450: cmd->error = null_handle_flush(nullb);
1451: goto out;
1452: }
1453:
1454: if (dev->zoned)
1455: sts = null_process_zoned_cmd(cmd, op, sector, nr_sectors);
1456: else
1457: sts = null_process_cmd(cmd, op, sector, nr_sectors);
1458:
1459: /* Do not overwrite errors (e.g. timeout errors) */
1460: if (cmd->error == BLK_STS_OK)
1461: cmd->error = sts;
1462:
1463: out:
1464: nullb_complete_cmd(cmd);
1465: }
SourceFile:drivers/block/null_blk/main.c]
|
| 96/2 |
2026/09/02 01:36 |
llm |
expert |
0m
Model:
Tokens:
input: 36357
output: 45
thoughts: 1357
Thoughts: **Debugging a Potential Sleep-in-Atomic Context in the Null Block Driver**
Okay, let's break this down. My initial suspicion was that a spinlock wasn't being properly unlocked before a potentially sleeping function (`null_alloc_page`) was called. Specifically, `null_handle_data_transfer` locks the `nullb->lock`, then a page allocation happens, and there was a possibility that the lock was not being released, which would be bad. My initial tracing led me through the `null_transfer` path to `null_insert_page`. I noticed the unlock before `null_alloc_page()`. The fact that `null_alloc_page` uses `GFP_NOIO` means it *can* sleep. The problem is that `null_alloc_page` is sometimes called with a lock held.
Then, I focused on the `blk_mq_run_dispatch_ops` function. I know that if `dev->memory_backed` is true, the driver *should* set `BLK_MQ_F_BLOCKING` which would mean that `blk_mq_run_dispatch_ops` should use `srcu_read_lock()` instead of `rcu_read_lock()`. I double-checked that `dev->blocking` is set correctly during device initialization by tracing `null_add_dev`, which calls `null_validate_conf`. This confirmed that `dev->blocking` is set to true when `dev->memory_backed` is true, and that `dev->blocking` is used to configure `BLK_MQ_F_BLOCKING` by the `null_setup_tagset` function. So it *should* work right.
However, the bug report shows `rcu_read_lock` being held and `in_atomic()` is 0, which suggests that `BLK_MQ_F_BLOCKING` is NOT set. So, this seemed wrong.
Looking back at the kernel's stack trace, I saw the call to `blk_mq_dispatch_queue_requests` and its place in `block/blk-mq.c:2872`. This function calls `blk_mq_run_dispatch_ops`. I know `blk_mq_run_dispatch_ops` is a macro, and, from that macro, it's clear: If `BLK_MQ_F_BLOCKING` is false, it uses `rcu_read_lock`, otherwise `srcu_read_lock` is used.
The fact that the bug report shows the `rcu_read_lock` being held means that, despite the checks I made, `BLK_MQ_F_BLOCKING` *isn't* set. But I know `null_handle_memory_backed` is called, which means `dev->memory_backed` *is* true. So, now, the question is: how can `dev->memory_backed` be true but `BLK_MQ_F_BLOCKING` be false? Is there a point where `dev->memory_backed` is set and then *later*, after the flag has been set, the flag gets cleared, or the memory backing is changed? I need to double-check that the memory backing isn't changed after `null_add_dev`.
|
| 97/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:nullb_device_bool_attr_store]
Results: map[SourceCode: 329: static ssize_t nullb_device_bool_attr_store(bool *val, const char *page,
330: size_t count)
331: {
332: bool tmp;
333: int result;
334:
335: result = kstrtobool(page, &tmp);
336: if (result < 0)
337: return result;
338:
339: *val = tmp;
340: return count;
341: }
SourceFile:drivers/block/null_blk/main.c]
|
| 98/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 38658
output: 41
thoughts: 747
Thoughts: **Analyzing the Blocking Behavior in the NULLB Device Driver**
Okay, let's break this down. It looks like `nullb_device_bool_attr_store` is the workhorse for setting boolean attributes via the `NULLB_DEVICE_ATTR` macro. I'm focusing on how `blocking` behaves, specifically in relation to `memory_backed`. The core of the issue is this: if the `APPLY` function is `NULL` within `NULLB_DEVICE_ATTR`, and `NULLB_DEV_FL_CONFIGURED` is set, we get `-EBUSY`. This means certain attributes become immutable after the device is "configured" or powered on, based on my understanding of `NULLB_DEV_FL_CONFIGURED`.
So, can I change `memory_backed` after the device is configured? Nope, because `NULLB_DEVICE_ATTR` prevents it via that `-EBUSY` return. But what about a scenario where `memory_backed` is true, but `blocking` is *explicitly* set to false after configuration? I see that `blocking` *is* an attribute, defined with `NULLB_DEVICE_ATTR(blocking, bool, NULL);`. So, it's configurable. My initial hypothesis is that I can set it to false after the device is configured.
Let's assume a specific sequence: `memory_backed = 1`, then `power = 1`. In this case, `null_validate_conf` will set `blocking = 1`. Can I subsequently set `blocking = 0`? The answer is no, because `NULLB_DEV_FL_CONFIGURED` will be set when the device is "on", and `-EBUSY` will be returned.
Alright, so what if I try to *preemptively* set `blocking = 0` *before* powering on the device? Let's walk through the device initialization (`null_add_dev`). I see `null_validate_conf` is called.
Inside `null_validate_conf`: Ah, here's the kicker!
```c
/* Do memory allocation, so set blocking */
if (dev->memory_backed)
dev->blocking = true;
```
Even if I try to set `blocking = 0` *before* the "power on" step (and thus configuration), `null_validate_conf` will *overwrite* it to `true` if `memory_backed` is true. The logic forces `dev->blocking` to always be true if memory is backed. So, even though I've set the value, `null_validate_conf` will update it.
So, `dev->blocking` will be `true`, and later, `null_setup_tagset` will set `BLK_MQ_F_BLOCKING`. Therefore `BLK_MQ_F_BLOCKING` is correctly set.
Now the million-dollar question: Is there any *other* way I could end up with `memory_backed` being true, but `BLK_MQ_F_BLOCKING` being false? The code clearly sets them together when the device is set. I'll need to double check other configuration options, such as `dev->shared_tags`. I'll have to consider this to ensure all potential configuration paths are covered.
|
| 99/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_setup_tagset]
Results: map[SourceCode:1864: static int null_setup_tagset(struct nullb *nullb)
1865: {
1866: if (nullb->dev->shared_tags) {
1867: nullb->tag_set = &tag_set;
1868: return null_init_global_tag_set();
1869: }
1870:
1871: nullb->tag_set = &nullb->__tag_set;
1872: nullb->tag_set->driver_data = nullb;
1873: nullb->tag_set->nr_hw_queues = nullb->dev->submit_queues;
1874: nullb->tag_set->queue_depth = nullb->dev->hw_queue_depth;
1875: nullb->tag_set->numa_node = nullb->dev->home_node;
1876: if (nullb->dev->no_sched)
1877: nullb->tag_set->flags |= BLK_MQ_F_NO_SCHED_BY_DEFAULT;
1878: if (nullb->dev->shared_tag_bitmap)
1879: nullb->tag_set->flags |= BLK_MQ_F_TAG_HCTX_SHARED;
1880: if (nullb->dev->blocking)
1881: nullb->tag_set->flags |= BLK_MQ_F_BLOCKING;
1882: return null_init_tag_set(nullb->tag_set, nullb->dev->poll_queues);
1883: }
SourceFile:drivers/block/null_blk/main.c]
|
| 100/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 40615
output: 44
thoughts: 56
Thoughts: Okay, here we go...
**Initial Assessment: Tag Management in Null Device Initialization**
Aha! My mind immediately latches onto a critical conditional. If the `nullb->dev->shared_tags` flag is set to true, the code is employing `&tag_set` and executing a function called `null_init_global_tag_set()`. This is significant! This tells me that we are in a shared tag scenario, and I need to understand how the global tag set is being initialized within that context. Therefore, my next step is clear. Let's delve directly into the implementation of `null_init_global_tag_set()` to comprehend how these shared tags are set up.
|
| 101/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_init_global_tag_set]
Results: map[SourceCode:1841: static int null_init_global_tag_set(void)
1842: {
1843: int error;
1844:
1845: if (tag_set.ops)
1846: return 0;
1847:
1848: tag_set.nr_hw_queues = g_submit_queues;
1849: tag_set.queue_depth = g_hw_queue_depth;
1850: tag_set.numa_node = g_home_node;
1851: if (g_no_sched)
1852: tag_set.flags |= BLK_MQ_F_NO_SCHED_BY_DEFAULT;
1853: if (g_shared_tag_bitmap)
1854: tag_set.flags |= BLK_MQ_F_TAG_HCTX_SHARED;
1855: if (g_blocking)
1856: tag_set.flags |= BLK_MQ_F_BLOCKING;
1857:
1858: error = null_init_tag_set(&tag_set, g_poll_queues);
1859: if (error)
1860: tag_set.ops = NULL;
1861: return error;
1862: }
SourceFile:drivers/block/null_blk/main.c]
|
| 102/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 35570
output: 42
thoughts: 0
|
| 103/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_init_tag_set]
Results: map[SourceCode:1828: static int null_init_tag_set(struct blk_mq_tag_set *set, int poll_queues)
1829: {
1830: set->ops = &null_mq_ops;
1831: set->cmd_size = sizeof(struct nullb_cmd);
1832: set->timeout = 5 * HZ;
1833: set->nr_maps = 1;
1834: if (poll_queues) {
1835: set->nr_hw_queues += poll_queues;
1836: set->nr_maps += 2;
1837: }
1838: return blk_mq_alloc_tag_set(set);
1839: }
SourceFile:drivers/block/null_blk/main.c]
|
| 104/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 35850
output: 40
thoughts: 0
|
| 105/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_mq_ops]
Results: map[SourceCode:1748: static const struct blk_mq_ops null_mq_ops = {
1749: .queue_rq = null_queue_rq,
1750: .queue_rqs = null_queue_rqs,
1751: .complete = null_complete_rq,
1752: .timeout = null_timeout_rq,
1753: .poll = null_poll,
1754: .map_queues = null_map_queues,
1755: .init_hctx = null_init_hctx,
1756: };
SourceFile:drivers/block/null_blk/main.c]
|
| 106/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 36086
output: 40
thoughts: 0
|
| 107/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_queue_rq]
Results: map[SourceCode:1652: static blk_status_t null_queue_rq(struct blk_mq_hw_ctx *hctx,
1653: const struct blk_mq_queue_data *bd)
1654: {
1655: struct request *rq = bd->rq;
1656: struct nullb_cmd *cmd = blk_mq_rq_to_pdu(rq);
1657: struct nullb_queue *nq = hctx->driver_data;
1658: sector_t nr_sectors = blk_rq_sectors(rq);
1659: sector_t sector = blk_rq_pos(rq);
1660: const bool is_poll = hctx->type == HCTX_TYPE_POLL;
1661:
1662: might_sleep_if(hctx->flags & BLK_MQ_F_BLOCKING);
1663:
1664: if (!is_poll && nq->dev->irqmode == NULL_IRQ_TIMER) {
1665: hrtimer_setup(&cmd->timer, null_cmd_timer_expired, CLOCK_MONOTONIC,
1666: HRTIMER_MODE_REL);
1667: }
1668: cmd->error = BLK_STS_OK;
1669: cmd->nq = nq;
1670: cmd->fake_timeout = should_timeout_request(rq) ||
1671: blk_should_fake_timeout(rq->q);
1672:
1673: if (should_requeue_request(rq)) {
1674: /*
1675: * Alternate between hitting the core BUSY path, and the
1676: * driver driven requeue path
1677: */
1678: nq->requeue_selection++;
1679: if (nq->requeue_selection & 1)
1680: return BLK_STS_RESOURCE;
1681: blk_mq_requeue_request(rq, true);
1682: return BLK_STS_OK;
1683: }
1684:
1685: if (test_bit(NULLB_DEV_FL_THROTTLED, &nq->dev->flags)) {
1686: blk_status_t sts = null_handle_throttled(cmd);
1687:
1688: if (sts != BLK_STS_OK)
1689: return sts;
1690: }
1691:
1692: blk_mq_start_request(rq);
1693:
1694: if (is_poll) {
1695: spin_lock(&nq->poll_lock);
1696: list_add_tail(&rq->queuelist, &nq->poll_list);
1697: spin_unlock(&nq->poll_lock);
1698: return BLK_STS_OK;
1699: }
1700: if (cmd->fake_timeout)
1701: return BLK_STS_OK;
1702:
1703: null_handle_cmd(cmd, sector, nr_sectors, req_op(rq));
1704: return BLK_STS_OK;
1705: }
SourceFile:drivers/block/null_blk/main.c]
|
| 108/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 42726
output: 38
thoughts: 394
Thoughts: **The Bug with Shared Tags and Memory-Backed Devices in `null_blk`**
Okay, here's what's finally clicked. Looking at `null_init_global_tag_set`, I see it uses `g_blocking` to set `BLK_MQ_F_BLOCKING`, not the device's own `dev->blocking` flag. That's a crucial distinction.
Now, if `g_shared_tags` is true, and `g_blocking` is *false* (which is the default, I believe), then `BLK_MQ_F_BLOCKING` is *not* set on the global tag set. But wait a minute... what if someone crafts a `null_blk` device through configfs with `shared_tags=1` *and* `memory_backed=1`?
If we're using `shared_tags=1`, it defaults to the global tag set. This global set is initialized using `g_blocking`. And if `g_blocking` is false, `BLK_MQ_F_BLOCKING` isn't set, as discussed. However, if `dev->memory_backed` is true (because we set it via configfs), `null_handle_memory_backed` is then called, which calls `null_alloc_page`. This allocates a page and puts the current task to sleep, and this sleep happens without the flag `BLK_MQ_F_BLOCKING` set! So what happens in `blk_mq_run_dispatch_ops`? Since we didn't set `BLK_MQ_F_BLOCKING`, it's going to use `rcu_read_lock()`! That's it! That's the bug. It's a classic rcu read-lock without the flag to indicate it's not a blocking request.
Let me confirm my hypothesis. If a user, specifically via configfs, creates a `null_blk` device with `shared_tags=1` and `memory_backed=1`, they will trigger this race condition. The device should sleep, and get a read-lock but no `BLK_MQ_F_BLOCKING` flag.
Can an unprivileged user do this? No, I believe configfs is only writable by root. What about via module loading? If we load the module with `shared_tags=1` and `memory_backed=1` as module parameters, wait, if `g_memory_backed=1`, then `g_blocking` is NOT automatically set to 1! I'm going to double check `null_init` right now to verify this.
|
| 109/2 |
2026/09/02 01:37 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:drivers/block/null_blk/main.c Name:null_init]
Results: map[SourceCode:2125: static int __init null_init(void)
2126: {
2127: int ret = 0;
2128: unsigned int i;
2129: struct nullb *nullb;
2130:
2131: if (g_bs > PAGE_SIZE) {
2132: pr_warn("invalid block size\n");
2133: pr_warn("defaults block size to %lu\n", PAGE_SIZE);
2134: g_bs = PAGE_SIZE;
2135: }
2136:
2137: if (g_home_node != NUMA_NO_NODE && g_home_node >= nr_online_nodes) {
2138: pr_err("invalid home_node value\n");
2139: g_home_node = NUMA_NO_NODE;
2140: }
2141:
2142: if (!null_setup_fault())
2143: return -EINVAL;
2144:
2145: if (g_queue_mode == NULL_Q_RQ) {
2146: pr_err("legacy IO path is no longer available\n");
2147: return -EINVAL;
2148: }
2149:
2150: if (g_use_per_node_hctx) {
2151: if (g_submit_queues != nr_online_nodes) {
2152: pr_warn("submit_queues param is set to %u.\n",
2153: nr_online_nodes);
2154: g_submit_queues = nr_online_nodes;
2155: }
2156: } else if (g_submit_queues > nr_cpu_ids) {
2157: g_submit_queues = nr_cpu_ids;
2158: } else if (g_submit_queues <= 0) {
2159: g_submit_queues = 1;
2160: }
2161:
2162: config_group_init(&nullb_subsys.su_group);
2163: mutex_init(&nullb_subsys.su_mutex);
2164:
2165: ret = configfs_register_subsystem(&nullb_subsys);
2166: if (ret)
2167: return ret;
2168:
2169: mutex_init(&lock);
2170:
2171: null_major = register_blkdev(0, "nullb");
2172: if (null_major < 0) {
2173: ret = null_major;
2174: goto err_conf;
2175: }
2176:
2177: for (i = 0; i < nr_devices; i++) {
2178: ret = null_create_dev();
2179: if (ret)
2180: goto err_dev;
2181: }
2182:
2183: pr_info("module loaded\n");
2184: return 0;
2185:
2186: err_dev:
2187: while (!list_empty(&nullb_list)) {
2188: nullb = list_entry(nullb_list.next, struct nullb, list);
2189: null_destroy_dev(nullb);
2190: }
2191: unregister_blkdev(null_major, "nullb");
2192: err_conf:
2193: configfs_unregister_subsystem(&nullb_subsys);
2194: return ret;
2195: }
SourceFile:drivers/block/null_blk/main.c]
|
| 110/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 38701
output: 66
thoughts: 0
|
| 111/2 |
2026/09/02 01:37 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 112/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 38831
output: 27
thoughts: 0
|
| 113/2 |
2026/09/02 01:37 |
tool |
grepper |
0m
Args: map[Expression:configfs_register_subsystem PathPrefix:]
Results: map[Output:Documentation/filesystems/configfs.rst=345=tells configfs to make the subsystem appear in the file tree::
--
Documentation/filesystems/configfs.rst-351-
Documentation/filesystems/configfs.rst:352: int configfs_register_subsystem(struct configfs_subsystem *subsys);
Documentation/filesystems/configfs.rst-353- void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
--
Documentation/filesystems/configfs.rst=357=this group is usually defined statically. Before calling
Documentation/filesystems/configfs.rst:358:configfs_register_subsystem(), the subsystem must have initialized the
Documentation/filesystems/configfs.rst-359-group via the usual group _init() functions, and it must also have
--
drivers/acpi/acpi_configfs.c=255=static int __init acpi_configfs_init(void)
--
drivers/acpi/acpi_configfs.c-261-
drivers/acpi/acpi_configfs.c:262: ret = configfs_register_subsystem(&acpi_configfs);
drivers/acpi/acpi_configfs.c-263- if (ret)
--
drivers/block/null_blk/main.c=2125=static int __init null_init(void)
--
drivers/block/null_blk/main.c-2164-
drivers/block/null_blk/main.c:2165: ret = configfs_register_subsystem(&nullb_subsys);
drivers/block/null_blk/main.c-2166- if (ret)
--
drivers/gpio/gpio-aggregator.c=1695=static int __init gpio_aggregator_init(void)
--
drivers/gpio/gpio-aggregator.c-1700- mutex_init(&gpio_aggregator_subsys.su_mutex);
drivers/gpio/gpio-aggregator.c:1701: ret = configfs_register_subsystem(&gpio_aggregator_subsys);
drivers/gpio/gpio-aggregator.c-1702- if (ret) {
--
drivers/gpio/gpio-sim.c=1608=static int __init gpio_sim_init(void)
--
drivers/gpio/gpio-sim.c-1619- mutex_init(&gpio_sim_config_subsys.su_mutex);
drivers/gpio/gpio-sim.c:1620: ret = configfs_register_subsystem(&gpio_sim_config_subsys);
drivers/gpio/gpio-sim.c-1621- if (ret) {
--
drivers/gpio/gpio-virtuser.c=1761=static int __init gpio_virtuser_init(void)
--
drivers/gpio/gpio-virtuser.c-1772- mutex_init(&gpio_virtuser_config_subsys.su_mutex);
drivers/gpio/gpio-virtuser.c:1773: ret = configfs_register_subsystem(&gpio_virtuser_config_subsys);
drivers/gpio/gpio-virtuser.c-1774- if (ret) {
--
drivers/gpu/drm/vkms/vkms_configfs.c=824=int vkms_configfs_register(void)
--
drivers/gpu/drm/vkms/vkms_configfs.c-831- config_group_init(&vkms_subsys.su_group);
drivers/gpu/drm/vkms/vkms_configfs.c:832: ret = configfs_register_subsystem(&vkms_subsys);
drivers/gpu/drm/vkms/vkms_configfs.c-833-
--
drivers/gpu/drm/xe/xe_configfs.c=1334=int __init xe_configfs_init(void)
--
drivers/gpu/drm/xe/xe_configfs.c-1339- mutex_init(&xe_configfs.su_mutex);
drivers/gpu/drm/xe/xe_configfs.c:1340: ret = configfs_register_subsystem(&xe_configfs);
drivers/gpu/drm/xe/xe_configfs.c-1341- if (ret) {
--
drivers/hwtracing/coresight/coresight-syscfg-configfs.c=451=int cscfg_configfs_init(struct cscfg_manager *cscfg_mgr)
--
drivers/hwtracing/coresight/coresight-syscfg-configfs.c-476-
drivers/hwtracing/coresight/coresight-syscfg-configfs.c:477: return configfs_register_subsystem(subsys);
drivers/hwtracing/coresight/coresight-syscfg-configfs.c-478-}
--
drivers/hwtracing/stm/policy.c=560=int __init stp_configfs_init(void)
--
drivers/hwtracing/stm/policy.c-563- mutex_init(&stp_policy_subsys.su_mutex);
drivers/hwtracing/stm/policy.c:564: return configfs_register_subsystem(&stp_policy_subsys);
drivers/hwtracing/stm/policy.c-565-}
--
drivers/iio/industrialio-configfs.c=32=static int __init iio_configfs_init(void)
--
drivers/iio/industrialio-configfs.c-35-
drivers/iio/industrialio-configfs.c:36: return configfs_register_subsystem(&iio_configfs_subsys);
drivers/iio/industrialio-configfs.c-37-}
--
drivers/infiniband/core/cma_configfs.c=349=int __init cma_configfs_init(void)
--
drivers/infiniband/core/cma_configfs.c-354- mutex_init(&cma_subsys.su_mutex);
drivers/infiniband/core/cma_configfs.c:355: ret = configfs_register_subsystem(&cma_subsys);
drivers/infiniband/core/cma_configfs.c-356- if (ret)
--
drivers/most/configfs.c=649=int most_register_configfs_subsys(struct most_component *c)
--
drivers/most/configfs.c-654- most_cdev.mod = c->mod;
drivers/most/configfs.c:655: ret = configfs_register_subsystem(&most_cdev.subsys);
drivers/most/configfs.c-656- } else if (!strcmp(c->name, "net")) {
drivers/most/configfs.c-657- most_net.mod = c->mod;
drivers/most/configfs.c:658: ret = configfs_register_subsystem(&most_net.subsys);
drivers/most/configfs.c-659- } else if (!strcmp(c->name, "video")) {
drivers/most/configfs.c-660- most_video.mod = c->mod;
drivers/most/configfs.c:661: ret = configfs_register_subsystem(&most_video.subsys);
drivers/most/configfs.c-662- } else if (!strcmp(c->name, "sound")) {
drivers/most/configfs.c-663- most_sound_subsys.mod = c->mod;
drivers/most/configfs.c:664: ret = configfs_register_subsystem(&most_sound_subsys.subsys);
drivers/most/configfs.c-665- } else {
--
drivers/net/netconsole.c=205=static int __init dynamic_netconsole_init(void)
--
drivers/net/netconsole.c-208- mutex_init(&netconsole_subsys.su_mutex);
drivers/net/netconsole.c:209: return configfs_register_subsystem(&netconsole_subsys);
drivers/net/netconsole.c-210-}
--
drivers/nvme/target/configfs.c=2363=int __init nvmet_init_configfs(void)
--
drivers/nvme/target/configfs.c-2384-
drivers/nvme/target/configfs.c:2385: ret = configfs_register_subsystem(&nvmet_configfs_subsystem);
drivers/nvme/target/configfs.c-2386- if (ret) {
drivers/nvme/target/configfs.c:2387: pr_err("configfs_register_subsystem: %d\n", ret);
drivers/nvme/target/configfs.c-2388- return ret;
--
drivers/pci/endpoint/pci-ep-cfs.c=722=static int __init pci_ep_cfs_init(void)
--
drivers/pci/endpoint/pci-ep-cfs.c-728-
drivers/pci/endpoint/pci-ep-cfs.c:729: ret = configfs_register_subsystem(&pci_ep_cfs_subsys);
drivers/pci/endpoint/pci-ep-cfs.c-730- if (ret) {
--
drivers/target/target_core_configfs.c=3744=static int __init target_core_init_configfs(void)
--
drivers/target/target_core_configfs.c-3799- */
drivers/target/target_core_configfs.c:3800: ret = configfs_register_subsystem(subsys);
drivers/target/target_core_configfs.c-3801- if (ret < 0) {
--
drivers/thunderbolt/configfs.c=51=int tb_configfs_init(void)
--
drivers/thunderbolt/configfs.c-54- mutex_init(&tb_configfs.su_mutex);
drivers/thunderbolt/configfs.c:55: return configfs_register_subsystem(&tb_configfs);
drivers/thunderbolt/configfs.c-56-}
--
drivers/usb/gadget/configfs.c=2093=static int __init gadget_cfs_init(void)
--
drivers/usb/gadget/configfs.c-2098-
drivers/usb/gadget/configfs.c:2099: ret = configfs_register_subsystem(&gadget_subsys);
drivers/usb/gadget/configfs.c-2100- return ret;
--
drivers/virt/coco/guest/report.c=508=static int __init tsm_report_init(void)
--
drivers/virt/coco/guest/report.c-514- config_group_init(root);
drivers/virt/coco/guest/report.c:515: rc = configfs_register_subsystem(&tsm_configfs);
drivers/virt/coco/guest/report.c-516- if (rc)
--
fs/configfs/dir.c=992=static int configfs_dump(struct configfs_dirent *sd, int level)
--
fs/configfs/dir.c-1034- * subsystem isn't registered, or when configfs is loading or unloading.
fs/configfs/dir.c:1035: * Just like configfs_register_subsystem(). So we take the same
fs/configfs/dir.c-1036- * precautions. We pin the filesystem. We lock configfs_dirent_lock.
--
fs/configfs/dir.c=1870=EXPORT_SYMBOL(configfs_unregister_default_group);
fs/configfs/dir.c-1871-
fs/configfs/dir.c:1872:int configfs_register_subsystem(struct configfs_subsystem *subsys)
fs/configfs/dir.c-1873-{
--
fs/configfs/dir.c=1934=void configfs_unregister_subsystem(struct configfs_subsystem *subsys)
--
fs/configfs/dir.c-1978-
fs/configfs/dir.c:1979:EXPORT_SYMBOL(configfs_register_subsystem);
fs/configfs/dir.c-1980-EXPORT_SYMBOL(configfs_unregister_subsystem);
--
fs/dlm/config.c=639=int __init dlm_config_init(void)
--
fs/dlm/config.c-642- mutex_init(&clusters_root.subsys.su_mutex);
fs/dlm/config.c:643: return configfs_register_subsystem(&clusters_root.subsys);
fs/dlm/config.c-644-}
--
fs/ocfs2/cluster/nodemanager.c=826=static int __init init_o2nm(void)
--
fs/ocfs2/cluster/nodemanager.c-841- mutex_init(&o2nm_cluster_group.cs_subsys.su_mutex);
fs/ocfs2/cluster/nodemanager.c:842: ret = configfs_register_subsystem(&o2nm_cluster_group.cs_subsys);
fs/ocfs2/cluster/nodemanager.c-843- if (ret) {
--
include/linux/configfs.h=233=static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
--
include/linux/configfs.h-239-
include/linux/configfs.h:240:int configfs_register_subsystem(struct configfs_subsystem *subsys);
include/linux/configfs.h-241-void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
--
kernel/crash_dump_dm_crypt.c=451=static int __init configfs_dmcrypt_keys_init(void)
--
kernel/crash_dump_dm_crypt.c-461- mutex_init(&config_keys_subsys.su_mutex);
kernel/crash_dump_dm_crypt.c:462: ret = configfs_register_subsystem(&config_keys_subsys);
kernel/crash_dump_dm_crypt.c-463- if (ret) {
--
rust/kernel/configfs.rs=147= pub fn new(
--
rust/kernel/configfs.rs-179- // SAFETY: We initialized `this.subsystem` according to C API contract above.
rust/kernel/configfs.rs:180: unsafe { bindings::configfs_register_subsystem(this.subsystem.get()) },
rust/kernel/configfs.rs-181- )
--
samples/configfs/configfs_sample.c=330=static int __init configfs_example_init(void)
--
samples/configfs/configfs_sample.c-339- mutex_init(&subsys->su_mutex);
samples/configfs/configfs_sample.c:340: ret = configfs_register_subsystem(subsys);
samples/configfs/configfs_sample.c-341- if (ret) {
]
|
| 114/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 42739
output: 32
thoughts: 0
|
| 115/2 |
2026/09/02 01:37 |
tool |
grepper |
0m
Error:
Args: map[Expression:FS_USERNS_MOUNT PathPrefix:fs/configfs/]
Results:
|
| 116/2 |
2026/09/02 01:37 |
llm |
expert |
0m
Model:
Tokens:
input: 48859
output: 712
thoughts: 472
Thoughts: **My Assessment of the `null_blk` Driver Vulnerability**
Okay, so here's my understanding of this issue. Configfs, which is how we interact with this `null_blk` driver, isn't mountable within user namespaces. That immediately limits the attack surface; unprivileged users are simply not going to be able to touch this. To even load the module or write to configfs, you'd need root. So, privilege escalation is off the table.
The core of the problem is a "sleeping function called from invalid context" bug. That's always nasty. In this case, it looks like `null_blk`, a test driver, can be configured in a specific way that sets up a conflict between how it handles memory allocation and the block layer's execution context.
Specifically, if the `null_blk` driver is set up to use memory-backed storage (`memory_backed=1`) *and* shared tags (`shared_tags=1`), it uses a global tag set. This tag set's behavior is influenced by the `g_blocking` module parameter. The default for this `g_blocking` parameter is false, so no blocking flags get set.
The problem lies with how this driver then allocates memory when processing requests using `null_alloc_page`. This function, used with the `memory_backed=1` flag, uses `GFP_NOIO`, which *can* sleep. However, because the tag set lacks the `BLK_MQ_F_BLOCKING` flag, the block layer's dispatch loop (`blk_mq_run_dispatch_ops`) executes the request queueing under an RCU read lock. The function that is called eventually, is `null_alloc_page`. Sleeping while holding an RCU read lock is a big no-no. It triggers that "sleeping function" bug, which can either lead to a warning, or, depending on the kernel's configuration, a complete crash – a denial of service (DoS), like an RCU stall or panic.
Essentially, this is a misconfiguration vulnerability within a test driver. The impact is definitely a DoS, specifically a kernel warning or panic, which the root user triggers. It's not memory corruption, not a means for privilege escalation, not accessible to unprivileged processes, and not remotely exploitable via network, peripherals, filesystems, or VM interactions.
|
| 117/1 |
2026/09/02 01:38 |
action |
format-explanation |
0m
Results: map[Explanation:The bug report describes a "sleeping function called from invalid context" in
the `null_blk` block device driver.
### Root Cause Analysis
The `null_blk` driver is a test block driver that can be configured to simulate
various storage device behaviors. It can be configured to store data in memory
by setting the `memory_backed` option. When `memory_backed` is enabled, the
driver allocates memory pages during request processing using `kmalloc_obj(...,
GFP_NOIO)` and `alloc_pages(GFP_NOIO, ...)`, which can sleep.
To safely sleep during request processing, the block layer must be informed that
the driver's queue operations may block. This is done by setting the
`BLK_MQ_F_BLOCKING` flag on the device's tag set. If this flag is set, the block
layer's dispatch loop (`blk_mq_run_dispatch_ops`) uses `srcu_read_lock()`, which
allows sleeping. If the flag is not set, it uses `rcu_read_lock()`, which
disables preemption and creates an atomic context where sleeping is invalid.
The bug occurs due to a mismatch in configuration when using **shared tags**
(`shared_tags=1`). When shared tags are enabled, the driver uses a single global
tag set (`tag_set`) for all devices. This global tag set is initialized based on
the global module parameter `g_blocking` (which defaults to `false`).
If a user creates a `null_blk` device via `configfs` with `memory_backed=1` and
`shared_tags=1`, the device requires blocking operations (because it allocates
memory), but the global tag set it uses does not have the `BLK_MQ_F_BLOCKING`
flag set (because `g_blocking` was false).
As a result, the block layer dispatches requests to the driver under an RCU read
lock. When the driver attempts to allocate memory in `null_alloc_page()`, it
sleeps while holding the RCU lock, triggering the `BUG: sleeping function called
from invalid context`.
### Security Impact
* **Exploitable:** No. This is a context violation (sleeping in atomic context)
that triggers a kernel warning or panic. It does not cause memory corruption,
use-after-free, or out-of-bounds accesses that could be leveraged for privilege
escalation or information leaks.
* **Denial of Service:** Yes. Depending on the kernel configuration (e.g.,
`CONFIG_PANIC_ON_WARN`), this can crash the system or lead to RCU stalls.
* **Accessible From Unprivileged Processes / User Namespaces:** No. The
`null_blk` driver is configured either via module parameters at load time or via
`configfs` (typically mounted at `/sys/kernel/config`). Both actions require
root privileges (`CAP_SYS_MODULE` or root access to `configfs`). `configfs`
cannot be mounted inside unprivileged user namespaces.
* **Other Triggers:** This bug is not triggerable via network, remote,
peripheral, or malicious filesystem vectors. It is strictly a local
configuration issue in a test driver.
In conclusion, this is a local Denial of Service bug that can only be triggered
by a privileged user (root) misconfiguring a test driver. It poses no security
risk to production systems from unprivileged attackers.]
|