| 0/0 |
2026/05/30 13:19 |
flow |
assessment-security |
56m
Results: map[DenialOfService:true Explanation:**Root Cause Analysis**
The bug is caused by the JFS filesystem (and a few others like BFS, HPFS, OMFS)
failing to check the return value of `sb_set_blocksize()` during the mount
process (`jfs_fill_super`).
When a block device has a logical block size larger than the size JFS attempts
to set (e.g., the device has a 32768-byte logical block size, but JFS tries to
set it to `PSIZE` which is 4096 bytes), `sb_set_blocksize()` fails and returns
`0`. Because JFS ignores this return value, `sb->s_blocksize` remains `0`.
Subsequently, JFS attempts to read the superblock using `sb_bread()`. Since
`sb->s_blocksize` and `sb->s_blocksize_bits` are `0`, this results in a call to
the block layer (`__bread_gfp`) with a requested read `size` of `0`. The block
layer accepts `size = 0` (as `0` is technically aligned to any logical block
size) and proceeds to allocate buffers via `folio_alloc_buffers(folio, size=0,
...)`.
Inside `folio_alloc_buffers()`, the loop `while ((offset -= size) >= 0)`
subtracts `0` from `offset`, leaving `offset` equal to the folio size. It then
calls `folio_set_bh(bh, folio, offset)`, which immediately hits the
`BUG_ON(offset >= folio_size(folio))` assertion, crashing the kernel.
**Security Impact Assessment**
* **Exploitable:** No. The bug triggers a deterministic `BUG_ON` assertion
failure. It does not cause memory corruption, out-of-bounds accesses, or
use-after-free conditions. It cannot be leveraged for privilege escalation or
arbitrary code execution.
* **Denial Of Service:** Yes. The `BUG_ON` will cause a kernel panic (if
`panic_on_oops` is enabled) or kill the mounting process while leaving critical
VFS/block layer locks held, inevitably leading to a system deadlock or crash.
* **Accessible From Unprivileged Processes & User Namespaces:** No. Mounting the
JFS filesystem requires `CAP_SYS_ADMIN` in the initial user namespace. JFS does
not have the `FS_USERNS_MOUNT` flag, meaning it cannot be mounted by
unprivileged users even within a new user namespace. Furthermore, unprivileged
users cannot configure loop devices with custom logical block sizes (which
requires `BLK_OPEN_WRITE` or `CAP_SYS_ADMIN` on `/dev/loopX`).
* **Peripheral & Malicious Filesystem Trigger:** Yes. A malicious USB mass
storage device can be engineered to report an unusually large logical block size
(e.g., 32768 bytes) via SCSI `READ CAPACITY` commands. If a modern Linux desktop
environment (e.g., GNOME, KDE via `udisks2`) detects the JFS magic number and
attempts to auto-mount the plugged-in device, the bug will be triggered
automatically without any user interaction, resulting in an immediate Denial of
Service. Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/30 13:19 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/05/30 13:19 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/e07873b30d0fc1ca4646478ca6992107750ce855]
|
| 3/1 |
2026/05/30 13:21 |
action |
kernel-builder |
28m
Results: map[KernelObj:/app/workdir/cache/build/947c9b3194c5bcf0acc0111fe2940d2bf868e637]
|
| 4/1 |
2026/05/30 13:49 |
action |
codesearch-prepare |
21m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/30 14:10 |
agent |
expert |
4m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true 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 or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a 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.
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:
loop0: detected capacity change from 0 to 2048
loop0: p2 p3 < > p4 < p5 >
loop0: partition table partially beyond EOD, truncated
loop0: p3 start 4284289 is beyond EOD, truncated
Zero length message leads to an empty skb
jfs: block size(32768) > page size(4096) not supported by filesystem
------------[ cut here ]------------
kernel BUG at fs/buffer.c:1479!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
CPU: 0 UID: 0 PID: 5337 Comm: syz.0.0 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:folio_set_bh+0x1dc/0x1e0 fs/buffer.c:1479
Code: 4c 89 e2 e8 76 51 98 02 e9 42 ff ff ff e8 bc 76 6d ff 48 89 df 48 c7 c6 80 26 df 8b e8 3d bd cf fe 90 0f 0b e8 a5 76 6d ff 90 <0f> 0b 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f
RSP: 0018:ffffc90004bc78f0 EFLAGS: 00010283
RAX: ffffffff8258509b RBX: ffffea0001534e00 RCX: 0000000000100000
RDX: ffffc90020001000 RSI: 0000000000001678 RDI: 0000000000001679
RBP: dffffc0000000000 R08: ffffea0001534e07 R09: 1ffffd40002a69c0
R10: dffffc0000000000 R11: fffff940002a69c1 R12: 0000000000000003
R13: 0000000000008000 R14: ffff88804679cae0 R15: 0000000000008000
FS: 00007f215501c6c0(0000) GS:ffff88808c893000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f2154186480 CR3: 00000000133be000 CR4: 0000000000352ef0
Call Trace:
<TASK>
folio_alloc_buffers+0x228/0x640 fs/buffer.c:849
grow_dev_folio fs/buffer.c:979 [inline]
grow_buffers fs/buffer.c:1020 [inline]
__getblk_slow fs/buffer.c:1038 [inline]
bdev_getblk+0x2cb/0x6e0 fs/buffer.c:1358
__bread_gfp+0x89/0x3b0 fs/buffer.c:1412
sb_bread include/linux/buffer_head.h:346 [inline]
readSuper+0xdb/0x270 fs/jfs/jfs_mount.c:462
chkSuper+0x5d/0xe00 fs/jfs/jfs_mount.c:299
jfs_mount+0x4b/0x870 fs/jfs/jfs_mount.c:83
jfs_fill_super+0x6bc/0xd80 fs/jfs/super.c:523
get_tree_bdev_flags+0x431/0x4f0 fs/super.c:1694
vfs_get_tree+0x92/0x2a0 fs/super.c:1754
fc_mount fs/namespace.c:1193 [inline]
do_new_mount_fc fs/namespace.c:3758 [inline]
do_new_mount+0x341/0xd30 fs/namespace.c:3834
do_mount fs/namespace.c:4167 [inline]
__do_sys_mount fs/namespace.c:4383 [inline]
__se_sys_mount+0x31d/0x420 fs/namespace.c:4360
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f215419ce59
Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007f215501bfe8 EFLAGS: 00000246 ORIG_RAX: 00000000000000a5
RAX: ffffffffffffffda RBX: 00007f2154415fa0 RCX: 00007f215419ce59
RDX: 0000200000000040 RSI: 0000200000000140 RDI: 0000200000000080
RBP: 00007f2154232d6f R08: 0000000000000000 R09: 0000000000000000
R10: 000000000000c000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f2154416038 R14: 00007f2154415fa0 R15: 00007ffc21110228
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:folio_set_bh+0x1dc/0x1e0 fs/buffer.c:1479
Code: 4c 89 e2 e8 76 51 98 02 e9 42 ff ff ff e8 bc 76 6d ff 48 89 df 48 c7 c6 80 26 df 8b e8 3d bd cf fe 90 0f 0b e8 a5 76 6d ff 90 <0f> 0b 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f
RSP: 0018:ffffc90004bc78f0 EFLAGS: 00010283
RAX: ffffffff8258509b RBX: ffffea0001534e00 RCX: 0000000000100000
RDX: ffffc90020001000 RSI: 0000000000001678 RDI: 0000000000001679
RBP: dffffc0000000000 R08: ffffea0001534e07 R09: 1ffffd40002a69c0
R10: dffffc0000000000 R11: fffff940002a69c1 R12: 0000000000000003
R13: 0000000000008000 R14: ffff88804679cae0 R15: 0000000000008000
FS: 00007f215501c6c0(0000) GS:ffff88808c893000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fa8e6997a08 CR3: 00000000133be000 CR4: 0000000000352ef0
Reply: **Root Cause Analysis**
The bug is caused by the JFS filesystem (and a few others like BFS, HPFS, OMFS) failing to check the return value of `sb_set_blocksize()` during the mount process (`jfs_fill_super`).
When a block device has a logical block size larger than the size JFS attempts to set (e.g., the device has a 32768-byte logical block size, but JFS tries to set it to `PSIZE` which is 4096 bytes), `sb_set_blocksize()` fails and returns `0`. Because JFS ignores this return value, `sb->s_blocksize` remains `0`.
Subsequently, JFS attempts to read the superblock using `sb_bread()`. Since `sb->s_blocksize` and `sb->s_blocksize_bits` are `0`, this results in a call to the block layer (`__bread_gfp`) with a requested read `size` of `0`. The block layer accepts `size = 0` (as `0` is technically aligned to any logical block size) and proceeds to allocate buffers via `folio_alloc_buffers(folio, size=0, ...)`.
Inside `folio_alloc_buffers()`, the loop `while ((offset -= size) >= 0)` subtracts `0` from `offset`, leaving `offset` equal to the folio size. It then calls `folio_set_bh(bh, folio, offset)`, which immediately hits the `BUG_ON(offset >= folio_size(folio))` assertion, crashing the kernel.
**Security Impact Assessment**
* **Exploitable:** No. The bug triggers a deterministic `BUG_ON` assertion failure. It does not cause memory corruption, out-of-bounds accesses, or use-after-free conditions. It cannot be leveraged for privilege escalation or arbitrary code execution.
* **Denial Of Service:** Yes. The `BUG_ON` will cause a kernel panic (if `panic_on_oops` is enabled) or kill the mounting process while leaving critical VFS/block layer locks held, inevitably leading to a system deadlock or crash.
* **Accessible From Unprivileged Processes & User Namespaces:** No. Mounting the JFS filesystem requires `CAP_SYS_ADMIN` in the initial user namespace. JFS does not have the `FS_USERNS_MOUNT` flag, meaning it cannot be mounted by unprivileged users even within a new user namespace. Furthermore, unprivileged users cannot configure loop devices with custom logical block sizes (which requires `BLK_OPEN_WRITE` or `CAP_SYS_ADMIN` on `/dev/loopX`).
* **Peripheral & Malicious Filesystem Trigger:** Yes. A malicious USB mass storage device can be engineered to report an unusually large logical block size (e.g., 32768 bytes) via SCSI `READ CAPACITY` commands. If a modern Linux desktop environment (e.g., GNOME, KDE via `udisks2`) detects the JFS magic number and attempts to auto-mount the plugged-in device, the bug will be triggered automatically without any user interaction, resulting in an immediate Denial of Service.
|
| 6/2 |
2026/05/30 14:10 |
llm |
expert |
0m
Model:
Tokens:
input: 8171
output: 34
thoughts: 515
Thoughts: **Analyzing a Kernel BUG in fs/buffer.c**
Alright, let's dive in. I'm seeing a kernel BUG, specifically at `fs/buffer.c:1479` within the `folio_set_bh` function. Looking at the call trace, the issue appears to originate from `folio_alloc_buffers` at `fs/buffer.c:849`. That leads me through a cascade of related functions: `grow_dev_folio`, `grow_buffers`, then the slow path `__getblk_slow`, eventually reaching `bdev_getblk`. From there, `__bread_gfp` calls `sb_bread`, the issue is then called in `readSuper`, and the related functions, up to the mounting process. My gut tells me this relates to the JFS filesystem since the mount code is related.
My immediate focus will be on that specific line, `fs/buffer.c:1479` and understand what `folio_set_bh` is trying to do in that context. Given the context, it likely has to do with buffer management during I/O operations, particularly concerning block device access and the allocation of buffers within a folio. This stack trace tells me that this is happening during the JFS filesystem's mount process. I have to see how the allocation/setting of the buffer head is going wrong. Is it a null pointer dereference, an out-of-bounds access, or perhaps a race condition during buffer allocation or initialization? The fact that it's triggered during mount is crucial; it narrows the scope and suggests a potential problem with how the JFS superblock or metadata is being read or interpreted during the initial setup.
I'll need to carefully examine the surrounding code in `folio_set_bh`, trace back through the functions that call it, and analyze the data structures involved, especially the folio and buffer head structures. I will have to look at how JFS interacts with the buffer cache. I have to look at the JFS specific functions. I am pretty sure I can get to the root cause of this relatively quickly.
|
| 7/2 |
2026/05/30 14:10 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:1460 LineCount:40]
Results: map[Contents:1460:
1461: /*
1462: * It's called from workqueue context so we need a bh_lru_lock to close
1463: * the race with preemption/irq.
1464: */
1465: void invalidate_bh_lrus_cpu(void)
1466: {
1467: struct bh_lru *b;
1468:
1469: bh_lru_lock();
1470: b = this_cpu_ptr(&bh_lrus);
1471: __invalidate_bh_lrus(b);
1472: bh_lru_unlock();
1473: }
1474:
1475: void folio_set_bh(struct buffer_head *bh, struct folio *folio,
1476: unsigned long offset)
1477: {
1478: bh->b_folio = folio;
1479: BUG_ON(offset >= folio_size(folio));
1480: if (folio_test_highmem(folio))
1481: /*
1482: * This catches illegal uses and preserves the offset:
1483: */
1484: bh->b_data = (char *)(0 + offset);
1485: else
1486: bh->b_data = folio_address(folio) + offset;
1487: }
1488: EXPORT_SYMBOL(folio_set_bh);
1489:
1490: /*
1491: * Called when truncating a buffer on a page completely.
1492: */
1493:
1494: /* Bits that are cleared during an invalidate */
1495: #define BUFFER_FLAGS_DISCARD \
1496: (1 << BH_Mapped | 1 << BH_New | 1 << BH_Req | \
1497: 1 << BH_Delay | 1 << BH_Unwritten)
1498:
1499: static void discard_buffer(struct buffer_head * bh)
]
|
| 8/2 |
2026/05/30 14:10 |
llm |
expert |
0m
Model:
Tokens:
input: 9738
output: 33
thoughts: 50
Thoughts: Okay, let's break this down.
**Investigating a `BUG_ON` in `folio_set_bh`**
Right, so I've hit a `BUG_ON` statement, specifically the one that checks `offset >= folio_size(folio)` within the `folio_set_bh` function. Clearly, something is going wrong with how offsets and folio sizes are interacting. The problem almost certainly lies in the logic that's leading to an out-of-bounds access. My first instinct, given the context of buffers and folios, is to check how buffers are allocated within the folio. Specifically, I need to understand how the offset is set in relation to the folio's size. Let me go straight to `folio_alloc_buffers` in `fs/buffer.c:849` to see how the buffers and offset are set in the first place.
|
| 9/2 |
2026/05/30 14:10 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:820 LineCount:50]
Results: map[Contents: 820: * buffers.
821: *
822: * The retry flag is used to differentiate async IO (paging, swapping)
823: * which may not fail from ordinary buffer allocations.
824: */
825: struct buffer_head *folio_alloc_buffers(struct folio *folio, unsigned long size,
826: gfp_t gfp)
827: {
828: struct buffer_head *bh, *head;
829: long offset;
830: struct mem_cgroup *memcg, *old_memcg;
831:
832: memcg = get_mem_cgroup_from_folio(folio);
833: old_memcg = set_active_memcg(memcg);
834:
835: head = NULL;
836: offset = folio_size(folio);
837: while ((offset -= size) >= 0) {
838: bh = alloc_buffer_head(gfp);
839: if (!bh)
840: goto no_grow;
841:
842: bh->b_this_page = head;
843: bh->b_blocknr = -1;
844: head = bh;
845:
846: bh->b_size = size;
847:
848: /* Link the buffer to its folio */
849: folio_set_bh(bh, folio, offset);
850: }
851: out:
852: set_active_memcg(old_memcg);
853: mem_cgroup_put(memcg);
854: return head;
855: /*
856: * In case anything failed, we just free everything we got.
857: */
858: no_grow:
859: if (head) {
860: do {
861: bh = head;
862: head = head->b_this_page;
863: free_buffer_head(bh);
864: } while (head);
865: }
866:
867: goto out;
868: }
869: EXPORT_SYMBOL_GPL(folio_alloc_buffers);
]
|
| 10/2 |
2026/05/30 14:10 |
llm |
expert |
0m
Model:
Tokens:
input: 10684
output: 33
thoughts: 306
Thoughts: **Analyzing a Potential Integer Overflow Vulnerability**
Okay, here's what's going through my head as I dissect this code. First, I see this check: `offset >= folio_size(folio)`. Hang on a second, isn't `offset` initialized to `folio_size(folio)` within `folio_alloc_buffers`? Then, we have this decrementing loop: `while ((offset -= size) >= 0)`. My immediate thought is, what if `size` is a problematic value, maybe negative, huge, or *zero*? Since `size` is an `unsigned long`, it can't be negative, so that's out.
If `size` is zero, `offset` will remain `folio_size(folio)` and the `offset >= folio_size(folio)` check would be *true* and the loop wouldn't execute, which might be a bug. But let's verify if `size` can actually be zero. The log message about block sizes got me thinking. It says, "jfs: block size(32768) > page size(4096) not supported by filesystem". Alright, so if the block size is 32768, then `size` should equal 32768, and the initial value of `offset` is 4096. Thus when we calculate `offset -= size`, `offset = -28672`.
Then, I remember `offset` is a `long`, so it *could* be negative. But `-28672 >= 0` is false, so the loop wouldn't execute. So I'm thinking the zero case *is* important! Then I see a log message, "Zero length message leads to an empty skb." This is probably unrelated, right? Let's check `grow_dev_folio` and `grow_buffers` to see how size might get initialized.
|
| 11/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:960 LineCount:50]
Results: map[Contents: 960: if (bh) {
961: if (bh->b_size == size) {
962: end_block = folio_init_buffers(folio, bdev, size);
963: goto unlock;
964: }
965:
966: /*
967: * Retrying may succeed; for example the folio may finish
968: * writeback, or buffers may be cleaned. This should not
969: * happen very often; maybe we have old buffers attached to
970: * this blockdev's page cache and we're trying to change
971: * the block size?
972: */
973: if (!try_to_free_buffers(folio)) {
974: end_block = ~0ULL;
975: goto unlock;
976: }
977: }
978:
979: bh = folio_alloc_buffers(folio, size, gfp | __GFP_ACCOUNT);
980: if (!bh)
981: goto unlock;
982:
983: /*
984: * Link the folio to the buffers and initialise them. Take the
985: * lock to be atomic wrt __find_get_block(), which does not
986: * run under the folio lock.
987: */
988: spin_lock(&mapping->i_private_lock);
989: link_dev_buffers(folio, bh);
990: end_block = folio_init_buffers(folio, bdev, size);
991: spin_unlock(&mapping->i_private_lock);
992: unlock:
993: folio_unlock(folio);
994: folio_put(folio);
995: return block < end_block;
996: }
997:
998: /*
999: * Create buffers for the specified block device block's folio. If
1000: * that folio was dirty, the buffers are set dirty also. Returns false
1001: * if we've hit a permanent error.
1002: */
1003: static bool grow_buffers(struct block_device *bdev, sector_t block,
1004: unsigned size, gfp_t gfp)
1005: {
1006: loff_t pos;
1007:
1008: /*
1009: * Check for a block which lies outside our maximum possible
]
|
| 12/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 12158
output: 34
thoughts: 10
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, and delivered as a first-person summary:
**Analyzing the `grow_buffers` Function**
Alright, let's dive into this `grow_buffers` function. My initial thought process here is to immediately understand its role and what specific contexts it might be used in. Given the name, it's clear we're dealing with dynamic memory allocation, likely within a data structure or system that relies on buffers. My mind races to consider potential implementations: Is this for expanding a circular buffer? A growable array? Or, is it involved in managing memory pools? I'm already anticipating the typical problems we encounter with buffer growth - the need for efficient allocation strategies (avoiding fragmentation), the considerations of copying overhead versus in-place reallocations, and how this function handles potential failure scenarios (memory exhaustion). I'll also be mentally noting the calling context - is this a critical section, multi-threaded environment, etc., as that drastically impacts how I'll evaluate the code for thread-safety and potential race conditions. Ultimately, the question in my mind is, how effectively does this function balance performance with resource management? Let's take a closer look...
|
| 13/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:1000 LineCount:50]
Results: map[Contents:1000: * that folio was dirty, the buffers are set dirty also. Returns false
1001: * if we've hit a permanent error.
1002: */
1003: static bool grow_buffers(struct block_device *bdev, sector_t block,
1004: unsigned size, gfp_t gfp)
1005: {
1006: loff_t pos;
1007:
1008: /*
1009: * Check for a block which lies outside our maximum possible
1010: * pagecache index.
1011: */
1012: if (check_mul_overflow(block, (sector_t)size, &pos) || pos > MAX_LFS_FILESIZE) {
1013: printk(KERN_ERR "%s: requested out-of-range block %llu for device %pg\n",
1014: __func__, (unsigned long long)block,
1015: bdev);
1016: return false;
1017: }
1018:
1019: /* Create a folio with the proper size buffers */
1020: return grow_dev_folio(bdev, block, pos / PAGE_SIZE, size, gfp);
1021: }
1022:
1023: static struct buffer_head *
1024: __getblk_slow(struct block_device *bdev, sector_t block,
1025: unsigned size, gfp_t gfp)
1026: {
1027: bool blocking = gfpflags_allow_blocking(gfp);
1028:
1029: if (WARN_ON_ONCE(!IS_ALIGNED(size, bdev_logical_block_size(bdev)))) {
1030: printk(KERN_ERR "getblk(): block size %d not aligned to logical block size %d\n",
1031: size, bdev_logical_block_size(bdev));
1032: return NULL;
1033: }
1034:
1035: for (;;) {
1036: struct buffer_head *bh;
1037:
1038: if (!grow_buffers(bdev, block, size, gfp))
1039: return NULL;
1040:
1041: if (blocking)
1042: bh = __find_get_block_nonatomic(bdev, block, size);
1043: else
1044: bh = __find_get_block(bdev, block, size);
1045: if (bh)
1046: return bh;
1047: }
1048: }
1049:
]
|
| 14/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 13211
output: 39
thoughts: 46
Thoughts: Okay, let's see...
**Analyzing the JFS Mount Process**
Right, so I'm digging into this JFS mount process. The first thing that jumps out is the use of `size` as an unsigned integer. That's a good heads-up, I'll need to keep that in mind when looking at comparisons or potential overflow issues later. The next thing I spot is the call to `chkSuper` within `jfs_mount`. That's where the superblock integrity check happens, which is always crucial. Now, let's dive into `fs/jfs/jfs_mount.c` and see what's actually happening inside that `chkSuper` function. I want to see how it's validating the superblock data; understanding the logic in `chkSuper` is key to ensuring a successful mount.
|
| 15/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/jfs/jfs_mount.c FirstLine:280 LineCount:50]
Results: map[Contents: 280: * validate the superblock of the file system to be mounted and
281: * get the file system parameters.
282: *
283: * returns
284: * 0 with fragsize set if check successful
285: * error code if not successful
286: */
287: static int chkSuper(struct super_block *sb)
288: {
289: int rc = 0;
290: struct jfs_sb_info *sbi = JFS_SBI(sb);
291: struct jfs_superblock *j_sb;
292: struct buffer_head *bh;
293: int AIM_bytesize, AIT_bytesize;
294: int expected_AIM_bytesize, expected_AIT_bytesize;
295: s64 AIM_byte_addr, AIT_byte_addr, fsckwsp_addr;
296: s64 byte_addr_diff0, byte_addr_diff1;
297: s32 bsize;
298:
299: if ((rc = readSuper(sb, &bh)))
300: return rc;
301: j_sb = (struct jfs_superblock *)bh->b_data;
302:
303: /*
304: * validate superblock
305: */
306: /* validate fs signature */
307: if (strncmp(j_sb->s_magic, JFS_MAGIC, 4) ||
308: le32_to_cpu(j_sb->s_version) > JFS_VERSION) {
309: rc = -EINVAL;
310: goto out;
311: }
312:
313: bsize = le32_to_cpu(j_sb->s_bsize);
314: if (bsize != PSIZE) {
315: jfs_err("Only 4K block size supported!");
316: rc = -EINVAL;
317: goto out;
318: }
319:
320: jfs_info("superblock: flag:0x%08x state:0x%08x size:0x%Lx",
321: le32_to_cpu(j_sb->s_flag), le32_to_cpu(j_sb->s_state),
322: (unsigned long long) le64_to_cpu(j_sb->s_size));
323:
324: /* validate the descriptors for Secondary AIM and AIT */
325: if ((j_sb->s_flag & cpu_to_le32(JFS_BAD_SAIT)) !=
326: cpu_to_le32(JFS_BAD_SAIT)) {
327: expected_AIM_bytesize = 2 * PSIZE;
328: AIM_bytesize = lengthPXD(&j_sb->s_aim2) * bsize;
329: expected_AIT_bytesize = 4 * PSIZE;
]
|
| 16/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 14343
output: 39
thoughts: 27
Thoughts: Here's my analysis of the situation:
**Initial Concerns Regarding Function Call Order**
Okay, hold on a second. Something feels off here. I'm seeing that `readSuper` is being called *before* the check for `bsize != PSIZE`. That sequence raises a flag in my mind. Let's dig deeper and take a closer look at the `readSuper` function itself. Understanding what `readSuper` is doing, and the state it expects, is crucial to understanding the potential implications of this order. It's possible that this sequence is entirely deliberate, but my initial gut reaction is to question whether this is intended.
|
| 17/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/jfs/jfs_mount.c FirstLine:450 LineCount:50]
Results: map[Contents: 450: return 0;
451: }
452:
453:
454: /*
455: * readSuper()
456: *
457: * read superblock by raw sector address
458: */
459: int readSuper(struct super_block *sb, struct buffer_head **bpp)
460: {
461: /* read in primary superblock */
462: *bpp = sb_bread(sb, SUPER1_OFF >> sb->s_blocksize_bits);
463: if (*bpp)
464: return 0;
465:
466: /* read in secondary/replicated superblock */
467: *bpp = sb_bread(sb, SUPER2_OFF >> sb->s_blocksize_bits);
468: if (*bpp)
469: return 0;
470:
471: return -EIO;
472: }
473:
474:
475: /*
476: * logMOUNT()
477: *
478: * function: write a MOUNT log record for file system.
479: *
480: * MOUNT record keeps logredo() from processing log records
481: * for this file system past this point in log.
482: * it is harmless if mount fails.
483: *
484: * note: MOUNT record is at aggregate level, not at fileset level,
485: * since log records of previous mounts of a fileset
486: * (e.g., AFTER record of extent allocation) have to be processed
487: * to update block allocation map at aggregate level.
488: */
489: static int logMOUNT(struct super_block *sb)
490: {
491: struct jfs_log *log = JFS_SBI(sb)->log;
492: struct lrd lrd;
493:
494: lrd.logtid = 0;
495: lrd.backchain = 0;
496: lrd.type = cpu_to_le16(LOG_MOUNT);
497: lrd.length = 0;
498: lrd.aggregate = cpu_to_le32(new_encode_dev(sb->s_bdev->bd_dev));
499: lmLog(log, NULL, &lrd, NULL);
]
|
| 18/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 15267
output: 36
thoughts: 61
Thoughts: Okay, let me think this through.
**Analyzing the Blocksize Calculation**
Hmm, `sb_bread(sb, SUPER1_OFF >> sb->s_blocksize_bits)`... That looks like we're trying to read a block using some shifting operation related to block size. Right, `sb->s_blocksize_bits` is definitely the key here. But where is that value actually *set*? I need to trace back where the `sb->s_blocksize` value that feeds into this `sb->s_blocksize_bits` is initialized. My immediate suspicion is that it's probably handled within the `jfs_fill_super` function. That seems like the logical place to load up superblock details. I'll need to check the code there to confirm and understand how the block size is determined, because that shift could easily lead to an off-by-one error or an incorrect block read if it's not set up correctly. Gotta double-check that this is correct, especially since a miscalculation in something like that can lead to all sorts of file system corruption!
|
| 19/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/jfs/super.c FirstLine:500 LineCount:50]
Results: map[Contents: 500: sb->s_export_op = &jfs_export_operations;
501: sb->s_xattr = jfs_xattr_handlers;
502: #ifdef CONFIG_QUOTA
503: sb->dq_op = &dquot_operations;
504: sb->s_qcop = &jfs_quotactl_ops;
505: sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
506: #endif
507:
508: /*
509: * Initialize direct-mapping inode/address-space
510: */
511: inode = new_inode(sb);
512: if (inode == NULL) {
513: ret = -ENOMEM;
514: goto out_unload;
515: }
516: inode->i_size = bdev_nr_bytes(sb->s_bdev);
517: inode->i_mapping->a_ops = &jfs_metapage_aops;
518: inode_fake_hash(inode);
519: mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS);
520:
521: sbi->direct_inode = inode;
522:
523: rc = jfs_mount(sb);
524: if (rc) {
525: if (!silent)
526: jfs_err("jfs_mount failed w/return code = %d", rc);
527: goto out_mount_failed;
528: }
529: if (sb_rdonly(sb))
530: sbi->log = NULL;
531: else {
532: rc = jfs_mount_rw(sb, 0);
533: if (rc) {
534: if (!silent) {
535: jfs_err("jfs_mount_rw failed, return code = %d",
536: rc);
537: }
538: goto out_no_rw;
539: }
540: }
541:
542: sb->s_magic = JFS_SUPER_MAGIC;
543:
544: if (sbi->mntflag & JFS_OS2)
545: set_default_d_op(sb, &jfs_ci_dentry_operations);
546:
547: inode = jfs_iget(sb, ROOT_I);
548: if (IS_ERR(inode)) {
549: ret = PTR_ERR(inode);
]
|
| 20/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 16365
output: 36
thoughts: 24
Thoughts: Here's a summary of my thought process, as requested:
**Navigating the JFS Filesystem Initialization**
Okay, so I need to track down how the block size (`sb->s_blocksize`) is getting set within the JFS filesystem's initialization routine. That's a crucial piece of the puzzle, and I need to understand it completely. My instinct is that I'll find it within the `jfs_fill_super` function. That's the logical place to start digging, since that function's responsible for filling the superblock data. I'll need to carefully inspect the code within `jfs_fill_super` to understand its execution path and where that variable is ultimately assigned a value.
|
| 21/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/jfs/super.c FirstLine:450 LineCount:50]
Results: map[Contents: 450: jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags);
451:
452: sbi = kzalloc_obj(struct jfs_sb_info);
453: if (!sbi)
454: return -ENOMEM;
455:
456: sb->s_fs_info = sbi;
457: sb->s_max_links = JFS_LINK_MAX;
458: sb->s_time_min = 0;
459: sb->s_time_max = U32_MAX;
460: sbi->sb = sb;
461:
462: /* Transfer results of parsing to the sbi */
463: sbi->flag = ctx->flag;
464: sbi->uid = ctx->uid;
465: sbi->gid = ctx->gid;
466: sbi->umask = ctx->umask;
467: if (ctx->nls_map != (void *) -1) {
468: unload_nls(sbi->nls_tab);
469: sbi->nls_tab = ctx->nls_map;
470: }
471: ctx->nls_map = NULL;
472:
473: if (sbi->flag & JFS_DISCARD) {
474: if (!bdev_max_discard_sectors(sb->s_bdev)) {
475: pr_err("JFS: discard option not supported on device\n");
476: sbi->flag &= ~JFS_DISCARD;
477: } else {
478: sbi->minblks_trim = ctx->minblks_trim;
479: }
480: }
481:
482: #ifdef CONFIG_JFS_POSIX_ACL
483: sb->s_flags |= SB_POSIXACL;
484: #endif
485:
486: if (ctx->resize) {
487: pr_err("resize option for remount only\n");
488: goto out_unload;
489: }
490:
491: /*
492: * Initialize blocksize to 4K.
493: */
494: sb_set_blocksize(sb, PSIZE);
495:
496: /*
497: * Set method vectors.
498: */
499: sb->s_op = &jfs_super_operations;
]
|
| 22/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 17332
output: 25
thoughts: 108
Thoughts: **Investigating a Block Size Discrepancy**
Okay, so I'm looking at this line of code: `sb_set_blocksize(sb, PSIZE);` Pretty straightforward, it's setting the block size of a superblock to the page size. And, oh yeah, `PSIZE` is 4096. No surprises there. But then something clicks. If the block size is being set to 4096, shouldn't `sb_bread` be operating on 4096-byte blocks?
This raises a red flag because I'm seeing an error in the logs that says: `jfs: block size(32768) > page size(4096) not supported by filesystem`. That block size of 32768 is huge, and the error clearly indicates that it's *not* supported, being larger than the page size.
So, I need to understand where that log message is originating, and how it relates to this block size setting. This suggests an inconsistency somewhere in the system. Why is the log saying the block size is 32768 when I'm clearly setting it to 4096? Time to dig deeper and trace this back.
|
| 23/2 |
2026/05/30 14:11 |
tool |
grepper |
0m
Error:
Args: map[Expression:block size.*> page size.*not supported by filesystem]
Results:
|
| 24/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 17747
output: 18
thoughts: 11
Thoughts: Here's my thought process, summarized as you requested:
**Navigating a Technical Roadblock**
Okay, so I'm encountering something, a potential error message or limitation, related to the filesystem. The wording is "not supported by filesystem". I immediately recognize this phrase as a key indicator of a specific kind of problem that often arises in my area of expertise. It's a clue, a starting point. Let's see if this phrase helps me narrow down the cause. Now, let's initiate a search using the exact phrase "not supported by filesystem". The phrasing is important for obtaining accurate results. This way I will be able to start with the most relevant information and efficiently identify the issue. Hopefully, this search will quickly illuminate the source of the problem.
|
| 25/2 |
2026/05/30 14:11 |
tool |
grepper |
0m
Args: map[Expression:not supported by filesystem]
Results: map[Output:block/bdev.c=219=static int sb_validate_large_blocksize(struct super_block *sb, int size)
--
block/bdev.c-223- if (!(sb->s_type->fs_flags & FS_LBS))
block/bdev.c:224: err_str = "not supported by filesystem";
block/bdev.c-225- else if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
--
tools/testing/selftests/mincore/mincore_selftest.c=187=TEST(check_file_mmap)
--
tools/testing/selftests/mincore/mincore_selftest.c-214- }
tools/testing/selftests/mincore/mincore_selftest.c:215: SKIP(goto out_free, "O_TMPFILE not supported by filesystem.");
tools/testing/selftests/mincore/mincore_selftest.c-216- }
--
tools/testing/selftests/mincore/mincore_selftest.c-223- }
tools/testing/selftests/mincore/mincore_selftest.c:224: SKIP(goto out_close, "fallocate not supported by filesystem.");
tools/testing/selftests/mincore/mincore_selftest.c-225- }
--
tools/testing/selftests/mm/gup_longterm.c=91=static void do_test(int fd, size_t size, enum test_type type, bool shared)
--
tools/testing/selftests/mm/gup_longterm.c-122- if (errno == EOPNOTSUPP) {
tools/testing/selftests/mm/gup_longterm.c:123: ksft_print_msg("fallocate() not supported by filesystem\n");
tools/testing/selftests/mm/gup_longterm.c-124- result = KSFT_SKIP;
]
|
| 26/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 18448
output: 34
thoughts: 37
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the weeds of block device driver development.
**Navigating the Block Layer**
Right, so I'm looking at something β likely a kernel panic or a performance anomaly β and my attention's been drawn to `block/bdev.c:224`. That tells me I'm in the core block device code. My mental map is already starting to piece together the likely surrounding code; I know the territory. The next thing that leaps out is `sb_validate_large_blocksize` within `block/bdev.c`. I immediately associate that function with checking and potentially correcting a block size issue, usually related to file systems. So, the investigation has clearly zeroed in on the interface between block devices and filesystems, most likely an abnormal large block size being reported. I need to understand what's triggering this validation and then whatβs happening during the validation and why it's failing. Gotta dig in and figure out the specific block size being validated and where it's coming from. This is likely an interesting edge case I havenβt seen before or a regression.
|
| 27/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:block/bdev.c FirstLine:210 LineCount:50]
Results: map[Contents: 210: mapping_set_folio_min_order(inode->i_mapping, get_order(size));
211: filemap_invalidate_unlock(inode->i_mapping);
212: inode_unlock(inode);
213: }
214: return 0;
215: }
216:
217: EXPORT_SYMBOL(set_blocksize);
218:
219: static int sb_validate_large_blocksize(struct super_block *sb, int size)
220: {
221: const char *err_str = NULL;
222:
223: if (!(sb->s_type->fs_flags & FS_LBS))
224: err_str = "not supported by filesystem";
225: else if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
226: err_str = "is only supported with CONFIG_TRANSPARENT_HUGEPAGE";
227:
228: if (!err_str)
229: return 0;
230:
231: pr_warn_ratelimited("%s: block size(%d) > page size(%lu) %s\n",
232: sb->s_type->name, size, PAGE_SIZE, err_str);
233: return -EINVAL;
234: }
235:
236: int sb_set_blocksize(struct super_block *sb, int size)
237: {
238: if (size > PAGE_SIZE && sb_validate_large_blocksize(sb, size))
239: return 0;
240: if (set_blocksize(sb->s_bdev_file, size))
241: return 0;
242: /* If we get here, we know size is validated */
243: sb->s_blocksize = size;
244: sb->s_blocksize_bits = blksize_bits(size);
245: return sb->s_blocksize;
246: }
247:
248: EXPORT_SYMBOL(sb_set_blocksize);
249:
250: int __must_check sb_min_blocksize(struct super_block *sb, int size)
251: {
252: int minsize = bdev_logical_block_size(sb->s_bdev);
253: if (size < minsize)
254: size = minsize;
255: return sb_set_blocksize(sb, size);
256: }
257:
258: EXPORT_SYMBOL(sb_min_blocksize);
259:
]
|
| 28/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 19543
output: 19
thoughts: 325
Thoughts: **Analyzing `sb_set_blocksize` and Potential Initialization Issues**
Okay, so I'm looking at this `sb_set_blocksize` function, and something's bugging me. Specifically, I'm concerned that `sb_set_blocksize` returns 0 if `sb_validate_large_blocksize` returns an error, and I suspect that this could be masking some initialization problems.
Let's break this down. From the code, it's pretty clear: if the requested `size` is larger than `PAGE_SIZE`, and `sb_validate_large_blocksize` validates that size, the function continues. However, if `sb_validate_large_blocksize` returns an error (which it does with a return of `-EINVAL`), `sb_set_blocksize` immediately returns 0.
Here's the problem: if `sb_validate_large_blocksize` fails, `sb_set_blocksize` returns 0 *without* setting `sb->s_blocksize` to any value. This is a bit of a red flag. What was the value of `sb->s_blocksize` before? If the initialization procedure in `alloc_super` or `sget` leaves it at 0, then we have a situation where a failed validation could leave `sb->s_blocksize` and subsequently `sb->s_blocksize_bits` at 0. That looks like a possible source of errors down the line. I need to understand what the initial value is, to confirm this potential issue. I should check `alloc_super` and `sget` to ensure that `sb->s_blocksize` is initialized to something other than zero. This could have serious ramifications.
|
| 29/2 |
2026/05/30 14:11 |
tool |
grepper |
0m
Args: map[Expression:s_blocksize =]
Results: map[Output:arch/powerpc/platforms/cell/spufs/inode.c=698=static int spufs_fill_super(struct super_block *sb, struct fs_context *fc)
--
arch/powerpc/platforms/cell/spufs/inode.c-700- sb->s_maxbytes = MAX_LFS_FILESIZE;
arch/powerpc/platforms/cell/spufs/inode.c:701: sb->s_blocksize = PAGE_SIZE;
arch/powerpc/platforms/cell/spufs/inode.c-702- sb->s_blocksize_bits = PAGE_SHIFT;
--
arch/s390/hypfs/inode.c=240=static int hypfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
arch/s390/hypfs/inode.c-246-
arch/s390/hypfs/inode.c:247: sb->s_blocksize = PAGE_SIZE;
arch/s390/hypfs/inode.c-248- sb->s_blocksize_bits = PAGE_SHIFT;
--
block/bdev.c=236=int sb_set_blocksize(struct super_block *sb, int size)
--
block/bdev.c-242- /* If we get here, we know size is validated */
block/bdev.c:243: sb->s_blocksize = size;
block/bdev.c-244- sb->s_blocksize_bits = blksize_bits(size);
--
drivers/android/binder/rust_binderfs.c=615=static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
drivers/android/binder/rust_binderfs.c-624-
drivers/android/binder/rust_binderfs.c:625: sb->s_blocksize = PAGE_SIZE;
drivers/android/binder/rust_binderfs.c-626- sb->s_blocksize_bits = PAGE_SHIFT;
--
drivers/android/binderfs.c=611=static int binderfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
drivers/android/binderfs.c-620-
drivers/android/binderfs.c:621: sb->s_blocksize = PAGE_SIZE;
drivers/android/binderfs.c-622- sb->s_blocksize_bits = PAGE_SHIFT;
--
drivers/misc/ibmasm/ibmasmfs.c=108=static int ibmasmfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
drivers/misc/ibmasm/ibmasmfs.c-111-
drivers/misc/ibmasm/ibmasmfs.c:112: sb->s_blocksize = PAGE_SIZE;
drivers/misc/ibmasm/ibmasmfs.c-113- sb->s_blocksize_bits = PAGE_SHIFT;
--
drivers/usb/gadget/legacy/inode.c=2015=gadgetfs_fill_super (struct super_block *sb, struct fs_context *fc)
--
drivers/usb/gadget/legacy/inode.c-2034- /* superblock */
drivers/usb/gadget/legacy/inode.c:2035: sb->s_blocksize = PAGE_SIZE;
drivers/usb/gadget/legacy/inode.c-2036- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/9p/vfs_super.c=34=static int v9fs_fill_super(struct super_block *sb)
--
fs/9p/vfs_super.c-40- sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
fs/9p/vfs_super.c:41: sb->s_blocksize = 1 << sb->s_blocksize_bits;
fs/9p/vfs_super.c-42- sb->s_magic = V9FS_MAGIC;
--
fs/adfs/super.c=254=static int adfs_probe(struct super_block *sb, unsigned int offset, int silent,
--
fs/adfs/super.c-292- blocksize = 1 << dr->log2secsize;
fs/adfs/super.c:293: if (sb->s_blocksize == blocksize) {
fs/adfs/super.c-294- asb->s_map = adfs_read_map(sb, dr);
--
fs/autofs/inode.c=301=static int autofs_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/autofs/inode.c-310- sbi->sb = s;
fs/autofs/inode.c:311: s->s_blocksize = 1024;
fs/autofs/inode.c-312- s->s_blocksize_bits = 10;
--
fs/btrfs/disk-io.c=2896=static int init_mount_fs_info(struct btrfs_fs_info *fs_info, struct super_block *sb)
--
fs/btrfs/disk-io.c-2901- /* Temporary fixed values for block size until we read the superblock. */
fs/btrfs/disk-io.c:2902: sb->s_blocksize = BTRFS_BDEV_BLOCKSIZE;
fs/btrfs/disk-io.c-2903- sb->s_blocksize_bits = blksize_bits(BTRFS_BDEV_BLOCKSIZE);
--
fs/btrfs/disk-io.c=3279=int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_devices)
--
fs/btrfs/disk-io.c-3451- /* Update the values for the current filesystem. */
fs/btrfs/disk-io.c:3452: sb->s_blocksize = sectorsize;
fs/btrfs/disk-io.c-3453- sb->s_blocksize_bits = blksize_bits(sectorsize);
--
fs/coda/inode.c=199=static int coda_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/coda/inode.c-228- sb->s_flags |= SB_NOATIME;
fs/coda/inode.c:229: sb->s_blocksize = 4096; /* XXXXX what do we put here?? */
fs/coda/inode.c-230- sb->s_blocksize_bits = 12;
--
fs/configfs/mount.c=63=static int configfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/configfs/mount.c-67-
fs/configfs/mount.c:68: sb->s_blocksize = PAGE_SIZE;
fs/configfs/mount.c-69- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/devpts/inode.c=360=static int devpts_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/devpts/inode.c-365- s->s_iflags &= ~SB_I_NODEV;
fs/devpts/inode.c:366: s->s_blocksize = 1024;
fs/devpts/inode.c-367- s->s_blocksize_bits = 10;
--
fs/ecryptfs/main.c=435=static int ecryptfs_get_tree(struct fs_context *fc)
--
fs/ecryptfs/main.c-530- s->s_maxbytes = path.dentry->d_sb->s_maxbytes;
fs/ecryptfs/main.c:531: s->s_blocksize = path.dentry->d_sb->s_blocksize;
fs/ecryptfs/main.c-532- s->s_magic = ECRYPTFS_SUPER_MAGIC;
--
fs/erofs/super.c=635=static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/erofs/super.c-679- }
fs/erofs/super.c:680: sb->s_blocksize = PAGE_SIZE;
fs/erofs/super.c-681- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/erofs/super.c-711- if (erofs_is_fileio_mode(sbi)) {
fs/erofs/super.c:712: sb->s_blocksize = 1 << sbi->blkszbits;
fs/erofs/super.c-713- sb->s_blocksize_bits = sbi->blkszbits;
--
fs/ext4/extents-test.c=220=static int extents_kunit_init(struct kunit *test)
--
fs/ext4/extents-test.c-243-
fs/ext4/extents-test.c:244: sb->s_blocksize = 4096;
fs/ext4/extents-test.c-245- sb->s_blocksize_bits = 12;
--
fs/ext4/mballoc-test.c=190=static void mbt_init_sb_layout(struct super_block *sb,
--
fs/ext4/mballoc-test.c-195-
fs/ext4/mballoc-test.c:196: sb->s_blocksize = 1UL << layout->blocksize_bits;
fs/ext4/mballoc-test.c-197- sb->s_blocksize_bits = layout->blocksize_bits;
--
fs/ext4/super.c=3549=static ext4_fsblk_t descriptor_loc(struct super_block *sb,
--
fs/ext4/super.c-3569- */
fs/ext4/super.c:3570: if (sb->s_blocksize == 1024 && nr == 0 &&
fs/ext4/super.c-3571- le32_to_cpu(sbi->s_es->s_first_data_block) == 0)
--
fs/ext4/super.c=4709=static int ext4_check_feature_compatibility(struct super_block *sb,
--
fs/ext4/super.c-4784- if (sbi->s_daxdev) {
fs/ext4/super.c:4785: if (sb->s_blocksize == PAGE_SIZE)
fs/ext4/super.c-4786- set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags);
--
fs/ext4/super.c=5122=static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb,
--
fs/ext4/super.c-5188- */
fs/ext4/super.c:5189: if (sb->s_blocksize == blocksize)
fs/ext4/super.c-5190- goto success;
--
fs/fuse/inode.c=1771=static int fuse_fill_super_submount(struct super_block *sb,
--
fs/fuse/inode.c-1789- sb->s_time_gran = parent_sb->s_time_gran;
fs/fuse/inode.c:1790: sb->s_blocksize = parent_sb->s_blocksize;
fs/fuse/inode.c-1791- sb->s_blocksize_bits = parent_sb->s_blocksize_bits;
--
fs/fuse/inode.c=1877=int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
--
fs/fuse/inode.c-1900- } else {
fs/fuse/inode.c:1901: sb->s_blocksize = PAGE_SIZE;
fs/fuse/inode.c-1902- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/hostfs/hostfs_kern.c=928=static int hostfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/hostfs/hostfs_kern.c-933-
fs/hostfs/hostfs_kern.c:934: sb->s_blocksize = 1024;
fs/hostfs/hostfs_kern.c-935- sb->s_blocksize_bits = 10;
--
fs/hugetlbfs/inode.c=1374=hugetlbfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/hugetlbfs/inode.c-1404- sb->s_maxbytes = MAX_LFS_FILESIZE;
fs/hugetlbfs/inode.c:1405: sb->s_blocksize = huge_page_size(ctx->hstate);
fs/hugetlbfs/inode.c-1406- sb->s_blocksize_bits = huge_page_shift(ctx->hstate);
--
fs/jffs2/fs.c=514=int jffs2_do_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/jffs2/fs.c-592- sb->s_maxbytes = 0xFFFFFFFF;
fs/jffs2/fs.c:593: sb->s_blocksize = PAGE_SIZE;
fs/jffs2/fs.c-594- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/kernfs/mount.c=283=static int kernfs_fill_super(struct super_block *sb, struct kernfs_fs_context *kfc)
--
fs/kernfs/mount.c-292- sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
fs/kernfs/mount.c:293: sb->s_blocksize = PAGE_SIZE;
fs/kernfs/mount.c-294- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/libfs.c=676=static int pseudo_fs_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/libfs.c-681- s->s_maxbytes = MAX_LFS_FILESIZE;
fs/libfs.c:682: s->s_blocksize = PAGE_SIZE;
fs/libfs.c-683- s->s_blocksize_bits = PAGE_SHIFT;
--
fs/libfs.c=1036=int simple_fill_super(struct super_block *s, unsigned long magic,
--
fs/libfs.c-1042-
fs/libfs.c:1043: s->s_blocksize = PAGE_SIZE;
fs/libfs.c-1044- s->s_blocksize_bits = PAGE_SHIFT;
--
fs/nfs/super.c=1068=static void nfs_fill_super(struct super_block *sb, struct nfs_fs_context *ctx)
--
fs/nfs/super.c-1072- sb->s_blocksize_bits = 0;
fs/nfs/super.c:1073: sb->s_blocksize = 0;
fs/nfs/super.c-1074- sb->s_xattr = server->nfs_client->cl_nfs_mod->xattr;
--
fs/nfs/super.c-1076- if (server->bsize)
fs/nfs/super.c:1077: sb->s_blocksize =
fs/nfs/super.c-1078- nfs_block_size(server->bsize, &sb->s_blocksize_bits);
--
fs/nfs/super.c-1112-
fs/nfs/super.c:1113: if (sb->s_blocksize == 0)
fs/nfs/super.c:1114: sb->s_blocksize = nfs_block_bits(server->wsize,
fs/nfs/super.c-1115- &sb->s_blocksize_bits);
--
fs/nilfs2/the_nilfs.c=702=int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb)
--
fs/nilfs2/the_nilfs.c-762- nilfs->ns_blocksize_bits = sb->s_blocksize_bits;
fs/nilfs2/the_nilfs.c:763: nilfs->ns_blocksize = blocksize;
fs/nilfs2/the_nilfs.c-764-
--
fs/ocfs2/dlmfs/dlmfs.c=508=static int dlmfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/ocfs2/dlmfs/dlmfs.c-510- sb->s_maxbytes = MAX_LFS_FILESIZE;
fs/ocfs2/dlmfs/dlmfs.c:511: sb->s_blocksize = PAGE_SIZE;
fs/ocfs2/dlmfs/dlmfs.c-512- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/ocfs2/localalloc.c=101=unsigned int ocfs2_la_default_mb(struct ocfs2_super *osb)
--
fs/ocfs2/localalloc.c-116- */
fs/ocfs2/localalloc.c:117: if ((sb->s_blocksize == 512 && osb->s_clustersize <= 8192)
fs/ocfs2/localalloc.c:118: || (sb->s_blocksize == 1024 && osb->s_clustersize == 4096))
fs/ocfs2/localalloc.c-119- return OCFS2_LA_OLD_DEFAULT;
--
fs/ocfs2/xattr.c=576=int ocfs2_calc_security_init(struct inode *dir,
--
fs/ocfs2/xattr.c-591- */
fs/ocfs2/xattr.c:592: if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE ||
fs/ocfs2/xattr.c-593- s_size > OCFS2_XATTR_FREE_IN_IBODY) {
--
fs/ocfs2/xattr.c=614=int ocfs2_calc_xattr_init(struct inode *dir,
--
fs/ocfs2/xattr.c-661- */
fs/ocfs2/xattr.c:662: if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE ||
fs/ocfs2/xattr.c-663- (S_ISDIR(mode) && ocfs2_supports_inline_data(osb)) ||
--
fs/ocfs2/xattr.c-668-
fs/ocfs2/xattr.c:669: if (dir->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE &&
fs/ocfs2/xattr.c-670- (s_size + a_size) > OCFS2_XATTR_FREE_IN_BLOCK(dir)) {
--
fs/ocfs2/xattr.c=2706=static int ocfs2_xattr_ibody_find(struct inode *inode,
--
fs/ocfs2/xattr.c-2715-
fs/ocfs2/xattr.c:2716: if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE)
fs/ocfs2/xattr.c-2717- return 0;
--
fs/ocfs2/xattr.c=2802=static int ocfs2_xattr_ibody_set(struct inode *inode,
--
fs/ocfs2/xattr.c-2810-
fs/ocfs2/xattr.c:2811: if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE)
fs/ocfs2/xattr.c-2812- return -ENOSPC;
--
fs/ocfs2/xattr.c=3477=int ocfs2_xattr_set_handle(handle_t *handle,
--
fs/ocfs2/xattr.c-3520- */
fs/ocfs2/xattr.c:3521: if (inode->i_sb->s_blocksize == OCFS2_MIN_BLOCKSIZE) {
fs/ocfs2/xattr.c-3522- xbs.bucket = ocfs2_xattr_bucket_new(inode);
--
fs/omfs/inode.c=456=static int omfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/omfs/inode.c-497- sbi->s_num_blocks = be64_to_cpu(omfs_sb->s_num_blocks);
fs/omfs/inode.c:498: sbi->s_blocksize = be32_to_cpu(omfs_sb->s_blocksize);
fs/omfs/inode.c-499- sbi->s_mirrors = be32_to_cpu(omfs_sb->s_mirrors);
fs/omfs/inode.c-500- sbi->s_root_ino = be64_to_cpu(omfs_sb->s_root_block);
fs/omfs/inode.c:501: sbi->s_sys_blocksize = be32_to_cpu(omfs_sb->s_sys_blocksize);
fs/omfs/inode.c-502- mutex_init(&sbi->s_bitmap_lock);
--
fs/openpromfs/inode.c=371=static int openprom_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/openpromfs/inode.c-377- s->s_flags |= SB_NOATIME;
fs/openpromfs/inode.c:378: s->s_blocksize = 1024;
fs/openpromfs/inode.c-379- s->s_blocksize_bits = 10;
--
fs/orangefs/super.c=400=static int orangefs_fill_sb(struct super_block *sb,
--
fs/orangefs/super.c-420-
fs/orangefs/super.c:421: sb->s_blocksize = PAGE_SIZE;
fs/orangefs/super.c-422- sb->s_blocksize_bits = PAGE_SHIFT;
--
fs/proc/root.c=245=static int proc_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/proc/root.c-261- s->s_flags |= SB_NODIRATIME | SB_NOSUID | SB_NOEXEC;
fs/proc/root.c:262: s->s_blocksize = 1024;
fs/proc/root.c-263- s->s_blocksize_bits = 10;
--
fs/romfs/super.c=450=static int romfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/romfs/super.c-465- } else {
fs/romfs/super.c:466: sb->s_blocksize = ROMBSIZE;
fs/romfs/super.c-467- sb->s_blocksize_bits = blksize_bits(ROMBSIZE);
--
fs/smb/client/cifsfs.c=193=cifs_read_super(struct super_block *sb)
--
fs/smb/client/cifsfs.c-260-
fs/smb/client/cifsfs.c:261: sb->s_blocksize = CIFS_MAX_MSGSIZE;
fs/smb/client/cifsfs.c-262- sb->s_blocksize_bits = 14; /* default 2**14 = CIFS_MAX_MSGSIZE */
--
fs/ubifs/super.c=2129=static int ubifs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/ubifs/super.c-2175- sb->s_magic = UBIFS_SUPER_MAGIC;
fs/ubifs/super.c:2176: sb->s_blocksize = UBIFS_BLOCK_SIZE;
fs/ubifs/super.c-2177- sb->s_blocksize_bits = UBIFS_BLOCK_SHIFT;
--
fs/udf/super.c=739=static int udf_check_vsd(struct super_block *sb)
--
fs/udf/super.c-789- */
fs/udf/super.c:790: if (sb->s_blocksize == 4096) {
fs/udf/super.c-791- nsr = identify_vsd(vsd + 1);
--
fs/vboxsf/super.c=111=static int vboxsf_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/vboxsf/super.c-188- sb->s_magic = VBOXSF_SUPER_MAGIC;
fs/vboxsf/super.c:189: sb->s_blocksize = 1024;
fs/vboxsf/super.c-190- sb->s_maxbytes = MAX_LFS_FILESIZE;
--
fs/xfs/xfs_super.c=1652=xfs_fs_fill_super(
--
fs/xfs/xfs_super.c-1863- sb->s_magic = XFS_SUPER_MAGIC;
fs/xfs/xfs_super.c:1864: sb->s_blocksize = mp->m_sb.sb_blocksize;
fs/xfs/xfs_super.c-1865- sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
--
ipc/mqueue.c=403=static int mqueue_fill_super(struct super_block *sb, struct fs_context *fc)
--
ipc/mqueue.c-408- sb->s_iflags |= SB_I_NOEXEC | SB_I_NODEV;
ipc/mqueue.c:409: sb->s_blocksize = PAGE_SIZE;
ipc/mqueue.c-410- sb->s_blocksize_bits = PAGE_SHIFT;
--
mm/shmem.c=4998=static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
--
mm/shmem.c-5079- sb->s_maxbytes = MAX_LFS_FILESIZE;
mm/shmem.c:5080: sb->s_blocksize = PAGE_SIZE;
mm/shmem.c-5081- sb->s_blocksize_bits = PAGE_SHIFT;
--
net/sunrpc/rpc_pipe.c=1117=rpc_fill_super(struct super_block *sb, struct fs_context *fc)
--
net/sunrpc/rpc_pipe.c-1124-
net/sunrpc/rpc_pipe.c:1125: sb->s_blocksize = PAGE_SIZE;
net/sunrpc/rpc_pipe.c-1126- sb->s_blocksize_bits = PAGE_SHIFT;
]
|
| 30/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 27539
output: 33
thoughts: 33
Thoughts: Okay, let's see...
**Checking the Superblock Blocksize Initialization**
Hmm, I need to understand something fundamental here. I'm looking at this code and my immediate thought is: "Wait, *exactly* what value is `sb->s_blocksize` initialized to?" I need to know where this value originates. Itβs absolutely critical to understanding how the file system's block size is handled.
Right, time to dive in. Let's head over to `fs/super.c`. Specifically, I need to check the `alloc_super` function. That's the likely place where the `superblock` structure, `sb`, gets its initial setup, including that crucial `s_blocksize` field. I need to trace this back. This initial assignment is the key!
|
| 31/2 |
2026/05/30 14:11 |
tool |
read-file |
0m
Args: map[File:fs/super.c FirstLine:300 LineCount:50]
Results: map[Contents: 300: super_unlock_excl(s);
301: list_lru_destroy(&s->s_dentry_lru);
302: list_lru_destroy(&s->s_inode_lru);
303: shrinker_free(s->s_shrink);
304: /* no delays needed */
305: destroy_super_work(&s->destroy_work);
306: }
307:
308: /**
309: * alloc_super - create new superblock
310: * @type: filesystem type superblock should belong to
311: * @flags: the mount flags
312: * @user_ns: User namespace for the super_block
313: *
314: * Allocates and initializes a new &struct super_block. alloc_super()
315: * returns a pointer new superblock or %NULL if allocation had failed.
316: */
317: static struct super_block *alloc_super(struct file_system_type *type, int flags,
318: struct user_namespace *user_ns)
319: {
320: struct super_block *s = kzalloc_obj(struct super_block);
321: static const struct super_operations default_op;
322: int i;
323:
324: if (!s)
325: return NULL;
326:
327: s->s_user_ns = get_user_ns(user_ns);
328: init_rwsem(&s->s_umount);
329: lockdep_set_class(&s->s_umount, &type->s_umount_key);
330: /*
331: * sget() can have s_umount recursion.
332: *
333: * When it cannot find a suitable sb, it allocates a new
334: * one (this one), and tries again to find a suitable old
335: * one.
336: *
337: * In case that succeeds, it will acquire the s_umount
338: * lock of the old one. Since these are clearly distrinct
339: * locks, and this object isn't exposed yet, there's no
340: * risk of deadlocks.
341: *
342: * Annotate this by putting this lock in a different
343: * subclass.
344: */
345: down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING);
346:
347: if (security_sb_alloc(s))
348: goto fail;
349:
]
|
| 32/2 |
2026/05/30 14:11 |
llm |
expert |
0m
Model:
Tokens:
input: 28558
output: 34
thoughts: 191
Thoughts: **Analyzing a Potential Zero-Size Block Issue**
Okay, so I'm looking at `kzalloc_obj`, which means this new structure is initialized with all zeros. Now, I see this interaction with `sb->s_blocksize` and it's making me pause. If `sb->s_blocksize` is zero, then this call to `sb_bread` with `SUPER1_OFF >> sb->s_blocksize_bits` is going to be problematic, given that the right-hand side of the bit shift becomes 0.
Wait, let me just check... `SUPER1_OFF` is 32768. A right shift of 0 bits is just 32768, so no change to the value. Thus, we're really calling `sb_bread` with an offset of 32768.
So, `sb_bread` then calls `__bread_gfp(bdev, block, sb->s_blocksize, gfp)`. This is where it gets interesting... or worrying. If `sb->s_blocksize` is zero, as suspected, that's what's getting passed into the `__bread_gfp` function.
Right, so we're looking at `__bread_gfp(bdev, 32768, 0, gfp)`. That *has* to be a problem. This means we are requesting that `__bread_gfp` read a block size of 0. Time to trace that function and see what it does with a zero-sized block.
|
| 33/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:1400 LineCount:50]
Results: map[Contents:1400: unsigned size, gfp_t gfp)
1401: {
1402: struct buffer_head *bh;
1403:
1404: gfp |= mapping_gfp_constraint(bdev->bd_mapping, ~__GFP_FS);
1405:
1406: /*
1407: * Prefer looping in the allocator rather than here, at least that
1408: * code knows what it's doing.
1409: */
1410: gfp |= __GFP_NOFAIL;
1411:
1412: bh = bdev_getblk(bdev, block, size, gfp);
1413:
1414: if (likely(bh) && !buffer_uptodate(bh))
1415: bh = __bread_slow(bh);
1416: return bh;
1417: }
1418: EXPORT_SYMBOL(__bread_gfp);
1419:
1420: static void __invalidate_bh_lrus(struct bh_lru *b)
1421: {
1422: int i;
1423:
1424: for (i = 0; i < BH_LRU_SIZE; i++) {
1425: brelse(b->bhs[i]);
1426: b->bhs[i] = NULL;
1427: }
1428: }
1429: /*
1430: * invalidate_bh_lrus() is called rarely - but not only at unmount.
1431: * This doesn't race because it runs in each cpu either in irq
1432: * or with preempt disabled.
1433: */
1434: static void invalidate_bh_lru(void *arg)
1435: {
1436: struct bh_lru *b = &get_cpu_var(bh_lrus);
1437:
1438: __invalidate_bh_lrus(b);
1439: put_cpu_var(bh_lrus);
1440: }
1441:
1442: bool has_bh_in_lru(int cpu, void *dummy)
1443: {
1444: struct bh_lru *b = per_cpu_ptr(&bh_lrus, cpu);
1445: int i;
1446:
1447: for (i = 0; i < BH_LRU_SIZE; i++) {
1448: if (b->bhs[i])
1449: return true;
]
|
| 34/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 29855
output: 34
thoughts: 38
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Investigating a Zero-Sized Block Request**
Alright, so `bdev_getblk(bdev, block, size, gfp)` is being called, and the `size` parameter is inexplicably zero. That's immediately a red flag. A zero-sized block request is fundamentally nonsensical; a block has to have *some* size, at least conceptually. My immediate instinct is to trace the call. I need to understand *why* this is happening. Is it an upstream bug in the file system, or perhaps a miscalculation during I/O setup? I need to quickly determine the origin of this request to assess the potential impact. It's likely a bug, a corner case, or maybe some unexpected interaction with the block layer. I need to determine the call path and if it is an expected case, and what the effect of the zero sized request might be. I need to see if it is a harmless optimization, or a more serious flaw.
|
| 35/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:1340 LineCount:50]
Results: map[Contents:1340: * caller can bring it uptodate either by reading it or overwriting it.
1341: *
1342: * Return: The buffer head, or NULL if memory could not be allocated.
1343: */
1344: struct buffer_head *bdev_getblk(struct block_device *bdev, sector_t block,
1345: unsigned size, gfp_t gfp)
1346: {
1347: struct buffer_head *bh;
1348:
1349: if (gfpflags_allow_blocking(gfp))
1350: bh = __find_get_block_nonatomic(bdev, block, size);
1351: else
1352: bh = __find_get_block(bdev, block, size);
1353:
1354: might_alloc(gfp);
1355: if (bh)
1356: return bh;
1357:
1358: return __getblk_slow(bdev, block, size, gfp);
1359: }
1360: EXPORT_SYMBOL(bdev_getblk);
1361:
1362: /*
1363: * Do async read-ahead on a buffer..
1364: */
1365: void __breadahead(struct block_device *bdev, sector_t block, unsigned size)
1366: {
1367: struct buffer_head *bh = bdev_getblk(bdev, block, size,
1368: GFP_NOWAIT | __GFP_MOVABLE);
1369:
1370: if (likely(bh)) {
1371: bh_readahead(bh, REQ_RAHEAD);
1372: brelse(bh);
1373: }
1374: }
1375: EXPORT_SYMBOL(__breadahead);
1376:
1377: /**
1378: * __bread_gfp() - Read a block.
1379: * @bdev: The block device to read from.
1380: * @block: Block number in units of block size.
1381: * @size: The block size of this device in bytes.
1382: * @gfp: Not page allocation flags; see below.
1383: *
1384: * You are not expected to call this function. You should use one of
1385: * sb_bread(), sb_bread_unmovable() or __bread().
1386: *
1387: * Read a specified block, and return the buffer head that refers to it.
1388: * If @gfp is 0, the memory will be allocated using the block device's
1389: * default GFP flags. If @gfp is __GFP_MOVABLE, the memory may be
]
|
| 36/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 30936
output: 34
thoughts: 41
Thoughts: Okay, here's my interpretation of that thought process, assuming I'm deep in the kernel code:
**Analyzing a Zero-Sized Block Request**
Right, so the trace indicates a call to `__getblk_slow(bdev, block, 0, gfp)`. Interesting. The `size` argument being zero immediately grabs my attention. That's not the usual scenario. It usually means an improper request. Time to revisit `__getblk_slow` and understand exactly how it handles that specific situation. I need to figure out the path the code takes when dealing with a zero-sized block request and why it's happening. Is this a potential bug, a corner case, or maybe a legitimate, albeit unusual, control flow? My experience tells me zero-sized blocks are usually a smell, so let's dig in and see what's going on.
|
| 37/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:fs/buffer.c FirstLine:1020 LineCount:50]
Results: map[Contents:1020: return grow_dev_folio(bdev, block, pos / PAGE_SIZE, size, gfp);
1021: }
1022:
1023: static struct buffer_head *
1024: __getblk_slow(struct block_device *bdev, sector_t block,
1025: unsigned size, gfp_t gfp)
1026: {
1027: bool blocking = gfpflags_allow_blocking(gfp);
1028:
1029: if (WARN_ON_ONCE(!IS_ALIGNED(size, bdev_logical_block_size(bdev)))) {
1030: printk(KERN_ERR "getblk(): block size %d not aligned to logical block size %d\n",
1031: size, bdev_logical_block_size(bdev));
1032: return NULL;
1033: }
1034:
1035: for (;;) {
1036: struct buffer_head *bh;
1037:
1038: if (!grow_buffers(bdev, block, size, gfp))
1039: return NULL;
1040:
1041: if (blocking)
1042: bh = __find_get_block_nonatomic(bdev, block, size);
1043: else
1044: bh = __find_get_block(bdev, block, size);
1045: if (bh)
1046: return bh;
1047: }
1048: }
1049:
1050: /*
1051: * The relationship between dirty buffers and dirty pages:
1052: *
1053: * Whenever a page has any dirty buffers, the page's dirty bit is set, and
1054: * the page is tagged dirty in the page cache.
1055: *
1056: * At all times, the dirtiness of the buffers represents the dirtiness of
1057: * subsections of the page. If the page has buffers, the page dirty bit is
1058: * merely a hint about the true dirty state.
1059: *
1060: * When a page is set dirty in its entirety, all its buffers are marked dirty
1061: * (if the page has buffers).
1062: *
1063: * When a buffer is marked dirty, its page is dirtied, but the page's other
1064: * buffers are not.
1065: *
1066: * Also. When blockdev buffers are explicitly read with bread(), they
1067: * individually become uptodate. But their backing page remains not
1068: * uptodate - even if all of its buffers are uptodate. A subsequent
1069: * block_read_full_folio() against that folio will discover all the uptodate
]
|
| 38/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 31992
output: 34
thoughts: 477
Thoughts: **Debugging a Kernel BUG_ON in Block Device Handling**
Okay, here's what's happening. I'm seeing this `BUG_ON` fire, and I need to figure out why. The trace leads me to this: `WARN_ON_ONCE(!IS_ALIGNED(size, bdev_logical_block_size(bdev)))`. If the `size` is zero, which seems to be the case, then this check passes silently because zero is always aligned. That's immediately suspicious.
So, when `size` is zero, we skip the warning and proceed to call `grow_buffers(bdev, block, 0, gfp)`. This then calls `grow_dev_folio`, which in turn calls `folio_alloc_buffers(folio, 0, gfp | __GFP_ACCOUNT)`.
Now, inside `folio_alloc_buffers`, the code does this:
```c
offset = folio_size(folio);
while ((offset -= size) >= 0) {
```
If `size` is zero, `offset` effectively never changes in the loop. It stays equal to `folio_size(folio)`. Then, we call `folio_set_bh(bh, folio, offset)`. And the issue hits in `folio_set_bh`:
```c
BUG_ON(offset >= folio_size(folio));
```
Since `offset` is equal to `folio_size(folio)`, this `BUG_ON` trips! So the underlying problem is that `sb->s_blocksize` is zero. This causes `sb_bread` to pass `size = 0` to `__bread_gfp`, ultimately leading to this `folio_alloc_buffers` call with `size = 0`, which creates a loop with a buggy termination condition, and thus the `BUG_ON`.
The next step is, why is `sb->s_blocksize` zero? It's because `sb_set_blocksize(sb, PSIZE)` failed. Wait, if `PSIZE` is 4096, which is common, then `size > PAGE_SIZE` would be false, so it shouldn't fail. Something is missing here. I need to re-examine the `sb_set_blocksize` logic. I need to understand why this initial block size setting isn't succeeding.
|
| 39/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:block/bdev.c FirstLine:230 LineCount:20]
Results: map[Contents: 230:
231: pr_warn_ratelimited("%s: block size(%d) > page size(%lu) %s\n",
232: sb->s_type->name, size, PAGE_SIZE, err_str);
233: return -EINVAL;
234: }
235:
236: int sb_set_blocksize(struct super_block *sb, int size)
237: {
238: if (size > PAGE_SIZE && sb_validate_large_blocksize(sb, size))
239: return 0;
240: if (set_blocksize(sb->s_bdev_file, size))
241: return 0;
242: /* If we get here, we know size is validated */
243: sb->s_blocksize = size;
244: sb->s_blocksize_bits = blksize_bits(size);
245: return sb->s_blocksize;
246: }
247:
248: EXPORT_SYMBOL(sb_set_blocksize);
249:
]
|
| 40/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 33349
output: 34
thoughts: 34
Thoughts: Here's my take on the thought process:
**Potential Block Size Failure**
Okay, hold on a second. When I'm calling `set_blocksize(sb->s_bdev_file, size)`, I've got to remember that this *could* actually fail. I'm operating under the assumption that it will set the block size successfully, but I need to be prepared for the situation where it doesn't. This can have serious implications depending on the filesystem's state. I'd better double-check the potential return values from that function. Let's dig into `set_blocksize` and see what error conditions it could throw. I need to understand exactly what I need to handle in the calling function.
|
| 41/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:block/bdev.c FirstLine:180 LineCount:40]
Results: map[Contents: 180: struct inode *inode = file->f_mapping->host;
181: struct block_device *bdev = I_BDEV(inode);
182: int ret;
183:
184: ret = bdev_validate_blocksize(bdev, size);
185: if (ret)
186: return ret;
187:
188: if (!file->private_data)
189: return -EINVAL;
190:
191: /* Don't change the size if it is same as current */
192: if (inode->i_blkbits != blksize_bits(size)) {
193: /*
194: * Flush and truncate the pagecache before we reconfigure the
195: * mapping geometry because folio sizes are variable now. If a
196: * reader has already allocated a folio whose size is smaller
197: * than the new min_order but invokes readahead after the new
198: * min_order becomes visible, readahead will think there are
199: * "zero" blocks per folio and crash. Take the inode and
200: * invalidation locks to avoid racing with
201: * read/write/fallocate.
202: */
203: inode_lock(inode);
204: filemap_invalidate_lock(inode->i_mapping);
205:
206: sync_blockdev(bdev);
207: kill_bdev(bdev);
208:
209: inode->i_blkbits = blksize_bits(size);
210: mapping_set_folio_min_order(inode->i_mapping, get_order(size));
211: filemap_invalidate_unlock(inode->i_mapping);
212: inode_unlock(inode);
213: }
214: return 0;
215: }
216:
217: EXPORT_SYMBOL(set_blocksize);
218:
219: static int sb_validate_large_blocksize(struct super_block *sb, int size)
]
|
| 42/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 34189
output: 34
thoughts: 28
Thoughts: Here's my take on those thoughts, assuming I'm deep in storage internals:
**Diving into Block Size Validation**
Alright, let's get down to brass tacks. I'm looking at `bdev_validate_blocksize(bdev, size)`. That function name alone tells me we're about to delve into the nitty-gritty of block size verification for a block device. I need to understand this validation step. What are the constraints? What are the implications if the `size` provided isn't kosher for the `bdev`? Is this about the physical block size of the underlying media, or something more related to the logical block size presented to the system? I need to check the exact function definition to ascertain which of these variables is at play. Any validation here is critical. Failure to do so could lead to fragmentation, corruption, or, at best, a performance bottleneck. Let's see how this works.
|
| 43/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:block/bdev.c FirstLine:150 LineCount:30]
Results: map[Contents: 150: BD_INODE(bdev)->i_blkbits = blksize_bits(bsize);
151: mapping_set_folio_min_order(BD_INODE(bdev)->i_mapping,
152: get_order(bsize));
153: }
154:
155: /**
156: * bdev_validate_blocksize - check that this block size is acceptable
157: * @bdev: blockdevice to check
158: * @block_size: block size to check
159: *
160: * For block device users that do not use buffer heads or the block device
161: * page cache, make sure that this block size can be used with the device.
162: *
163: * Return: On success zero is returned, negative error code on failure.
164: */
165: int bdev_validate_blocksize(struct block_device *bdev, int block_size)
166: {
167: if (blk_validate_block_size(block_size))
168: return -EINVAL;
169:
170: /* Size cannot be smaller than the size supported by the device */
171: if (block_size < bdev_logical_block_size(bdev))
172: return -EINVAL;
173:
174: return 0;
175: }
176: EXPORT_SYMBOL_GPL(bdev_validate_blocksize);
177:
178: int set_blocksize(struct file *file, int size)
179: {
]
|
| 44/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 34929
output: 36
thoughts: 357
Thoughts: **Investigating a Block Size Mismatch**
Okay, here's what's going through my head: I see this `block_size < bdev_logical_block_size(bdev)` condition, which immediately triggers a red flag. Let's say the logical block size of the block device (`bdev`) is 32768, while the requested `block_size` is 4096. That, based on my understanding, should cause `bdev_validate_blocksize` to return `-EINVAL`. Then I see the log message: "jfs: block size(32768) > page size(4096) not supported by filesystem". I immediately wonder where that log originates from.
Time to search the codebase. A quick search for the log message's format string, "block size(%d) > page size(%lu) %s", leads me to `block/bdev.c`. And there it is: `sb_validate_large_blocksize`.
Okay, let's think about this: if `sb_validate_large_blocksize` is being called, it *must* mean that the `size` being passed is greater than `PAGE_SIZE`. But in the `sb_set_blocksize(sb, PSIZE)` function, the `PSIZE` argument, which is equivalent to the `PAGE_SIZE`, which is 4096. If `PAGE_SIZE` is 4096, then it must be false that `size > PAGE_SIZE`. So, it shouldn't be called from `sb_set_blocksize(sb, PSIZE)`.
There's something I'm missing. Is there another place where `sb_set_blocksize` is called? The `jfs_fill_super` function comes to mind. Let's dig deeper there.
|
| 45/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:fs/jfs/super.c FirstLine:520 LineCount:50]
Results: map[Contents: 520:
521: sbi->direct_inode = inode;
522:
523: rc = jfs_mount(sb);
524: if (rc) {
525: if (!silent)
526: jfs_err("jfs_mount failed w/return code = %d", rc);
527: goto out_mount_failed;
528: }
529: if (sb_rdonly(sb))
530: sbi->log = NULL;
531: else {
532: rc = jfs_mount_rw(sb, 0);
533: if (rc) {
534: if (!silent) {
535: jfs_err("jfs_mount_rw failed, return code = %d",
536: rc);
537: }
538: goto out_no_rw;
539: }
540: }
541:
542: sb->s_magic = JFS_SUPER_MAGIC;
543:
544: if (sbi->mntflag & JFS_OS2)
545: set_default_d_op(sb, &jfs_ci_dentry_operations);
546:
547: inode = jfs_iget(sb, ROOT_I);
548: if (IS_ERR(inode)) {
549: ret = PTR_ERR(inode);
550: goto out_no_rw;
551: }
552: sb->s_root = d_make_root(inode);
553: if (!sb->s_root)
554: goto out_no_root;
555:
556: /* logical blocks are represented by 40 bits in pxd_t, etc.
557: * and page cache is indexed by long
558: */
559: sb->s_maxbytes = min(((loff_t)sb->s_blocksize) << 40, MAX_LFS_FILESIZE);
560: sb->s_time_gran = 1;
561: return 0;
562:
563: out_no_root:
564: jfs_err("jfs_read_super: get root dentry failed");
565:
566: out_no_rw:
567: rc = jfs_umount(sb);
568: if (rc)
569: jfs_err("jfs_umount failed with return code %d", rc);
]
|
| 46/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 36470
output: 38
thoughts: 22
Thoughts: Here's my take on the thought process, summarized as you requested:
**Deconstructing the `jfs_mount` Call**
Okay, so I see a call to `jfs_mount`. Immediately, my brain kicks into gear. My initial thought is, "Ah, `jfs_mount`! Let's dig into that function." It's likely the core of the JFS filesystem interaction, so understanding its behavior is critical to understanding the bigger picture. I need to refresh my understanding of its role within the mounting process. I'll need to know this inside and out. It's time to dive into the specifics of the `jfs_mount` function.
|
| 47/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:fs/jfs/jfs_mount.c FirstLine:60 LineCount:50]
Results: map[Contents: 60: * FUNCTION: vfs_mount()
61: *
62: * PARAMETER: sb - super block
63: *
64: * RETURN: -EBUSY - device already mounted or open for write
65: * -EBUSY - cvrdvp already mounted;
66: * -EBUSY - mount table full
67: * -ENOTDIR- cvrdvp not directory on a device mount
68: * -ENXIO - device open failure
69: */
70: int jfs_mount(struct super_block *sb)
71: {
72: int rc = 0; /* Return code */
73: struct jfs_sb_info *sbi = JFS_SBI(sb);
74: struct inode *ipaimap = NULL;
75: struct inode *ipaimap2 = NULL;
76: struct inode *ipimap = NULL;
77: struct inode *ipbmap = NULL;
78:
79: /*
80: * read/validate superblock
81: * (initialize mount inode from the superblock)
82: */
83: if ((rc = chkSuper(sb))) {
84: goto out;
85: }
86:
87: ipaimap = diReadSpecial(sb, AGGREGATE_I, 0);
88: if (ipaimap == NULL) {
89: jfs_err("jfs_mount: Failed to read AGGREGATE_I");
90: rc = -EIO;
91: goto out;
92: }
93: sbi->ipaimap = ipaimap;
94:
95: jfs_info("jfs_mount: ipaimap:0x%p", ipaimap);
96:
97: /*
98: * initialize aggregate inode allocation map
99: */
100: if ((rc = diMount(ipaimap))) {
101: jfs_err("jfs_mount: diMount(ipaimap) failed w/rc = %d", rc);
102: goto err_ipaimap;
103: }
104:
105: /*
106: * open aggregate block allocation map
107: */
108: ipbmap = diReadSpecial(sb, BMAP_I, 0);
109: if (ipbmap == NULL) {
]
|
| 48/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 37381
output: 39
thoughts: 20
Thoughts: Here's my thought process, summarized as if I were considering the code:
**Analyzing the `chkSuper` Call**
Okay, I'm tracing through this, and the first thing that jumps out is that `chkSuper` is being called. Alright, let's stop and re-examine exactly what `chkSuper` does, what its purpose is in this context. I need to refresh my memory on the intricacies of that function. Let's dig back into the specifics of its implementation, the variables it operates on, and what conditions trigger its invocation here. I need to be sure I understand the flow and its impact. Back to the code!
|
| 49/2 |
2026/05/30 14:12 |
tool |
read-file |
0m
Args: map[File:fs/jfs/jfs_mount.c FirstLine:310 LineCount:50]
Results: map[Contents: 310: goto out;
311: }
312:
313: bsize = le32_to_cpu(j_sb->s_bsize);
314: if (bsize != PSIZE) {
315: jfs_err("Only 4K block size supported!");
316: rc = -EINVAL;
317: goto out;
318: }
319:
320: jfs_info("superblock: flag:0x%08x state:0x%08x size:0x%Lx",
321: le32_to_cpu(j_sb->s_flag), le32_to_cpu(j_sb->s_state),
322: (unsigned long long) le64_to_cpu(j_sb->s_size));
323:
324: /* validate the descriptors for Secondary AIM and AIT */
325: if ((j_sb->s_flag & cpu_to_le32(JFS_BAD_SAIT)) !=
326: cpu_to_le32(JFS_BAD_SAIT)) {
327: expected_AIM_bytesize = 2 * PSIZE;
328: AIM_bytesize = lengthPXD(&j_sb->s_aim2) * bsize;
329: expected_AIT_bytesize = 4 * PSIZE;
330: AIT_bytesize = lengthPXD(&j_sb->s_ait2) * bsize;
331: AIM_byte_addr = addressPXD(&j_sb->s_aim2) * bsize;
332: AIT_byte_addr = addressPXD(&j_sb->s_ait2) * bsize;
333: byte_addr_diff0 = AIT_byte_addr - AIM_byte_addr;
334: fsckwsp_addr = addressPXD(&j_sb->s_fsckpxd) * bsize;
335: byte_addr_diff1 = fsckwsp_addr - AIT_byte_addr;
336: if ((AIM_bytesize != expected_AIM_bytesize) ||
337: (AIT_bytesize != expected_AIT_bytesize) ||
338: (byte_addr_diff0 != AIM_bytesize) ||
339: (byte_addr_diff1 <= AIT_bytesize))
340: j_sb->s_flag |= cpu_to_le32(JFS_BAD_SAIT);
341: }
342:
343: if ((j_sb->s_flag & cpu_to_le32(JFS_GROUPCOMMIT)) !=
344: cpu_to_le32(JFS_GROUPCOMMIT))
345: j_sb->s_flag |= cpu_to_le32(JFS_GROUPCOMMIT);
346:
347: /* validate fs state */
348: if (j_sb->s_state != cpu_to_le32(FM_CLEAN) &&
349: !sb_rdonly(sb)) {
350: jfs_err("jfs_mount: Mount Failure: File System Dirty.");
351: rc = -EINVAL;
352: goto out;
353: }
354:
355: sbi->state = le32_to_cpu(j_sb->s_state);
356: sbi->mntflag = le32_to_cpu(j_sb->s_flag);
357:
358: /*
359: * JFS always does I/O by 4K pages. Don't tell the buffer cache
]
|
| 50/2 |
2026/05/30 14:12 |
llm |
expert |
0m
Model:
Tokens:
input: 38602
output: 23
thoughts: 1219
Thoughts: **Debugging JFS Block Size Initialization**
Okay, let's see. `chkSuper` calls `readSuper`, which in turn calls `sb_bread`. Now, `readSuper` is supposed to read the superblock from the block device. In JFS, this happens after `sb_set_blocksize` is called, but before `jfs_mount`, where the block size is initialized to 4096 (PSIZE). So, normally, the block size should be 4096, and `sb_bread` should be called with an offset calculated using 4096.
But what if something goes wrong, and `sb_set_blocksize` *fails*? If it fails, `sb->s_blocksize` would remain 0. Looking at the code for `sb_set_blocksize`, the important parts are: `sb_set_blocksize` calls `set_blocksize`, which eventually calls `bdev_validate_blocksize`. `bdev_validate_blocksize` has a check: `block_size < bdev_logical_block_size(bdev)`. Aha! If the *device* has a logical block size larger than 4096, like 32768, then this check will fail, returning `-EINVAL`. This would cause the entire function call to fail, and `sb->s_blocksize` would be zero, which is the root cause. This confirms the log: "jfs: block size(32768) > page size(4096) not supported by filesystem".
Now the question is, why is the code calling `sb_validate_large_blocksize` with 32768, when `jfs_fill_super` only sets it to 4096?
|
| 51/2 |
2026/05/30 14:13 |
tool |
grepper |
0m
Error:
Args: map[Expression:sb_min_blocksize.*jfs]
Results:
|
| 52/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 40250
output: 34
thoughts: 22
Thoughts: Here's a summary of my thought process:
**Diving into Block Device Flags**
Okay, I need to understand how block device flags are handled within the file system code. My first instinct is to check out `get_tree_bdev_flags` and see how they are retrieved, since I'm trying to work out something more high level. My hunch is it's located in `fs/super.c`. This is where a lot of the superblock and block device information usually resides, so it seems like the logical place to start digging. Let's see what we can find. I'm going to look specifically at the implementation of that function and how it interfaces with the lower-level block device structures. I'll need to understand the data structures it uses, and what operations it's performing to pull those flags out and see how this fits into my overall understanding of the kernel's block device management.
|
| 53/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:fs/super.c FirstLine:1650 LineCount:50]
Results: map[Contents:1650: sb->s_id);
1651: sb_set_blocksize(sb, block_size(bdev));
1652: return 0;
1653: }
1654: EXPORT_SYMBOL_GPL(setup_bdev_super);
1655:
1656: /**
1657: * get_tree_bdev_flags - Get a superblock based on a single block device
1658: * @fc: The filesystem context holding the parameters
1659: * @fill_super: Helper to initialise a new superblock
1660: * @flags: GET_TREE_BDEV_* flags
1661: */
1662: int get_tree_bdev_flags(struct fs_context *fc,
1663: int (*fill_super)(struct super_block *sb,
1664: struct fs_context *fc), unsigned int flags)
1665: {
1666: struct super_block *s;
1667: int error = 0;
1668: dev_t dev;
1669:
1670: if (!fc->source)
1671: return invalf(fc, "No source specified");
1672:
1673: error = lookup_bdev(fc->source, &dev);
1674: if (error) {
1675: if (!(flags & GET_TREE_BDEV_QUIET_LOOKUP))
1676: errorf(fc, "%s: Can't lookup blockdev", fc->source);
1677: return error;
1678: }
1679: fc->sb_flags |= SB_NOSEC;
1680: s = sget_dev(fc, dev);
1681: if (IS_ERR(s))
1682: return PTR_ERR(s);
1683:
1684: if (s->s_root) {
1685: /* Don't summarily change the RO/RW state. */
1686: if ((fc->sb_flags ^ s->s_flags) & SB_RDONLY) {
1687: warnf(fc, "%pg: Can't mount, would change RO state", s->s_bdev);
1688: deactivate_locked_super(s);
1689: return -EBUSY;
1690: }
1691: } else {
1692: error = setup_bdev_super(s, fc->sb_flags, fc);
1693: if (!error)
1694: error = fill_super(s, fc);
1695: if (error) {
1696: deactivate_locked_super(s);
1697: return error;
1698: }
1699: s->s_flags |= SB_ACTIVE;
]
|
| 54/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 41282
output: 34
thoughts: 46
Thoughts: Okay, here's my interpretation of that thought process, from an expert's perspective:
**Initial Assessment: Superblock Setup Sequence**
Right, *setup_bdev_super(s, fc->sb_flags, fc)* is being called *before* the actual *fill_super(s, fc)* call. That's interesting. It suggests a specific initialization order, and it's something I need to keep in mind. We're dealing with the superblock setup sequence, so this initial call clearly establishes the base for how the superblock interacts with the underlying block device (`bdev`).
Time to examine what's going on within *setup_bdev_super*. This will undoubtedly shed light on the pre-superblock preparation and any early metadata handling or device interaction that takes place. Let's dig in.
|
| 55/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:fs/super.c FirstLine:1620 LineCount:40]
Results: map[Contents:1620: /*
1621: * This really should be in blkdev_get_by_dev, but right now can't due
1622: * to legacy issues that require us to allow opening a block device node
1623: * writable from userspace even for a read-only block device.
1624: */
1625: if ((mode & BLK_OPEN_WRITE) && bdev_read_only(bdev)) {
1626: bdev_fput(bdev_file);
1627: return -EACCES;
1628: }
1629:
1630: /*
1631: * It is enough to check bdev was not frozen before we set
1632: * s_bdev as freezing will wait until SB_BORN is set.
1633: */
1634: if (atomic_read(&bdev->bd_fsfreeze_count) > 0) {
1635: if (fc)
1636: warnf(fc, "%pg: Can't mount, blockdev is frozen", bdev);
1637: bdev_fput(bdev_file);
1638: return -EBUSY;
1639: }
1640: spin_lock(&sb_lock);
1641: sb->s_bdev_file = bdev_file;
1642: sb->s_bdev = bdev;
1643: sb->s_bdi = bdi_get(bdev->bd_disk->bdi);
1644: if (bdev_stable_writes(bdev))
1645: sb->s_iflags |= SB_I_STABLE_WRITES;
1646: spin_unlock(&sb_lock);
1647:
1648: snprintf(sb->s_id, sizeof(sb->s_id), "%pg", bdev);
1649: shrinker_debugfs_rename(sb->s_shrink, "sb-%s:%s", sb->s_type->name,
1650: sb->s_id);
1651: sb_set_blocksize(sb, block_size(bdev));
1652: return 0;
1653: }
1654: EXPORT_SYMBOL_GPL(setup_bdev_super);
1655:
1656: /**
1657: * get_tree_bdev_flags - Get a superblock based on a single block device
1658: * @fc: The filesystem context holding the parameters
1659: * @fill_super: Helper to initialise a new superblock
]
|
| 56/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 42245
output: 24
thoughts: 1131
Thoughts: **JFS Block Size Handling: A Deep Dive into a Potential Kernel Bug**
Okay, let's see. It appears that the `setup_bdev_super` function initiates this. It calls `sb_set_blocksize` with the block size of the block device. In the case of a 32768 byte block size, `sb_set_blocksize(sb, 32768)` is called. Since 32768 is larger than the page size of 4096, `sb_validate_large_blocksize` kicks in, prints a warning indicating the block size is unsupported and returns `-EINVAL`. Then, somewhat surprisingly, `sb_set_blocksize` returns 0, but crucially, `setup_bdev_super` *ignores* the return value. This leaves `sb->s_blocksize` set to zero!
Then, `fill_super`, in particular `jfs_fill_super`, is called. Here, the filesystem attempts to set the block size again, this time to 4096 with `sb_set_blocksize(sb, PSIZE)`. This then calls `bdev_validate_blocksize`, and in that routine it compares the proposed block size to `bdev_logical_block_size(bdev)`. Since the logical block size is 32768 and we're proposing 4096, the check fails, returning `-EINVAL`. Again, though, `sb_set_blocksize` *succeeds* returning 0. And again, `sb->s_blocksize` remains zero!
This is where things get interesting. The code then proceeds to `jfs_mount`, which in turn calls `chkSuper`. `chkSuper` calls `readSuper`, which then calls `sb_bread`. This results in `__bread_gfp(bdev, 32768, 0, gfp)` being called, since `sb->s_blocksize` is still zero. `__bread_gfp` then ends up calling `bdev_getblk` and eventually, `grow_dev_folio`. The key problem? `folio_alloc_buffers` now sees offset subtracted by zero and calls `folio_set_bh` which then triggers `BUG_ON(offset >= folio_size(folio))` as offset is zero and folio_size isn't, and we crash.
So, it seems we have a kernel bug: a local denial-of-service vulnerability triggered by mounting a JFS filesystem on a block device that has a logical block size larger than the page size (e.g. 32768 bytes). The mounting process is mishandling the block size, which leads to `sb->s_blocksize` being set incorrectly and then a crash down the line.
The immediate question is: can this be triggered by an unprivileged user? Mounting a filesystem typically requires `CAP_SYS_ADMIN` within the initial user namespace. However, the user namespace aspect is critical. I need to verify whether JFS can be mounted within a user namespace. If it *can*, then this becomes a much more serious issue.
|
| 57/2 |
2026/05/30 14:13 |
tool |
grepper |
0m
Error:
Args: map[Expression:FS_USERNS_MOUNT.*jfs]
Results:
|
| 58/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 44104
output: 36
thoughts: 23
Thoughts: Here's a summary of my thought process:
**Diving into the JFS Filesystem Code**
Okay, time to get my hands dirty. I need to understand something related to the JFS filesystem, and my initial instinct is to look at its superblock code. Let's start by checking `jfs_fs_type` within `fs/jfs/super.c`. This is a classic starting point for understanding how the filesystem identifies itself, and likely where its basic registration and initialization take place. Let's see what's defined there and what clues it gives me. I'm expecting to find information about the magic numbers, the supported features, or how it hooks into the VFS layer. This should give me a good jumping-off point.
|
| 59/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:fs/jfs/super.c FirstLine:900 LineCount:50]
Results: map[Contents: 900: unload_nls(ctx->nls_map);
901: kfree(ctx);
902: }
903:
904: static const struct fs_context_operations jfs_context_ops = {
905: .parse_param = jfs_parse_param,
906: .get_tree = jfs_get_tree,
907: .reconfigure = jfs_reconfigure,
908: .free = jfs_free_fc,
909: };
910:
911: static int jfs_init_fs_context(struct fs_context *fc)
912: {
913: struct jfs_context *ctx;
914:
915: ctx = kzalloc_obj(*ctx);
916: if (!ctx)
917: return -ENOMEM;
918:
919: jfs_init_options(fc, ctx);
920:
921: fc->fs_private = ctx;
922: fc->ops = &jfs_context_ops;
923:
924: return 0;
925: }
926:
927: static struct file_system_type jfs_fs_type = {
928: .owner = THIS_MODULE,
929: .name = "jfs",
930: .kill_sb = kill_block_super,
931: .fs_flags = FS_REQUIRES_DEV,
932: .init_fs_context = jfs_init_fs_context,
933: .parameters = jfs_param_spec,
934: };
935: MODULE_ALIAS_FS("jfs");
936:
937: static void init_once(void *foo)
938: {
939: struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo;
940:
941: memset(jfs_ip, 0, sizeof(struct jfs_inode_info));
942: INIT_LIST_HEAD(&jfs_ip->anon_inode_list);
943: init_rwsem(&jfs_ip->rdwrlock);
944: mutex_init(&jfs_ip->commit_mutex);
945: init_rwsem(&jfs_ip->xattr_sem);
946: spin_lock_init(&jfs_ip->ag_lock);
947: jfs_ip->active_ag = -1;
948: inode_init_once(&jfs_ip->vfs_inode);
949: }
]
|
| 60/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 45103
output: 36
thoughts: 350
Thoughts: **Analyzing the JFS and Loop Device Mounting Issue**
Okay, so `jfs_fs_type` doesn't have `FS_USERNS_MOUNT`, which means an unprivileged user in a user namespace can't mount it directly. But wait, can an unprivileged user mount JFS at all? The answer is no, that `FS_USERNS_MOUNT` flag is crucial. I need to keep that in mind.
Now, what about loop devices? Could that be a factor? An unprivileged user *can* create a loop device if they have the necessary device access β `/dev/loop-control` and `/dev/loopX`. However, mounting it still needs `CAP_SYS_ADMIN` in the initial namespace unless `FS_USERNS_MOUNT` is set. So, still no joy there.
Alright, let's look at that bug report... "loop0: detected capacity change... jfs: block size(32768) > page size(4096) not supported." Bingo! It's likely related to mounting a JFS filesystem on a loop device. And the block size of 32768 is a key part.
How is that possible? A loop device with a logical block size of 32768? That's what I need to understand. Ah, the `LOOP_SET_BLOCK_SIZE` ioctl! That's the mechanism. I need to confirm this. Let me check the code in `drivers/block/loop.c` to see how that works.
|
| 61/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:drivers/block/loop.c FirstLine:1200 LineCount:50]
Results: map[Contents:1200: * Therefore, use global lock when setting Lo_rundown state in order to
1201: * make sure that loop_validate_file() will fail if the "struct file"
1202: * which loop_configure()/loop_change_fd() found via fget() was this
1203: * loop device.
1204: */
1205: err = loop_global_lock_killable(lo, true);
1206: if (err)
1207: return err;
1208: if (lo->lo_state != Lo_bound) {
1209: loop_global_unlock(lo, true);
1210: return -ENXIO;
1211: }
1212: /*
1213: * Mark the device for removing the backing device on last close.
1214: * If we are the only opener, also switch the state to roundown here to
1215: * prevent new openers from coming in.
1216: */
1217:
1218: lo->lo_flags |= LO_FLAGS_AUTOCLEAR;
1219: if (disk_openers(lo->lo_disk) == 1)
1220: WRITE_ONCE(lo->lo_state, Lo_rundown);
1221: loop_global_unlock(lo, true);
1222:
1223: return 0;
1224: }
1225:
1226: static int
1227: loop_set_status(struct loop_device *lo, const struct loop_info64 *info)
1228: {
1229: int err;
1230: bool partscan = false;
1231: bool size_changed = false;
1232: unsigned int memflags;
1233:
1234: err = mutex_lock_killable(&lo->lo_mutex);
1235: if (err)
1236: return err;
1237: if (lo->lo_state != Lo_bound) {
1238: err = -ENXIO;
1239: goto out_unlock;
1240: }
1241:
1242: if (lo->lo_offset != info->lo_offset ||
1243: lo->lo_sizelimit != info->lo_sizelimit) {
1244: size_changed = true;
1245: sync_blockdev(lo->lo_device);
1246: invalidate_bdev(lo->lo_device);
1247: }
1248:
1249: /* I/O needs to be drained before changing lo_offset or lo_sizelimit */
]
|
| 62/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 46576
output: 21
thoughts: 14
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing the Search Query: `LOOP_SET_BLOCK_SIZE`**
Okay, here's what I'm thinking. The query `LOOP_SET_BLOCK_SIZE` immediately flags a few key areas in my mind. The prefix "LOOP" suggests this variable or setting is fundamentally tied to iterative processes, most likely within a data processing or algorithmic context. The inclusion of "SET" implies we're dealing with a configurable parameter, not a calculated value. And "BLOCK_SIZE" strongly indicates we're concerned with the granularity of data chunks being handled within the loop.
My initial assumption is this relates to optimizing some form of buffering, I/O, or memory management inside a loop. This likely dictates the amount of data processed per iteration, with the trade-offs being processing latency vs. memory overhead.
Given the naming conventions, this screams a low-level optimization problem. I'm imagining this is probably within a driver, kernel, or very performance-sensitive library. It could also exist as a compile-time constant controlling the block size of operations on a given data structure within a tight inner loop.
Let's begin exploring the search results to find what this constant is used for.
|
| 63/2 |
2026/05/30 14:13 |
tool |
grepper |
0m
Args: map[Expression:LOOP_SET_BLOCK_SIZE]
Results: map[Output:drivers/block/loop.c=1515=static int lo_ioctl(struct block_device *bdev, blk_mode_t mode,
--
drivers/block/loop.c-1561- return loop_get_status64(lo, argp);
drivers/block/loop.c:1562: case LOOP_SET_BLOCK_SIZE:
drivers/block/loop.c-1563- if (!(mode & BLK_OPEN_WRITE) && !capable(CAP_SYS_ADMIN))
--
drivers/block/loop.c=1679=static int lo_compat_ioctl(struct block_device *bdev, blk_mode_t mode,
--
drivers/block/loop.c-1702- case LOOP_CHANGE_FD:
drivers/block/loop.c:1703: case LOOP_SET_BLOCK_SIZE:
drivers/block/loop.c-1704- case LOOP_SET_DIRECT_IO:
--
include/uapi/linux/loop.h=77=struct loop_config {
--
include/uapi/linux/loop.h-112-#define LOOP_SET_DIRECT_IO 0x4C08
include/uapi/linux/loop.h:113:#define LOOP_SET_BLOCK_SIZE 0x4C09
include/uapi/linux/loop.h-114-#define LOOP_CONFIGURE 0x4C0A
]
|
| 64/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 47244
output: 36
thoughts: 28
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Diving into the `loop` driver**
Alright, let's get down to brass tacks. I'm taking a look at the `loop` driver, specifically, I want to find where the `LOOP_SET_BLOCK_SIZE` ioctl is handled. The code's in `drivers/block/loop.c` -- I already know where to look, it's a routine I've worked with before. Line 1562, that's where the action *should* be. I'll need to confirm, of course, but that's my starting point. I anticipate the logic there might be related to adjusting the block size of the loop device. I'm keen to see the details.
|
| 65/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:drivers/block/loop.c FirstLine:1550 LineCount:50]
Results: map[Contents:1550: if ((mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN))
1551: err = loop_set_status_old(lo, argp);
1552: break;
1553: case LOOP_GET_STATUS:
1554: return loop_get_status_old(lo, argp);
1555: case LOOP_SET_STATUS64:
1556: err = -EPERM;
1557: if ((mode & BLK_OPEN_WRITE) || capable(CAP_SYS_ADMIN))
1558: err = loop_set_status64(lo, argp);
1559: break;
1560: case LOOP_GET_STATUS64:
1561: return loop_get_status64(lo, argp);
1562: case LOOP_SET_BLOCK_SIZE:
1563: if (!(mode & BLK_OPEN_WRITE) && !capable(CAP_SYS_ADMIN))
1564: return -EPERM;
1565: return loop_set_block_size(lo, mode, bdev, arg);
1566: case LOOP_SET_CAPACITY:
1567: case LOOP_SET_DIRECT_IO:
1568: if (!(mode & BLK_OPEN_WRITE) && !capable(CAP_SYS_ADMIN))
1569: return -EPERM;
1570: fallthrough;
1571: default:
1572: err = lo_simple_ioctl(lo, cmd, arg);
1573: break;
1574: }
1575:
1576: return err;
1577: }
1578:
1579: #ifdef CONFIG_COMPAT
1580: struct compat_loop_info {
1581: compat_int_t lo_number; /* ioctl r/o */
1582: compat_dev_t lo_device; /* ioctl r/o */
1583: compat_ulong_t lo_inode; /* ioctl r/o */
1584: compat_dev_t lo_rdevice; /* ioctl r/o */
1585: compat_int_t lo_offset;
1586: compat_int_t lo_encrypt_type; /* obsolete, ignored */
1587: compat_int_t lo_encrypt_key_size; /* ioctl w/o */
1588: compat_int_t lo_flags; /* ioctl r/o */
1589: char lo_name[LO_NAME_SIZE];
1590: unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */
1591: compat_ulong_t lo_init[2];
1592: char reserved[4];
1593: };
1594:
1595: /*
1596: * Transfer 32-bit compatibility structure in userspace to 64-bit loop info
1597: * - noinlined to reduce stack space usage in main part of driver
1598: */
1599: static noinline int
]
|
| 66/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 48350
output: 36
thoughts: 32
Thoughts: Okay, here's my interpretation of that.
**Analyzing `loop_set_block_size`**
Alright, let's break down this function: `loop_set_block_size(lo, mode, bdev, arg)`. My first thought is to understand what each of these arguments represents. "lo" likely refers to the loop device itself, that's almost a given. The function is named `loop_set_block_size` so `arg` will contain the new block size - probably expressed in bytes or sectors. `bdev` is interesting; that's probably the underlying block device being affected. And finally `mode` - that sounds like it might indicate *how* the block size change is handled, perhaps flags for read-only vs. read-write, or maybe some more granular access control. So, the overall intention is to change the block size, which is a key attribute of block devices, for a particular loop device connected to some backing block device, and potentially with some specific configuration rules for how that happens. This means it is a potentially critical function, and a change here requires careful consideration to maintain data integrity.
|
| 67/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:drivers/block/loop.c FirstLine:1400 LineCount:50]
Results: map[Contents:1400: if (!err && copy_to_user(arg, &info64, sizeof(info64)))
1401: err = -EFAULT;
1402:
1403: return err;
1404: }
1405:
1406: static int loop_set_capacity(struct loop_device *lo)
1407: {
1408: loff_t size;
1409:
1410: if (unlikely(lo->lo_state != Lo_bound))
1411: return -ENXIO;
1412:
1413: size = lo_calculate_size(lo, lo->lo_backing_file);
1414: loop_set_size(lo, size);
1415:
1416: return 0;
1417: }
1418:
1419: static int loop_set_dio(struct loop_device *lo, unsigned long arg)
1420: {
1421: bool use_dio = !!arg;
1422: unsigned int memflags;
1423:
1424: if (lo->lo_state != Lo_bound)
1425: return -ENXIO;
1426: if (use_dio == !!(lo->lo_flags & LO_FLAGS_DIRECT_IO))
1427: return 0;
1428:
1429: if (use_dio) {
1430: if (!lo_can_use_dio(lo))
1431: return -EINVAL;
1432: /* flush dirty pages before starting to use direct I/O */
1433: vfs_fsync(lo->lo_backing_file, 0);
1434: }
1435:
1436: memflags = blk_mq_freeze_queue(lo->lo_queue);
1437: if (use_dio)
1438: lo->lo_flags |= LO_FLAGS_DIRECT_IO;
1439: else
1440: lo->lo_flags &= ~LO_FLAGS_DIRECT_IO;
1441: blk_mq_unfreeze_queue(lo->lo_queue, memflags);
1442: return 0;
1443: }
1444:
1445: static int loop_set_block_size(struct loop_device *lo, blk_mode_t mode,
1446: struct block_device *bdev, unsigned long arg)
1447: {
1448: struct queue_limits lim;
1449: unsigned int memflags;
]
|
| 68/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 49390
output: 36
thoughts: 15
Thoughts: Okay, let's dive into this. I need to understand the `loop_set_block_size` implementation. I'm going to look at the code and think through how it's designed. My goal here is to determine its functionality and its impact on the system. I will consider the variables it modifies, the parameters it takes, and the control flow within the function. I'll mentally step through different scenarios to ensure I get a comprehensive understanding of the logic. I am also going to think about what assumptions the function is making and what potential pitfalls exist. Are there any edge cases? Any potential for performance bottlenecks or unexpected behavior? I also need to see if this function is crucial to the performance of the system. My experience allows me to anticipate and detect possible issues early. This process should hopefully allow me to deeply understand the implementation.
|
| 69/2 |
2026/05/30 14:13 |
tool |
read-file |
0m
Args: map[File:drivers/block/loop.c FirstLine:1445 LineCount:50]
Results: map[Contents:1445: static int loop_set_block_size(struct loop_device *lo, blk_mode_t mode,
1446: struct block_device *bdev, unsigned long arg)
1447: {
1448: struct queue_limits lim;
1449: unsigned int memflags;
1450: int err = 0;
1451:
1452: /*
1453: * If we don't hold exclusive handle for the device, upgrade to it
1454: * here to avoid changing device under exclusive owner.
1455: */
1456: if (!(mode & BLK_OPEN_EXCL)) {
1457: err = bd_prepare_to_claim(bdev, loop_set_block_size, NULL);
1458: if (err)
1459: return err;
1460: }
1461:
1462: err = mutex_lock_killable(&lo->lo_mutex);
1463: if (err)
1464: goto abort_claim;
1465:
1466: if (lo->lo_state != Lo_bound) {
1467: err = -ENXIO;
1468: goto unlock;
1469: }
1470:
1471: if (lo->lo_queue->limits.logical_block_size == arg)
1472: goto unlock;
1473:
1474: sync_blockdev(lo->lo_device);
1475: invalidate_bdev(lo->lo_device);
1476:
1477: lim = queue_limits_start_update(lo->lo_queue);
1478: loop_update_limits(lo, &lim, arg);
1479:
1480: memflags = blk_mq_freeze_queue(lo->lo_queue);
1481: err = queue_limits_commit_update(lo->lo_queue, &lim);
1482: loop_update_dio(lo);
1483: blk_mq_unfreeze_queue(lo->lo_queue, memflags);
1484:
1485: unlock:
1486: mutex_unlock(&lo->lo_mutex);
1487: abort_claim:
1488: if (!(mode & BLK_OPEN_EXCL))
1489: bd_abort_claiming(bdev, loop_set_block_size);
1490: return err;
1491: }
1492:
1493: static int lo_simple_ioctl(struct loop_device *lo, unsigned int cmd,
1494: unsigned long arg)
]
|
| 70/2 |
2026/05/30 14:13 |
llm |
expert |
0m
Model:
Tokens:
input: 50362
output: 21
thoughts: 1361
Thoughts: **Analyzing the Loop Device Block Size Vulnerability**
Okay, so I'm looking at this `LOOP_SET_BLOCK_SIZE` ioctl in the loop driver. It needs either `BLK_OPEN_WRITE` or `CAP_SYS_ADMIN`, which makes sense. I can't just casually manipulate block sizes without some level of privilege. An unprivileged user opening `/dev/loopX` with `O_RDWR` and calling `LOOP_SET_BLOCK_SIZE` is out, since those devices are typically root-owned and have restrictive permissions, and I don't see any obvious way to escalate permissions. Also, the same is true for the control device. Even user namespaces don't help here because you still can't access `/dev/loopX` unless it's bind-mounted, which, again, doesn't get around the permission issue.
Wait... a malicious filesystem image! That's the key. If an unprivileged user can provide a *malicious* filesystem image, and the system auto-mounts it β say, through udisks2 on a desktop environment β then we've got a potential vector. But, udisks2 normally sets standard block sizes for loop devices. Does it set the block size to the malicious value here?
The bug report mentions the issue being with JFS and block sizes, specifically that "block size(32768) > page size(4096) not supported by filesystem." Bingo! This means the *loop device* itself has a logical block size of 32768. Hmm, so how did *that* happen? Syzkaller? Yep, probably a `ioctl(LOOP_SET_BLOCK_SIZE, 32768)` call.
Now, could a USB device trigger this? USB mass storage devices report their block size via SCSI commands. Yes, SCSI *does* allow a logical block size of up to 32768 or even larger, so a malicious USB device could report this large block size. The kernel would then set the loop device's block size to 32768. If the system *then* tries to auto-mount a JFS filesystem on this "broken" device, boom, we've got a problem. Desktop environments love to probe and automount filesystems, so that's probably what's going on. This is clearly a "Peripheral Trigger" (the USB device) and a "Local Denial of Service" (kernel BUG).
Okay, the specific bug is in `fs/buffer.c:1479`, a `BUG_ON(offset >= folio_size(folio))`. That's a *direct* kernel panic or, at the least, a process kill which can leave locks held and lead to a hang. This *is* a Denial of Service, but it's not directly exploitable for privilege escalation or code execution, as the vulnerability results in a hard crash.
Let me just quickly check `sb_set_blocksize` to be completely sure I understand how the blocksize is set. So, if `set_blocksize` fails, the block size is never set, but the return value is ignored by some filesystems. In JFS, for example, it initializes `sb->s_blocksize` and ignores the return value of the function. Meaning that if the block size set fails, the function does not set the superblock block size. Thus, later calls to things like `sb_bread`, with `sb->s_blocksize` being 0, can lead to trouble. This leads to an infinite loop or `BUG_ON`, so it's a good candidate for our DoS vulnerability.
Now, let me just check other filesystems and see if they have the same issue.
|
| 71/2 |
2026/05/30 14:14 |
tool |
grepper |
0m
Args: map[Expression:sb_set_blocksize\(]
Results: map[Output:Documentation/filesystems/porting.rst=9=New helpers: sb_bread(), sb_getblk(), sb_find_get_block(), set_bh(),
Documentation/filesystems/porting.rst:10:sb_set_blocksize() and sb_min_blocksize().
Documentation/filesystems/porting.rst-11-
--
block/bdev.c=219=static int sb_validate_large_blocksize(struct super_block *sb, int size)
--
block/bdev.c-235-
block/bdev.c:236:int sb_set_blocksize(struct super_block *sb, int size)
block/bdev.c-237-{
--
block/bdev.c=250=int __must_check sb_min_blocksize(struct super_block *sb, int size)
--
block/bdev.c-254- size = minsize;
block/bdev.c:255: return sb_set_blocksize(sb, size);
block/bdev.c-256-}
--
fs/adfs/super.c=254=static int adfs_probe(struct super_block *sb, unsigned int offset, int silent,
--
fs/adfs/super.c-267- if (sb->s_blocksize != blocksize &&
fs/adfs/super.c:268: !sb_set_blocksize(sb, blocksize)) {
fs/adfs/super.c-269- if (!silent)
--
fs/affs/affs.h=231=affs_set_blocksize(struct super_block *sb, int size)
fs/affs/affs.h-232-{
fs/affs/affs.h:233: sb_set_blocksize(sb, size);
fs/affs/affs.h-234-}
--
fs/befs/linuxvfs.c=780=befs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/befs/linuxvfs.c-862- /* Set real blocksize of fs */
fs/befs/linuxvfs.c:863: sb_set_blocksize(sb, (ulong) befs_sb->block_size);
fs/befs/linuxvfs.c-864- sb->s_op = &befs_sops;
--
fs/bfs/inode.c=330=static int bfs_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/bfs/inode.c-348-
fs/bfs/inode.c:349: sb_set_blocksize(s, BFS_BSIZE);
fs/bfs/inode.c-350-
--
fs/efs/super.c=240=static int efs_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/efs/super.c-253- s->s_magic = EFS_SUPER_MAGIC;
fs/efs/super.c:254: if (!sb_set_blocksize(s, EFS_BLOCKSIZE)) {
fs/efs/super.c-255- pr_err("device does not support %d byte blocks\n",
--
fs/erofs/super.c=635=static int erofs_fc_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/erofs/super.c-691- } else {
fs/erofs/super.c:692: if (!sb_set_blocksize(sb, PAGE_SIZE)) {
fs/erofs/super.c-693- errorfc(fc, "failed to set initial blksize");
--
fs/erofs/super.c-713- sb->s_blocksize_bits = sbi->blkszbits;
fs/erofs/super.c:714: } else if (!sb_set_blocksize(sb, 1 << sbi->blkszbits)) {
fs/erofs/super.c-715- errorfc(fc, "failed to set erofs blksize");
--
fs/exfat/super.c=396=static int exfat_calibrate_blocksize(struct super_block *sb, int logical_sect)
--
fs/exfat/super.c-414-
fs/exfat/super.c:415: if (!sb_set_blocksize(sb, logical_sect)) {
fs/exfat/super.c-416- exfat_err(sb, "unable to set blocksize %u",
--
fs/ext2/super.c=878=static int ext2_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/ext2/super.c-1009-
fs/ext2/super.c:1010: if (!sb_set_blocksize(sb, blocksize)) {
fs/ext2/super.c-1011- ext2_msg(sb, KERN_ERR,
--
fs/ext4/super.c=5122=static int ext4_load_super(struct super_block *sb, ext4_fsblk_t *lsb,
--
fs/ext4/super.c-5194- * it won't be freed and its page also. kill_bdev()
fs/ext4/super.c:5195: * is called by sb_set_blocksize().
fs/ext4/super.c-5196- */
--
fs/ext4/super.c-5198- /* Validate the filesystem blocksize */
fs/ext4/super.c:5199: if (!sb_set_blocksize(sb, blocksize)) {
fs/ext4/super.c-5200- ext4_msg(sb, KERN_ERR, "bad block size %d",
--
fs/f2fs/super.c=4946=static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/f2fs/super.c-4997- /* set a block size */
fs/f2fs/super.c:4998: if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) {
fs/f2fs/super.c-4999- f2fs_err(sbi, "unable to set blocksize");
--
fs/fat/inode.c=1538=int fat_fill_super(struct super_block *sb, struct fs_context *fc,
--
fs/fat/inode.c-1638-
fs/fat/inode.c:1639: if (!sb_set_blocksize(sb, logical_sector_size)) {
fs/fat/inode.c-1640- fat_msg(sb, KERN_ERR, "unable to set blocksize %u",
--
fs/freevxfs/vxfs_super.c=184=static int vxfs_fill_super(struct super_block *sbp, struct fs_context *fc)
--
fs/freevxfs/vxfs_super.c-245- j = fs32_to_cpu(infp, rsbp->vs_bsize);
fs/freevxfs/vxfs_super.c:246: if (!sb_set_blocksize(sbp, j)) {
fs/freevxfs/vxfs_super.c-247- warnf(fc, "vxfs: unable to set final block size");
--
fs/fuse/inode.c=1877=int fuse_fill_super_common(struct super_block *sb, struct fuse_fs_context *ctx)
--
fs/fuse/inode.c-1895- err = -EINVAL;
fs/fuse/inode.c:1896: if (!sb_set_blocksize(sb, ctx->blksize))
fs/fuse/inode.c-1897- goto err;
--
fs/gfs2/ops_fstype.c=441=static int init_sb(struct gfs2_sbd *sdp, int silent)
--
fs/gfs2/ops_fstype.c-489- ret = -EINVAL;
fs/gfs2/ops_fstype.c:490: if (!sb_set_blocksize(sb, sdp->sd_sb.sb_bsize))
fs/gfs2/ops_fstype.c-491- goto out;
--
fs/hfs/mdb.c=94=int hfs_mdb_get(struct super_block *sb)
--
fs/hfs/mdb.c-147- brelse(bh);
fs/hfs/mdb.c:148: if (!sb_set_blocksize(sb, size)) {
fs/hfs/mdb.c-149- pr_err("unable to set blocksize to %u\n", size);
--
fs/hfsplus/wrapper.c=134=int hfsplus_read_wrapper(struct super_block *sb)
--
fs/hfsplus/wrapper.c-221-
fs/hfsplus/wrapper.c:222: if (sb_set_blocksize(sb, blocksize) != blocksize) {
fs/hfsplus/wrapper.c-223- pr_err("unable to set blocksize to %u!\n", blocksize);
--
fs/hpfs/super.c=501=static int hpfs_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/hpfs/super.c-525- /*sbi->sb_mounting = 1;*/
fs/hpfs/super.c:526: sb_set_blocksize(s, 512);
fs/hpfs/super.c-527- sbi->sb_fs_size = -1;
--
fs/isofs/inode.c=574=static int isofs_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/isofs/inode.c-820- */
fs/isofs/inode.c:821: sb_set_blocksize(s, orig_zonesize);
fs/isofs/inode.c-822-
--
fs/jfs/super.c=441=static int jfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/jfs/super.c-493- */
fs/jfs/super.c:494: sb_set_blocksize(sb, PSIZE);
fs/jfs/super.c-495-
--
fs/minix/inode.c=221=static int minix_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/minix/inode.c-240-
fs/minix/inode.c:241: if (!sb_set_blocksize(s, BLOCK_SIZE))
fs/minix/inode.c-242- goto out_bad_hblock;
--
fs/minix/inode.c-294- sbi->s_mount_state = MINIX_VALID_FS;
fs/minix/inode.c:295: sb_set_blocksize(s, m3s->s_blocksize);
fs/minix/inode.c-296- s->s_max_links = MINIX2_LINK_MAX;
--
fs/nilfs2/the_nilfs.c=702=int init_nilfs(struct the_nilfs *nilfs, struct super_block *sb)
--
fs/nilfs2/the_nilfs.c-747- nilfs_release_super_block(nilfs);
fs/nilfs2/the_nilfs.c:748: if (!sb_set_blocksize(sb, blocksize)) {
fs/nilfs2/the_nilfs.c-749- nilfs_err(sb, "bad blocksize %d", blocksize);
--
fs/ntfs/super.c=2267=static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/ntfs/super.c-2353- if (vol->sector_size > blocksize) {
fs/ntfs/super.c:2354: blocksize = sb_set_blocksize(sb, vol->sector_size);
fs/ntfs/super.c-2355- if (blocksize != vol->sector_size) {
--
fs/ntfs3/super.c=954=static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,
--
fs/ntfs3/super.c-1176-
fs/ntfs3/super.c:1177: sb_set_blocksize(sb, min_t(u32, sbi->cluster_size, PAGE_SIZE));
fs/ntfs3/super.c-1178-
--
fs/ntfs3/super.c-1227- */
fs/ntfs3/super.c:1228: sb_set_blocksize(sb, block_size);
fs/ntfs3/super.c-1229- hint = "Alternative boot";
--
fs/ocfs2/super.c=1694=static int ocfs2_get_sector(struct super_block *sb,
--
fs/ocfs2/super.c-1698-{
fs/ocfs2/super.c:1699: if (!sb_set_blocksize(sb, sect_size)) {
fs/ocfs2/super.c-1700- mlog(ML_ERROR, "unable to set blocksize\n");
--
fs/omfs/inode.c=456=static int omfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/omfs/inode.c-480-
fs/omfs/inode.c:481: sb_set_blocksize(sb, 0x200);
fs/omfs/inode.c-482-
--
fs/omfs/inode.c-532- */
fs/omfs/inode.c:533: sb_set_blocksize(sb, sbi->s_sys_blocksize);
fs/omfs/inode.c-534-
--
fs/qnx4/inode.c=192=static int qnx4_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/qnx4/inode.c-204-
fs/qnx4/inode.c:205: sb_set_blocksize(s, QNX4_BLOCK_SIZE);
fs/qnx4/inode.c-206-
--
fs/qnx6/inode.c=291=static int qnx6_fill_super(struct super_block *s, struct fs_context *fc)
--
fs/qnx6/inode.c-311- /* Superblock always is 512 Byte long */
fs/qnx6/inode.c:312: if (!sb_set_blocksize(s, QNX6_SUPERBLOCK_SIZE)) {
fs/qnx6/inode.c-313- pr_err("unable to set blocksize\n");
--
fs/qnx6/inode.c-353- /* set new blocksize */
fs/qnx6/inode.c:354: if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
fs/qnx6/inode.c-355- pr_err("unable to set blocksize\n");
--
fs/qnx6/super_mmi.c=36=struct qnx6_super_block *qnx6_mmi_fill_super(struct super_block *s, int silent)
--
fs/qnx6/super_mmi.c-71- /* set new blocksize */
fs/qnx6/super_mmi.c:72: if (!sb_set_blocksize(s, fs32_to_cpu(sbi, sb1->sb_blocksize))) {
fs/qnx6/super_mmi.c-73- pr_err("unable to set blocksize\n");
--
fs/romfs/super.c=450=static int romfs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/romfs/super.c-460- if (!sb->s_mtd) {
fs/romfs/super.c:461: if (!sb_set_blocksize(sb, ROMBSIZE)) {
fs/romfs/super.c-462- errorf(fc, "romfs: unable to set blocksize\n");
--
fs/super.c=1605=int setup_bdev_super(struct super_block *sb, int sb_flags,
--
fs/super.c-1650- sb->s_id);
fs/super.c:1651: sb_set_blocksize(sb, block_size(bdev));
fs/super.c-1652- return 0;
--
fs/udf/super.c=2001=static int udf_load_vrs(struct super_block *sb, struct udf_options *uopt,
--
fs/udf/super.c-2007-
fs/udf/super.c:2008: if (!sb_set_blocksize(sb, uopt->blocksize)) {
fs/udf/super.c-2009- if (!silent)
--
fs/ufs/super.c=716=static int ufs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/ufs/super.c-925-again:
fs/ufs/super.c:926: if (!sb_set_blocksize(sb, block_size)) {
fs/ufs/super.c-927- pr_err("failed to set blocksize\n");
--
fs/zonefs/super.c=1229=static int zonefs_fill_super(struct super_block *sb, struct fs_context *fc)
--
fs/zonefs/super.c-1263- */
fs/zonefs/super.c:1264: sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev));
fs/zonefs/super.c-1265- sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev));
--
include/linux/fs/super.h=225=static inline bool sb_has_encoding(const struct super_block *sb)
--
include/linux/fs/super.h-229-
include/linux/fs/super.h:230:int sb_set_blocksize(struct super_block *sb, int size);
include/linux/fs/super.h-231-int __must_check sb_min_blocksize(struct super_block *sb, int size);
]
|
| 72/2 |
2026/05/30 14:14 |
llm |
expert |
0m
Model:
Tokens:
input: 57446
output: 35
thoughts: 2866
Thoughts: **Analysis of Kernel BUG in JFS (and others) related to `sb_set_blocksize`**
Okay, so I've been digging into this potential vulnerability, and it seems like a pretty nasty one, potentially leading to a Denial of Service. The core issue, as I see it, stems from a lack of error checking after calling `sb_set_blocksize` within several filesystems, most notably JFS, but also BFS, HPFS, OMFS, and ZONEFS. Specifically, `fs/jfs/super.c:494` doesn't check the return value when it calls `sb_set_blocksize(sb, PSIZE)`. This lack of a check allows `sb->s_blocksize` to potentially remain zero, leading to a later crash.
Here's how this happens: The `sb_set_blocksize` function can fail if the device's logical block size is larger than the block size being set (e.g., 4096). This is verified during `bdev_validate_blocksize`, specifically `set_blocksize` within `sb_set_blocksize`. In JFS, after `setup_bdev_super` calls `sb_set_blocksize(sb, block_size(bdev))`, and then `fill_super` calls `sb_set_blocksize(sb, 4096)`, if the block device *reports* a logical block size larger than 4096 (say, 32768, which is perfectly valid for modern drives), the subsequent `sb_set_blocksize` call will fail, but the error is ignored! This leaves `sb->s_blocksize` at zero. This zero value is then later used in `sb_bread` to calculate the block offset in `sb_bread(sb, SUPER1_OFF >> sb->s_blocksize_bits)`, triggering a kernel BUG when trying to allocate buffers with a size of zero (since `sb->s_blocksize_bits` is also zero!).
So, is this exploitable, and how? I've been going through the attack vectors. Mounting JFS requires CAP_SYS_ADMIN, so an unprivileged user can't trigger it directly. A malicious filesystem image alone isn't sufficient *if* it is mounted in the traditional manner via a loop device, because udisks2 or similar will set a standard loop device size which will be successfully set. It requires a larger block device size. The critical thing here is the *block device* characteristics, not the filesystem image itself. The bug is triggered during `jfs_fill_super`, before the filesystem is even fully parsed, so the contents aren't even required to be malicious!
However, the key is the *peripheral*. And here's where it gets interesting: a USB mass storage device *can* report an arbitrary logical block size using SCSI READ CAPACITY commands, so, a malicious USB drive can report a block size of 32768. If a system with automount enabled then tries to mount a JFS filesystem (perhaps by containing a JFS magic number in the MBR or boot sector), this triggers the bug, because `sb->s_blocksize` will not be successfully set to 4096 as the `bdev_logical_block_size` is greater than 4096.
I've determined that a peripheral device with an incorrect block size is the trigger for a DoS. Though the issue *is* technically the block device reporting an invalid size and *not* necessarily the filesystem itself, it's triggered during mount, making it a Malicious Filesystem Trigger as well, since it's the filesystem *mount* that triggers the crash because of the block device's attributes.
I also checked to see if any other conditions can trigger a failure in `sb_set_blocksize`. It ultimately boils down to `bdev_validate_blocksize`, which requires `size < bdev_logical_block_size(bdev)` or a failure in `blk_validate_block_size`, which is trivial to pass. Given that it checks `file->private_data` in `set_blocksize` to prevent a generic file from being opened as a block device.
As far as other filesystems go: BFS, HPFS, OMFS, and ZONEFS are also vulnerable because they *also* fail to check the return value of `sb_set_blocksize`. The same logic and exploit would apply if one of these filesystems are mounted on a block device with a block size > 4096.
|
| 73/2 |
2026/05/30 14:14 |
tool |
read-file |
0m
Args: map[File:fs/bfs/inode.c FirstLine:330 LineCount:50]
Results: map[Contents: 330: static int bfs_fill_super(struct super_block *s, struct fs_context *fc)
331: {
332: struct buffer_head *bh, *sbh;
333: struct bfs_super_block *bfs_sb;
334: struct inode *inode;
335: unsigned i;
336: struct bfs_sb_info *info;
337: int ret = -EINVAL;
338: unsigned long i_sblock, i_eblock, i_eoff, s_size;
339: int silent = fc->sb_flags & SB_SILENT;
340:
341: info = kzalloc_obj(*info);
342: if (!info)
343: return -ENOMEM;
344: mutex_init(&info->bfs_lock);
345: s->s_fs_info = info;
346: s->s_time_min = 0;
347: s->s_time_max = U32_MAX;
348:
349: sb_set_blocksize(s, BFS_BSIZE);
350:
351: sbh = sb_bread(s, 0);
352: if (!sbh)
353: goto out;
354: bfs_sb = (struct bfs_super_block *)sbh->b_data;
355: if (le32_to_cpu(bfs_sb->s_magic) != BFS_MAGIC) {
356: if (!silent)
357: printf("No BFS filesystem on %s (magic=%08x)\n", s->s_id, le32_to_cpu(bfs_sb->s_magic));
358: goto out1;
359: }
360: if (BFS_UNCLEAN(bfs_sb, s) && !silent)
361: printf("%s is unclean, continuing\n", s->s_id);
362:
363: s->s_magic = BFS_MAGIC;
364:
365: if (le32_to_cpu(bfs_sb->s_start) > le32_to_cpu(bfs_sb->s_end) ||
366: le32_to_cpu(bfs_sb->s_start) < sizeof(struct bfs_super_block) + sizeof(struct bfs_dirent)) {
367: printf("Superblock is corrupted on %s\n", s->s_id);
368: goto out1;
369: }
370:
371: info->si_lasti = (le32_to_cpu(bfs_sb->s_start) - BFS_BSIZE) / sizeof(struct bfs_inode) + BFS_ROOT_INO - 1;
372: if (info->si_lasti == BFS_MAX_LASTI)
373: printf("NOTE: filesystem %s was created with 512 inodes, the real maximum is 511, mounting anyway\n", s->s_id);
374: else if (info->si_lasti > BFS_MAX_LASTI) {
375: printf("Impossible last inode number %lu > %d on %s\n", info->si_lasti, BFS_MAX_LASTI, s->s_id);
376: goto out1;
377: }
378: for (i = 0; i < BFS_ROOT_INO; i++)
379: set_bit(i, info->si_imap);
]
|
| 74/2 |
2026/05/30 14:14 |
llm |
expert |
0m
Model:
Tokens:
input: 62319
output: 36
thoughts: 84
Thoughts: Here's my understanding of the situation, tailored for my fellow expert:
**Investigating a Potential Kernel Bug**
Okay, so I'm digging into this BFS issue, and it's looking pretty straightforward. We know that `BFS` calls `sb_bread(s, 0)` immediately after `sb_set_blocksize(s, BFS_BSIZE)`. Now, if that `sb_set_blocksize` function fails, which, of course, can happen, we're going to end up with `sb->s_blocksize` being set to zero. And the crucial thing is that `sb_bread(s, 0)` will *always* trigger that `BUG_ON` condition we're seeing if the block size is zero. Basically, it's the same root cause.
Let's shift focus and make sure this behavior doesn't exist in HPFS too. I need to make sure we understand the scope of this.
|
| 75/2 |
2026/05/30 14:14 |
tool |
read-file |
0m
Args: map[File:fs/hpfs/super.c FirstLine:520 LineCount:50]
Results: map[Contents: 520: s->s_fs_info = sbi;
521:
522: mutex_init(&sbi->hpfs_mutex);
523: hpfs_lock(s);
524:
525: /*sbi->sb_mounting = 1;*/
526: sb_set_blocksize(s, 512);
527: sbi->sb_fs_size = -1;
528: if (!(bootblock = hpfs_map_sector(s, 0, &bh0, 0))) goto bail1;
529: if (!(superblock = hpfs_map_sector(s, 16, &bh1, 1))) goto bail2;
530: if (!(spareblock = hpfs_map_sector(s, 17, &bh2, 0))) goto bail3;
531:
532: /* Check magics */
533: if (/*le16_to_cpu(bootblock->magic) != BB_MAGIC
534: ||*/ le32_to_cpu(superblock->magic) != SB_MAGIC
535: || le32_to_cpu(spareblock->magic) != SP_MAGIC) {
536: if (!silent)
537: pr_err("Bad magic ... probably not HPFS\n");
538: goto bail4;
539: }
540:
541: /* Check version */
542: if (!sb_rdonly(s) && superblock->funcversion != 2 && superblock->funcversion != 3) {
543: pr_err("Bad version %d,%d. Mount readonly to go around\n",
544: (int)superblock->version, (int)superblock->funcversion);
545: pr_err("please try recent version of HPFS driver at http://artax.karlin.mff.cuni.cz/~mikulas/vyplody/hpfs/index-e.cgi and if it still can't understand this format, contact author - mikulas@artax.karlin.mff.cuni.cz\n");
546: goto bail4;
547: }
548:
549: s->s_flags |= SB_NOATIME;
550:
551: /* Fill superblock stuff */
552: s->s_magic = HPFS_SUPER_MAGIC;
553: s->s_op = &hpfs_sops;
554: set_default_d_op(s, &hpfs_dentry_operations);
555: s->s_time_min = local_to_gmt(s, 0);
556: s->s_time_max = local_to_gmt(s, U32_MAX);
557:
558: sbi->sb_root = le32_to_cpu(superblock->root);
559: sbi->sb_fs_size = le32_to_cpu(superblock->n_sectors);
560: sbi->sb_bitmaps = le32_to_cpu(superblock->bitmaps);
561: sbi->sb_dirband_start = le32_to_cpu(superblock->dir_band_start);
562: sbi->sb_dirband_size = le32_to_cpu(superblock->n_dir_band);
563: sbi->sb_dmap = le32_to_cpu(superblock->dir_band_bitmap);
564: sbi->sb_uid = ctx->uid;
565: sbi->sb_gid = ctx->gid;
566: sbi->sb_mode = 0777 & ~ctx->umask;
567: sbi->sb_n_free = -1;
568: sbi->sb_n_free_dnodes = -1;
569: sbi->sb_lowercase = ctx->lowercase;
]
|
| 76/2 |
2026/05/30 14:14 |
llm |
expert |
0m
Model:
Tokens:
input: 63720
output: 36
thoughts: 34
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating Potential Sector Read Vulnerabilities in HPFS and OMFS**
Right, let's see. `hpfs_map_sector` is calling `sb_bread`. Immediately, that raises a red flag. If `hpfs_map_sector` is relying on `sb_bread` for sector reads, then we're staring down the barrel of the same potential `BUG_ON` vulnerability that we've been discussing elsewhere. This means HPFS is also susceptible to whatever issue triggered that safeguard. We really need to check the exact circumstances to see the same bug occurs.
Now, that brings up another question, though. What about the other file systems? OMFS, specifically, comes to mind. Are there similar functions at play in OMFS that might also be using `sb_bread`? It is likely OMFS is also vulnerable, but we must check. It's time to dig into the OMFS code and see if there are parallel functions that could expose similar vulnerabilities. This is an area that must be addressed, lest it become exploitable.
|
| 77/2 |
2026/05/30 14:14 |
tool |
read-file |
0m
Args: map[File:fs/omfs/inode.c FirstLine:480 LineCount:50]
Results: map[Contents: 480:
481: sb_set_blocksize(sb, 0x200);
482:
483: bh = sb_bread(sb, 0);
484: if (!bh)
485: goto end;
486:
487: omfs_sb = (struct omfs_super_block *)bh->b_data;
488:
489: if (omfs_sb->s_magic != cpu_to_be32(OMFS_MAGIC)) {
490: if (!silent)
491: printk(KERN_ERR "omfs: Invalid superblock (%x)\n",
492: omfs_sb->s_magic);
493: goto out_brelse_bh;
494: }
495: sb->s_magic = OMFS_MAGIC;
496:
497: sbi->s_num_blocks = be64_to_cpu(omfs_sb->s_num_blocks);
498: sbi->s_blocksize = be32_to_cpu(omfs_sb->s_blocksize);
499: sbi->s_mirrors = be32_to_cpu(omfs_sb->s_mirrors);
500: sbi->s_root_ino = be64_to_cpu(omfs_sb->s_root_block);
501: sbi->s_sys_blocksize = be32_to_cpu(omfs_sb->s_sys_blocksize);
502: mutex_init(&sbi->s_bitmap_lock);
503:
504: if (sbi->s_num_blocks > OMFS_MAX_BLOCKS) {
505: printk(KERN_ERR "omfs: sysblock number (%llx) is out of range\n",
506: (unsigned long long)sbi->s_num_blocks);
507: goto out_brelse_bh;
508: }
509:
510: if (sbi->s_sys_blocksize > PAGE_SIZE) {
511: printk(KERN_ERR "omfs: sysblock size (%d) is out of range\n",
512: sbi->s_sys_blocksize);
513: goto out_brelse_bh;
514: }
515:
516: if (sbi->s_sys_blocksize < OMFS_DIR_START) {
517: printk(KERN_ERR "omfs: sysblock size (%d) is too small\n",
518: sbi->s_sys_blocksize);
519: goto out_brelse_bh;
520: }
521:
522: if (sbi->s_blocksize < sbi->s_sys_blocksize ||
523: sbi->s_blocksize > OMFS_MAX_BLOCK_SIZE) {
524: printk(KERN_ERR "omfs: block size (%d) is out of range\n",
525: sbi->s_blocksize);
526: goto out_brelse_bh;
527: }
528:
529: /*
]
|
| 78/2 |
2026/05/30 14:14 |
llm |
expert |
0m
Model:
Tokens:
input: 64945
output: 37
thoughts: 42
Thoughts: Okay, here's my take on those thoughts, framed as an expert's inner monologue:
**Investigating Block Size and Buffer Cache Interactions in File Systems**
Alright, so I'm seeing this pattern... with OMFS, it's clear: they immediately call `sb_bread(sb, 0)` after setting the block size to 0x200 with `sb_set_blocksize(sb, 0x200)`. Interesting. That initial read after block size configuration is a pretty standard setup, but the 0 block is unusual. I need to understand why they're doing that so quickly. Is this to prime the buffer cache with the superblock, or perhaps some critical metadata needed right at mount? Or, is there an initialization issue or an optimization being attempted? I should trace that `sb_bread` call and see what exactly it retrieves.
Now, I need to expand my search. How does this compare to other filesystems? What about ZONEFS? Is it doing something similar with the initial block read after block size changes? I'm curious if they have a similar approach, and if so, how they handle the potential impact on the buffer cache. It's a good comparison point for seeing what techniques OMFS has put to use. That's my next avenue of investigation.
|
| 79/2 |
2026/05/30 14:15 |
tool |
read-file |
0m
Args: map[File:fs/zonefs/super.c FirstLine:1260 LineCount:50]
Results: map[Contents:1260: * The block size is set to the device zone write granularity to ensure
1261: * that write operations are always aligned according to the device
1262: * interface constraints.
1263: */
1264: sb_set_blocksize(sb, bdev_zone_write_granularity(sb->s_bdev));
1265: sbi->s_zone_sectors_shift = ilog2(bdev_zone_sectors(sb->s_bdev));
1266: sbi->s_uid = GLOBAL_ROOT_UID;
1267: sbi->s_gid = GLOBAL_ROOT_GID;
1268: sbi->s_perm = 0640;
1269: sbi->s_mount_opts = ctx->s_mount_opts;
1270:
1271: atomic_set(&sbi->s_wro_seq_files, 0);
1272: sbi->s_max_wro_seq_files = bdev_max_open_zones(sb->s_bdev);
1273: atomic_set(&sbi->s_active_seq_files, 0);
1274: sbi->s_max_active_seq_files = bdev_max_active_zones(sb->s_bdev);
1275:
1276: ret = zonefs_read_super(sb);
1277: if (ret)
1278: return ret;
1279:
1280: zonefs_info(sb, "Mounting %u zones", bdev_nr_zones(sb->s_bdev));
1281:
1282: if (!sbi->s_max_wro_seq_files &&
1283: !sbi->s_max_active_seq_files &&
1284: sbi->s_mount_opts & ZONEFS_MNTOPT_EXPLICIT_OPEN) {
1285: zonefs_info(sb,
1286: "No open and active zone limits. Ignoring explicit_open mount option\n");
1287: sbi->s_mount_opts &= ~ZONEFS_MNTOPT_EXPLICIT_OPEN;
1288: }
1289:
1290: /* Initialize the zone groups */
1291: ret = zonefs_init_zgroups(sb);
1292: if (ret)
1293: goto cleanup;
1294:
1295: /* Create the root directory inode */
1296: ret = -ENOMEM;
1297: inode = new_inode(sb);
1298: if (!inode)
1299: goto cleanup;
1300:
1301: inode->i_ino = bdev_nr_zones(sb->s_bdev);
1302: inode->i_mode = S_IFDIR | 0555;
1303: simple_inode_init_ts(inode);
1304: inode->i_op = &zonefs_dir_inode_operations;
1305: inode->i_fop = &zonefs_dir_operations;
1306: inode->i_size = 2;
1307: set_nlink(inode, 2);
1308: for (ztype = 0; ztype < ZONEFS_ZTYPE_MAX; ztype++) {
1309: if (sbi->s_zgroup[ztype].g_nr_zones) {
]
|
| 80/2 |
2026/05/30 14:15 |
llm |
expert |
0m
Model:
Tokens:
input: 66245
output: 66
thoughts: 681
Thoughts: **My Analysis of the Filesystem Block Size Bug**
Okay, so looking into this `BUG_ON` issue, it appears ZONEFS is off the hook β it doesn't even use `sb_bread`, instead using `zonefs_read_super`, implying direct block layer interaction or something similar. Interesting.
So, JFS, BFS, HPFS, and OMFS are the vulnerable parties, susceptible to this `BUG_ON` if they're mounted on a block device with a logical block size exceeding their capabilities. This isnβt new; syzkaller picked it up. The fix is pretty straightforward: check the return value of `sb_set_blocksize` and bail out with an error if it fails. That should prevent the kernel panic.
Let's break this down:
* **Exploitable?** No, in the traditional sense. It's a `BUG_ON` in `folio_set_bh` due to an offset issue. It results in a kernel crash, a Denial of Service. No memory corruption, no code execution, at least not directly.
* **Denial of Service?** Absolutely. The `BUG_ON` causes a kernel crash, or at least a crash of the current process, which can lead to system instability, potential lock issues.
* **Privilege Required?** Mounting these filesystems requires `CAP_SYS_ADMIN` in the initial user namespace, so unprivileged users are blocked.
* **User Namespaces?** Nope. These filesystems lack the `FS_USERNS_MOUNT` flag, so user namespaces are a dead end.
* **VM/Network Triggers?** No on those fronts.
* **Peripheral Trigger?** Yes. A malicious USB mass storage device could report a large logical block size (like 32KB) via SCSI commands, triggering the bug during auto-mount.
* **Malicious Filesystem Trigger?** Yes, because the bug hits during the *mount* process itself when encountering such a device with a large logical block size. The filesystem image doesn't need to be actively malicious, simply being on this media, or auto-mounted, will trigger the issue. Think downloaded image, external media.
Now, let me double-check: is there any way for an unprivileged user to get around the peripheral restriction? What about `udisksctl loop-setup`? Seems like it does allow unprivileged setup of loop devices for filesystem images, but it won't let you set the logical block size. It uses a default (512 or 4096). Since `sb_set_blocksize(sb, 4096)` will succeed in either of those cases (because 4096 >= 512 and 4096 >= 4096), the bug won't be triggered.
So, it's strictly a Peripheral Trigger, or you need root to set up a loop device with a huge block size. Iβm comfortable calling it there. Time to set the results.
|
| 81/2 |
2026/05/30 14:15 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 82/2 |
2026/05/30 14:15 |
llm |
expert |
0m
Model:
Tokens:
input: 67708
output: 683
thoughts: 608
Thoughts: **My Analysis of the JFS Filesystem Vulnerability**
Okay, the analysis is complete, and it's time to craft the final response. Let me recap my thought process. The issue stems from a flawed interaction within the JFS filesystem, and others like BFS, HPFS, and OMFS. During the `fill_super` process, `sb_set_blocksize(sb, PSIZE)` is called, but there's a critical oversight: the code fails to check the return value of this function.
Here's the problem. If the underlying block device has a *larger* logical block size than `PSIZE`βlet's say 32KBβ`sb_set_blocksize` *fails*. It returns 0, leaving the superblock's `sb->s_blocksize` at 0. This is the crux of the matter.
Later, when JFS attempts to read the superblock using `sb_bread`, it uses this incorrect `sb->s_blocksize`. It uses 0 for `sb->s_blocksize_bits` to compute block number, and 0 for `sb->s_blocksize` as the size. This results in a call to `__bread_gfp` with a size of 0.
The block layer, specifically `__getblk_slow`, accepts this 0 size because of the `IS_ALIGNED(0, ...)` check. It then proceeds to call `folio_alloc_buffers` with this same 0 size, leading to the crucial infinite loop: `while ((offset -= size) >= 0)`. Because `size` is 0, `offset` *never* decreases and stays equal to `folio_size(folio)`. The code then calls `folio_set_bh(bh, folio, offset)`, which *triggers* the `BUG_ON(offset >= folio_size(folio))` assertion. This assertion failure, in turn, causes a kernel panic.
Now, as an expert, I know the impact is quite specific. It's not exploitable in the classic sense. The bug leads to a deterministic `BUG_ON`, not memory corruption or use-after-free conditions. It halts the execution thread, making it a Denial of Service vulnerability. Although the panic can be avoided by turning the panic-on-oops setting off, it may leave processes in a hung/deadlocked state.
The attack vector is interesting. Mounting JFS requires `CAP_SYS_ADMIN`, and it doesn't support user namespaces. So, unprivileged users are out. But the crucial part is the *peripheral* or malicious filesystem trigger. A crafted USB device reporting a large logical block size, triggered by something as simple as automatic mounting in desktop environments like GNOME or KDE, could cause a kernel panic. This makes it a viable attack vector via physical access. Essentially, this allows an attacker with physical access to a machine to crash the system through an auto-mounting malicious device. That's a serious practical concern.
|
| 83/1 |
2026/05/30 14:15 |
action |
format-explanation |
0m
Results: map[Explanation:**Root Cause Analysis**
The bug is caused by the JFS filesystem (and a few others like BFS, HPFS, OMFS)
failing to check the return value of `sb_set_blocksize()` during the mount
process (`jfs_fill_super`).
When a block device has a logical block size larger than the size JFS attempts
to set (e.g., the device has a 32768-byte logical block size, but JFS tries to
set it to `PSIZE` which is 4096 bytes), `sb_set_blocksize()` fails and returns
`0`. Because JFS ignores this return value, `sb->s_blocksize` remains `0`.
Subsequently, JFS attempts to read the superblock using `sb_bread()`. Since
`sb->s_blocksize` and `sb->s_blocksize_bits` are `0`, this results in a call to
the block layer (`__bread_gfp`) with a requested read `size` of `0`. The block
layer accepts `size = 0` (as `0` is technically aligned to any logical block
size) and proceeds to allocate buffers via `folio_alloc_buffers(folio, size=0,
...)`.
Inside `folio_alloc_buffers()`, the loop `while ((offset -= size) >= 0)`
subtracts `0` from `offset`, leaving `offset` equal to the folio size. It then
calls `folio_set_bh(bh, folio, offset)`, which immediately hits the
`BUG_ON(offset >= folio_size(folio))` assertion, crashing the kernel.
**Security Impact Assessment**
* **Exploitable:** No. The bug triggers a deterministic `BUG_ON` assertion
failure. It does not cause memory corruption, out-of-bounds accesses, or
use-after-free conditions. It cannot be leveraged for privilege escalation or
arbitrary code execution.
* **Denial Of Service:** Yes. The `BUG_ON` will cause a kernel panic (if
`panic_on_oops` is enabled) or kill the mounting process while leaving critical
VFS/block layer locks held, inevitably leading to a system deadlock or crash.
* **Accessible From Unprivileged Processes & User Namespaces:** No. Mounting the
JFS filesystem requires `CAP_SYS_ADMIN` in the initial user namespace. JFS does
not have the `FS_USERNS_MOUNT` flag, meaning it cannot be mounted by
unprivileged users even within a new user namespace. Furthermore, unprivileged
users cannot configure loop devices with custom logical block sizes (which
requires `BLK_OPEN_WRITE` or `CAP_SYS_ADMIN` on `/dev/loopX`).
* **Peripheral & Malicious Filesystem Trigger:** Yes. A malicious USB mass
storage device can be engineered to report an unusually large logical block size
(e.g., 32768 bytes) via SCSI `READ CAPACITY` commands. If a modern Linux desktop
environment (e.g., GNOME, KDE via `udisks2`) detects the JFS magic number and
attempts to auto-mount the plugged-in device, the bug will be triggered
automatically without any user interaction, resulting in an immediate Denial of
Service.]
|