| 0/0 |
2026/09/04 06:51 |
flow |
assessment-security |
48m
Results: map[DenialOfService:true Explanation:**Exploitable:** No
The bug is a `BUG()` macro invocation in `jffs2_sum_write_sumnode()` which is
triggered when the JFFS2 summary information is empty (`!c->summary->sum_num ||
!c->summary->sum_list_head`). Hitting a `BUG()` macro immediately halts the
kernel (or the current task, depending on configuration, but typically panics in
this context). It does not cause memory corruption, use-after-free, or
information leaks, so it cannot be exploited for privilege escalation or
arbitrary code execution.
**Denial of Service:** Yes
Because the bug triggers a `BUG()` macro, it will crash the kernel, resulting in
a complete system Denial of Service (DoS).
**Accessible From Unprivileged Processes:** Yes
The crash is triggered during a standard file write operation
(`generic_perform_write` -> `jffs2_write_end` -> `jffs2_reserve_space` ->
garbage collection). Any unprivileged user with write access to a file on a
JFFS2 filesystem can potentially trigger this bug by writing data that forces
the filesystem into garbage collection under specific conditions.
**Accessible From User Namespaces:** Yes
Since it only requires standard filesystem write access, it is accessible from
within a user namespace, provided the user has access to a mounted JFFS2
filesystem.
**VM Guest Trigger:** No
This is a filesystem-level bug and does not involve KVM guest-to-host escapes or
paravirtualized devices.
**VM Host Trigger in The Confidential Computing Context:** No
This is a filesystem-level bug and does not involve host-to-guest attacks in
confidential computing.
**Ethernet Network Trigger:** No
The bug is in the JFFS2 filesystem and is not reachable via network packet
processing.
**Other Remote Trigger:** No
The bug is not reachable via other remote protocols (Bluetooth, WiFi, etc.).
**Peripheral Trigger:** No
The bug is not triggered by plugging in a malicious peripheral device (unless
the device contains a malicious JFFS2 image that is auto-mounted).
**Malicious Filesystem Trigger:** Yes
The bug can be triggered by mounting a maliciously crafted JFFS2 filesystem
image and interacting with it (e.g., writing to it), which forces the filesystem
into the inconsistent state that triggers the `BUG()`. Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/09/04 06:51 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/09/04 06:51 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/297d41c12fba07000f4cde269f3580a719860dd9]
|
| 3/1 |
2026/09/04 06:53 |
action |
kernel-builder |
24m
Results: map[KernelObj:/app/workdir/cache/build/5645977bc23f679792a3f47a74872e7a45c95979]
|
| 4/1 |
2026/09/04 07:17 |
action |
codesearch-prepare |
17m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/09/04 07:35 |
agent |
expert |
4m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
jffs2: warning: (10801) jffs2_sum_write_sumnode: Empty summary info!!!
------------[ cut here ]------------
------------[ cut here ]------------
kernel BUG at fs/jffs2/summary.c:868!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
CPU: 0 UID: 0 PID: 10801 Comm: syz.9.661 Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/05/2026
RIP: 0010:jffs2_sum_write_sumnode.cold+0x4e/0x174 fs/jffs2/summary.c:868
Code: 0f b6 04 02 84 c0 74 08 3c 03 0f 8e 2c 01 00 00 8b b3 40 06 00 00 48 c7 c2 00 76 33 8c 48 c7 c7 00 72 33 8c e8 cd 73 f8 ff 90 <0f> 0b e8 45 f9 e1 00 65 4c 8b 3d 65 1a 62 13 b8 ff ff 37 00 48 c1
RSP: 0018:ffffc90003a56d90 EFLAGS: 00010282
RAX: 0000000000000046 RBX: ffff8880375f8000 RCX: 0000000000000000
RDX: 0000000000000046 RSI: ffffffff81e9c5d9 RDI: fffff5200074ada3
RBP: ffffc90003a56f10 R08: 0000000000000007 R09: 0000000000000000
R10: 8000000000000000 R11: 0000000000000001 R12: ffff88807e062a00
R13: 0000000000000000 R14: 0000000000000f40 R15: 0000000000000000
FS: 00007f34bbf8d6c0(0000) GS:ffff888123b61000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000557616249078 CR3: 0000000074bae000 CR4: 0000000000350ef0
Call Trace:
<TASK>
jffs2_do_reserve_space+0xb94/0xf70 fs/jffs2/nodemgmt.c:392
jffs2_reserve_space_gc+0x6b/0xf0 fs/jffs2/nodemgmt.c:226
jffs2_garbage_collect_pristine+0x103/0x870 fs/jffs2/gc.c:613
jffs2_garbage_collect_live+0x1471/0x36b0 fs/jffs2/gc.c:546
jffs2_garbage_collect_pass+0xb28/0x1b40 fs/jffs2/gc.c:464
jffs2_reserve_space+0x489/0xbb0 fs/jffs2/nodemgmt.c:171
jffs2_write_inode_range+0x275/0xb80 fs/jffs2/write.c:362
jffs2_write_end+0x72c/0xea0 fs/jffs2/file.c:299
generic_perform_write+0x513/0xa40 mm/filemap.c:4395
__generic_file_write_iter+0x1f7/0x240 mm/filemap.c:4491
generic_file_write_iter+0xe1/0x390 mm/filemap.c:4517
iter_file_splice_write+0x830/0x10b0 fs/splice.c:736
do_splice_from fs/splice.c:936 [inline]
direct_splice_actor+0x192/0x690 fs/splice.c:1159
splice_direct_to_actor+0x345/0xa30 fs/splice.c:1103
do_splice_direct_actor fs/splice.c:1202 [inline]
do_splice_direct+0x174/0x240 fs/splice.c:1228
do_sendfile+0xadc/0xe20 fs/read_write.c:1371
__do_sys_sendfile64 fs/read_write.c:1432 [inline]
__se_sys_sendfile64 fs/read_write.c:1418 [inline]
__x64_sys_sendfile64+0x1d8/0x220 fs/read_write.c:1418
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x123/0x790 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f34bb19e159
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:00007f34bbf8d028 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
RAX: ffffffffffffffda RBX: 00007f34bb426090 RCX: 00007f34bb19e159
RDX: 0000000000000000 RSI: 0000000000000008 RDI: 0000000000000009
RBP: 00007f34bb235024 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000020000 R11: 0000000000000246 R12: 0000000000000000
R13: 00007f34bb426128 R14: 00007f34bb426090 R15: 00007ffc4299d258
</TASK>
Modules linked in:
---[ end trace 0000000000000000 ]---
RIP: 0010:jffs2_sum_write_sumnode.cold+0x4e/0x174 fs/jffs2/summary.c:868
Code: 0f b6 04 02 84 c0 74 08 3c 03 0f 8e 2c 01 00 00 8b b3 40 06 00 00 48 c7 c2 00 76 33 8c 48 c7 c7 00 72 33 8c e8 cd 73 f8 ff 90 <0f> 0b e8 45 f9 e1 00 65 4c 8b 3d 65 1a 62 13 b8 ff ff 37 00 48 c1
RSP: 0018:ffffc90003a56d90 EFLAGS: 00010282
RAX: 0000000000000046 RBX: ffff8880375f8000 RCX: 0000000000000000
RDX: 0000000000000046 RSI: ffffffff81e9c5d9 RDI: fffff5200074ada3
RBP: ffffc90003a56f10 R08: 0000000000000007 R09: 0000000000000000
R10: 8000000000000000 R11: 0000000000000001 R12: ffff88807e062a00
R13: 0000000000000000 R14: 0000000000000f40 R15: 0000000000000000
FS: 00007f34bbf8d6c0(0000) GS:ffff888123c61000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fe398fd0000 CR3: 0000000074bae000 CR4: 0000000000350ef0
Reply: **Exploitable:** No
The bug is a `BUG()` macro invocation in `jffs2_sum_write_sumnode()` which is triggered when the JFFS2 summary information is empty (`!c->summary->sum_num || !c->summary->sum_list_head`). Hitting a `BUG()` macro immediately halts the kernel (or the current task, depending on configuration, but typically panics in this context). It does not cause memory corruption, use-after-free, or information leaks, so it cannot be exploited for privilege escalation or arbitrary code execution.
**Denial of Service:** Yes
Because the bug triggers a `BUG()` macro, it will crash the kernel, resulting in a complete system Denial of Service (DoS).
**Accessible From Unprivileged Processes:** Yes
The crash is triggered during a standard file write operation (`generic_perform_write` -> `jffs2_write_end` -> `jffs2_reserve_space` -> garbage collection). Any unprivileged user with write access to a file on a JFFS2 filesystem can potentially trigger this bug by writing data that forces the filesystem into garbage collection under specific conditions.
**Accessible From User Namespaces:** Yes
Since it only requires standard filesystem write access, it is accessible from within a user namespace, provided the user has access to a mounted JFFS2 filesystem.
**VM Guest Trigger:** No
This is a filesystem-level bug and does not involve KVM guest-to-host escapes or paravirtualized devices.
**VM Host Trigger in The Confidential Computing Context:** No
This is a filesystem-level bug and does not involve host-to-guest attacks in confidential computing.
**Ethernet Network Trigger:** No
The bug is in the JFFS2 filesystem and is not reachable via network packet processing.
**Other Remote Trigger:** No
The bug is not reachable via other remote protocols (Bluetooth, WiFi, etc.).
**Peripheral Trigger:** No
The bug is not triggered by plugging in a malicious peripheral device (unless the device contains a malicious JFFS2 image that is auto-mounted).
**Malicious Filesystem Trigger:** Yes
The bug can be triggered by mounting a maliciously crafted JFFS2 filesystem image and interacting with it (e.g., writing to it), which forces the filesystem into the inconsistent state that triggers the `BUG()`.
|
| 6/2 |
2026/09/04 07:35 |
llm |
expert |
0m
Model:
Tokens:
input: 8766
output: 38
thoughts: 107
Thoughts: **Investigating a JFFS2 Filesystem Bug**
Okay, so I've got a kernel BUG, and it's pointing me directly to `fs/jffs2/summary.c:868`. That's a good starting point, at least. The function implicated is `jffs2_sum_write_sumnode`. Now, the warning right before the BUG is interesting: "jffs2: warning: (10801) jffs2_sum_write_sumnode: Empty summary info!!!" Empty summary info⦠hmm, that suggests a data consistency problem, potentially where the summary node creation is failing to populate the expected metadata. Time to dive into that specific section of `fs/jffs2/summary.c` and see what's going on around line 868. I need to understand why `jffs2_sum_write_sumnode` is being called with what seems to be invalid, or maybe absent, summary information. This is likely related to how the summary node is being constructed, how it's being populated, and whether any checks for validity are present or missing. My first step is to trace the execution flow leading up to that line, examining any conditional logic that might be triggering this scenario.
|
| 7/2 |
2026/09/04 07:35 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:850 LineCount:50]
Results: map[Contents: 850: __must_hold(&c->erase_completion_block)
851: {
852: int datasize, infosize, padsize;
853: struct jffs2_eraseblock *jeb;
854: int ret = 0;
855:
856: dbg_summary("called\n");
857:
858: spin_unlock(&c->erase_completion_lock);
859:
860: jeb = c->nextblock;
861: ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
862:
863: if (ret)
864: goto out;
865:
866: if (!c->summary->sum_num || !c->summary->sum_list_head) {
867: JFFS2_WARNING("Empty summary info!!!\n");
868: BUG();
869: }
870:
871: datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
872: infosize = sizeof(struct jffs2_raw_summary) + datasize;
873: padsize = jeb->free_size - infosize;
874: infosize += padsize;
875: datasize += padsize;
876:
877: ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
878:
879: out:
880: spin_lock(&c->erase_completion_lock);
881: return ret;
882: }
]
|
| 8/2 |
2026/09/04 07:35 |
llm |
expert |
0m
Model:
Tokens:
input: 9679
output: 34
thoughts: 422
Thoughts: **My Analysis of the JFFS2 Bug**
Okay, so I've got this bug report, and it looks like a `BUG()` call within `jffs2_sum_write_sumnode` is being triggered. The key is that `c->summary` is empty, or at least `!c->summary->sum_num || !c->summary->sum_list_head`. Essentially, we're trying to write a summary node when there's no summary data. Obviously, that's a problem.
First thought: is this a potential exploit? No, not directly. It's a `BUG()` macro, so it's a kernel panic, a denial of service. It's not memory corruption; so, no memory corruption = not easily exploitable for code execution. It's just going to kill the kernel.
Now, can an unprivileged user trigger this? That's the important question. Since JFFS2 is a filesystem, the answer depends on access. I need to figure out the context of the panic. The stack trace is what I was looking for. The trace shows a write path: `sendfile` -> `generic_perform_write` -> `jffs2_write_end` -> `jffs2_write_inode_range` -> `jffs2_reserve_space` -> `jffs2_garbage_collect_pass` -> `jffs2_garbage_collect_live` -> `jffs2_garbage_collect_pristine` -> `jffs2_reserve_space_gc` -> `jffs2_do_reserve_space` -> `jffs2_sum_write_sumnode`. This is a garbage collection path, triggered by writing to a file on a JFFS2 filesystem.
Bingo! If an unprivileged user has *write* access to a file on a JFFS2 filesystem, they can trigger this by making changes which trigger garbage collection. But, JFFS2 is a flash filesystem and I'll need to know if the target permits unprivileged users to mount JFFS2 to confirm this.
|
| 9/2 |
2026/09/04 07:35 |
tool |
grepper |
0m
Error:
Args: map[Expression:FS_USERNS_MOUNT PathPrefix:fs/jffs2/]
Results:
|
| 10/2 |
2026/09/04 07:35 |
llm |
expert |
0m
Model:
Tokens:
input: 10615
output: 41
thoughts: 224
Thoughts: **My Analysis of the JFFS2 Vulnerability**
Okay, so I'm looking at this JFFS2 bug and my initial thought is, "Right, no `FS_USERNS_MOUNT`, so a regular user can't just slap this onto a user namespace. That's good security practice." But wait, it's more nuanced than that. The problem lies in the fact that if root has already mounted a JFFS2 file system and an unprivileged user has write access to a file or directory on it, then boom β they can trigger the bug. Apparently, garbage collection is the key β writing to that file sets off the chain reaction.
So, it's *accessible* from unprivileged processes. That's the important takeaway. Now, the bug report mentions "Malicious Filesystem Trigger". Does that mean I need a carefully crafted, evil image to exploit it? Actually, it seems that's right. If the image is crafted carefully to cause the empty summary info during garbage collection, then it's vulnerable.
But the question comes back, does it require a malicious image or can this occur on a normal JFFS2 filesystem? I have to go deeper. Let's dig into the details and find out *why* `c->summary->sum_num` might be zero. Ah, yes, looking deeper into the details, `jffs2_sum_write_sumnode` is called from `jffs2_do_reserve_space`. That's where the critical piece of the puzzle lies, and where my focus needs to be to understand this fully.
|
| 11/2 |
2026/09/04 07:35 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/nodemgmt.c FirstLine:370 LineCount:50]
Results: map[Contents: 370:
371: if (jeb) {
372: reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE);
373: dbg_summary("minsize=%d , jeb->free=%d ,"
374: "summary->size=%d , sumsize=%d\n",
375: minsize, jeb->free_size,
376: c->summary->sum_size, sumsize);
377: }
378:
379: /* Is there enough space for writing out the current node, or we have to
380: write out summary information now, close this jeb and select new nextblock? */
381: if (jeb && (PAD(minsize) + PAD(c->summary->sum_size + sumsize +
382: JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size)) {
383:
384: /* Has summary been disabled for this jeb? */
385: if (jffs2_sum_is_disabled(c->summary)) {
386: sumsize = JFFS2_SUMMARY_NOSUM_SIZE;
387: goto restart;
388: }
389:
390: /* Writing out the collected summary information */
391: dbg_summary("generating summary for 0x%08x.\n", jeb->offset);
392: ret = jffs2_sum_write_sumnode(c);
393:
394: if (ret)
395: return ret;
396:
397: if (jffs2_sum_is_disabled(c->summary)) {
398: /* jffs2_write_sumnode() couldn't write out the summary information
399: diabling summary for this jeb and free the collected information
400: */
401: sumsize = JFFS2_SUMMARY_NOSUM_SIZE;
402: goto restart;
403: }
404:
405: jffs2_close_nextblock(c, jeb);
406: jeb = NULL;
407: /* keep always valid value in reserved_size */
408: reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE);
409: }
410: } else {
411: if (jeb && minsize > jeb->free_size) {
412: uint32_t waste;
413:
414: /* Skip the end of this block and file it as having some dirty space */
415: /* If there's a pending write to it, flush now */
416:
417: if (jffs2_wbuf_dirty(c)) {
418: spin_unlock(&c->erase_completion_lock);
419: jffs2_dbg(1, "%s(): Flushing write buffer\n",
]
|
| 12/2 |
2026/09/04 07:35 |
llm |
expert |
0m
Model:
Tokens:
input: 12072
output: 41
thoughts: 519
Thoughts: **Analyzing Summary Node Generation in JFFS2**
Okay, so I'm looking at this `jffs2_do_reserve_space` function, specifically the part where summary nodes are generated. The logic is a bit convoluted, and I'm trying to wrap my head around a specific scenario. It looks like `jffs2_sum_write_sumnode` is being called, which indicates a few things: `jeb` (the JFFS2 erase block structure) isn't null, and there isn't enough free space in the block for the requested data plus the summary data. Specifically, `PAD(minsize) + PAD(c->summary->sum_size + sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size`.
Now, the puzzling bit: If `jffs2_sum_write_sumnode` is called, what's going on with the summary information *itself*? If `c->summary->sum_num` is zero, which likely implies `c->summary->sum_size` is also zero, why is it writing *any* summary data? It doesn't make sense to write an empty summary node.
Perhaps the comparison `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size` is the deciding factor, causing it to close the block early and write a summary even if it's currently empty? Could there be an edge case where the block is considered full *before* any actual nodes are written, which means the block already had data in it but no summary info? However, the summary would have been disabled, in which case the conditional would have selected the other path.
I'm thinking maybe the block's `jeb->free_size` is smaller than expected, even if there are currently no nodes in the block. That seems contradictory unless there's some prior state I'm missing. How can the free size be small if the block is essentially empty?
Is it possible the block was partially filled *previously*, but the summary was somehow not collected correctly? But, if the summary was disabled, `jffs2_sum_is_disabled` should have been true.
The only other scenario I can think of is that `jeb` represents a newly opened block, but `minsize` is exceptionally large. Maybe `minsize` is bigger than the block size? That would definitely trigger this condition. I'm going to revisit `jffs2_do_reserve_space` from the beginning to ensure I'm not missing anything. There's probably a sequence of events I'm not fully grasping yet.
|
| 13/2 |
2026/09/04 07:35 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/nodemgmt.c FirstLine:300 LineCount:70]
Results: map[Contents: 300: jffs2_dbg(1, "%s(): Triggering erase of erasable block at 0x%08x\n",
301: __func__, ejeb->offset);
302: }
303:
304: if (!c->nr_erasing_blocks &&
305: !list_empty(&c->erasable_pending_wbuf_list)) {
306: jffs2_dbg(1, "%s(): Flushing write buffer\n",
307: __func__);
308: /* c->nextblock is NULL, no update to c->nextblock allowed */
309: spin_unlock(&c->erase_completion_lock);
310: jffs2_flush_wbuf_pad(c);
311: spin_lock(&c->erase_completion_lock);
312: /* Have another go. It'll be on the erasable_list now */
313: return -EAGAIN;
314: }
315:
316: if (!c->nr_erasing_blocks) {
317: /* Ouch. We're in GC, or we wouldn't have got here.
318: And there's no space left. At all. */
319: pr_crit("Argh. No free space left for GC. nr_erasing_blocks is %d. nr_free_blocks is %d. (erasableempty: %s, erasingempty: %s, erasependingempty: %s)\n",
320: c->nr_erasing_blocks, c->nr_free_blocks,
321: str_yes_no(list_empty(&c->erasable_list)),
322: str_yes_no(list_empty(&c->erasing_list)),
323: str_yes_no(list_empty(&c->erase_pending_list)));
324: return -ENOSPC;
325: }
326:
327: spin_unlock(&c->erase_completion_lock);
328: /* Don't wait for it; just erase one right now */
329: jffs2_erase_pending_blocks(c, 1);
330: spin_lock(&c->erase_completion_lock);
331:
332: /* An erase may have failed, decreasing the
333: amount of free space available. So we must
334: restart from the beginning */
335: return -EAGAIN;
336: }
337:
338: next = c->free_list.next;
339: list_del(next);
340: c->nextblock = list_entry(next, struct jffs2_eraseblock, list);
341: c->nr_free_blocks--;
342:
343: jffs2_sum_reset_collected(c->summary); /* reset collected summary */
344:
345: #ifdef CONFIG_JFFS2_FS_WRITEBUFFER
346: /* adjust write buffer offset, else we get a non contiguous write bug */
347: if (!(c->wbuf_ofs % c->sector_size) && !c->wbuf_len)
348: c->wbuf_ofs = 0xffffffff;
349: #endif
350:
351: jffs2_dbg(1, "%s(): new nextblock = 0x%08x\n",
352: __func__, c->nextblock->offset);
353:
354: return 0;
355: }
356:
357: /* Called with alloc sem _and_ erase_completion_lock */
358: static int jffs2_do_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
359: uint32_t *len, uint32_t sumsize)
360: {
361: struct jffs2_eraseblock *jeb = c->nextblock;
362: uint32_t reserved_size; /* for summary information at the end of the jeb */
363: int ret;
364:
365: restart:
366: reserved_size = 0;
367:
368: if (jffs2_sum_active() && (sumsize != JFFS2_SUMMARY_NOSUM_SIZE)) {
369: /* NOSUM_SIZE means not to generate summary */
]
|
| 14/2 |
2026/09/04 07:35 |
llm |
expert |
0m
Model:
Tokens:
input: 14473
output: 41
thoughts: 46
Thoughts: Here's my summary, as though I'm thinking through this myself:
**Tracing the JFFS2 Space Reservation Logic**
Okay, so I'm digging into this JFFS2 garbage collection space reservation. The flow starts with `jffs2_do_reserve_space`. Right, right... that's the core reservation function. But *where* is it being called from? Let's check the calling function... looks like it's `jffs2_reserve_space_gc`. Ah, that makes sense. It's the garbage collector that's actually requesting the space reservation. Now I want to understand *how* the GC is requesting the space. Time to dive into `jffs2_reserve_space_gc` and see what's happening there. What triggers the reservation, under what conditions, how much space is requested... Let's see if this sheds some light!
|
| 15/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/nodemgmt.c FirstLine:210 LineCount:50]
Results: map[Contents: 210: ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
211: if (ret)
212: mutex_unlock(&c->alloc_sem);
213: return ret;
214: }
215:
216: int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
217: uint32_t *len, uint32_t sumsize)
218: {
219: int ret;
220: minsize = PAD(minsize);
221:
222: jffs2_dbg(1, "%s(): Requested 0x%x bytes\n", __func__, minsize);
223:
224: while (true) {
225: spin_lock(&c->erase_completion_lock);
226: ret = jffs2_do_reserve_space(c, minsize, len, sumsize);
227: if (ret) {
228: jffs2_dbg(1, "%s(): looping, ret is %d\n",
229: __func__, ret);
230: }
231: spin_unlock(&c->erase_completion_lock);
232:
233: if (ret == -EAGAIN)
234: cond_resched();
235: else
236: break;
237: }
238: if (!ret)
239: ret = jffs2_prealloc_raw_node_refs(c, c->nextblock, 1);
240:
241: return ret;
242: }
243:
244:
245: /* Classify nextblock (clean, dirty of verydirty) and force to select an other one */
246:
247: static void jffs2_close_nextblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb)
248: {
249:
250: if (c->nextblock == NULL) {
251: jffs2_dbg(1, "%s(): Erase block at 0x%08x has already been placed in a list\n",
252: __func__, jeb->offset);
253: return;
254: }
255: /* Check, if we have a dirty block now, or if it was dirty already */
256: if (ISDIRTY (jeb->wasted_size + jeb->dirty_size)) {
257: c->dirty_size += jeb->wasted_size;
258: c->wasted_size -= jeb->wasted_size;
259: jeb->dirty_size += jeb->wasted_size;
]
|
| 16/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 14261
output: 38
thoughts: 0
|
| 17/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/gc.c FirstLine:600 LineCount:50]
Results: map[Contents: 600: int retried = 0;
601:
602: jffs2_dbg(1, "Going to GC REF_PRISTINE node at 0x%08x\n",
603: ref_offset(raw));
604:
605: alloclen = rawlen = ref_totlen(c, c->gcblock, raw);
606:
607: /* Ask for a small amount of space (or the totlen if smaller) because we
608: don't want to force wastage of the end of a block if splitting would
609: work. */
610: if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
611: alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN;
612:
613: ret = jffs2_reserve_space_gc(c, alloclen, &alloclen, rawlen);
614: /* 'rawlen' is not the exact summary size; it is only an upper estimation */
615:
616: if (ret)
617: return ret;
618:
619: if (alloclen < rawlen) {
620: /* Doesn't fit untouched. We'll go the old route and split it */
621: return -EBADFD;
622: }
623:
624: node = kmalloc(rawlen, GFP_KERNEL);
625: if (!node)
626: return -ENOMEM;
627:
628: ret = jffs2_flash_read(c, ref_offset(raw), rawlen, &retlen, (char *)node);
629: if (!ret && retlen != rawlen)
630: ret = -EIO;
631: if (ret)
632: goto out_node;
633:
634: crc = crc32(0, node, sizeof(struct jffs2_unknown_node)-4);
635: if (je32_to_cpu(node->u.hdr_crc) != crc) {
636: pr_warn("Header CRC failed on REF_PRISTINE node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
637: ref_offset(raw), je32_to_cpu(node->u.hdr_crc), crc);
638: goto bail;
639: }
640:
641: switch(je16_to_cpu(node->u.nodetype)) {
642: case JFFS2_NODETYPE_INODE:
643: crc = crc32(0, node, sizeof(node->i)-8);
644: if (je32_to_cpu(node->i.node_crc) != crc) {
645: pr_warn("Node CRC failed on REF_PRISTINE data node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
646: ref_offset(raw), je32_to_cpu(node->i.node_crc),
647: crc);
648: goto bail;
649: }
]
|
| 18/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 16564
output: 37
thoughts: 617
Thoughts: **Garbage Collection Conundrum**
Okay, so I'm in `jffs2_garbage_collect_pristine`, and it calls `jffs2_reserve_space_gc`. I'm focusing on that last argument, `sumsize`. It's set to `rawlen`, which is the length of the node we're garbage collecting. But isn't `sumsize` supposed to be the size of the *summary* information for the node? That feels off.
Ah, right, the comment clarifies: "'`rawlen` is not the exact summary size; it's just an upper estimation.'" So `sumsize` is an *upper* bound. Got it. But if the block (`jeb`) is nearly full, this could be a problem: `PAD(minsize) + PAD(c->summary->sum_size + sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size`. `c->summary->sum_num` is zero? `c->summary->sum_size` is then zero. This reduces down to `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size`.
And if that condition is true, it tries to write the summary node. But if `c->summary->sum_num` is zero, we're going to hit a `BUG!` What's going on here? Ah, this is probably the *first* node being written to a block, so no summary info is available.
If `jeb` is a fresh block, `jeb->free_size` is the whole block size. If `minsize` plus `sumsize` plus the summary frame size is larger than the block size, this triggers it. `minsize` is `alloclen`, which is at most `rawlen`, and we know `sumsize` is `rawlen`. So, the condition is now `rawlen + rawlen + JFFS2_SUMMARY_FRAME_SIZE > jeb->free_size`.
The problem is, if `rawlen` is huge β bigger than half the block size β this condition is met, *even on an empty block*. Now, the usual JFFS2 node sizes are limited, right? Say, data nodes are 4KB max.
But...what about pathological cases? A malicious filesystem image? Or, what about a very large extended attribute? Could the user create a truly massive node? I need to go look up the max node size allowed by JFFS2.
|
| 19/2 |
2026/09/04 07:36 |
tool |
grepper |
0m
Args: map[Expression:JFFS2_MAX_NAME_LEN PathPrefix:fs/jffs2/]
Results: map[Output:fs/jffs2/dir.c=80=static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
--
fs/jffs2/dir.c-90-
fs/jffs2/dir.c:91: if (target->d_name.len > JFFS2_MAX_NAME_LEN)
fs/jffs2/dir.c-92- return ERR_PTR(-ENAMETOOLONG);
--
fs/jffs2/fs.c=210=int jffs2_statfs(struct dentry *dentry, struct kstatfs *buf)
--
fs/jffs2/fs.c-219- buf->f_ffree = 0;
fs/jffs2/fs.c:220: buf->f_namelen = JFFS2_MAX_NAME_LEN;
fs/jffs2/fs.c-221- buf->f_fsid.val[0] = JFFS2_SUPER_MAGIC;
--
fs/jffs2/readinode.c=1145=static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
--
fs/jffs2/readinode.c-1268- uint32_t csize = je32_to_cpu(latest_node->csize);
fs/jffs2/readinode.c:1269: if (csize > JFFS2_MAX_NAME_LEN)
fs/jffs2/readinode.c-1270- return -ENAMETOOLONG;
]
|
| 20/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 18196
output: 38
thoughts: 57
Thoughts: Okay, let's see, my mind is jumping around a bit here, focusing on the nitty-gritty of JFFS2, as usual.
**JFFS2 Deep Dive**
Right, so I'm thinking about file names... *`JFFS2_MAX_NAME_LEN`*... that rings a bell. 254 bytes, right? Gotta keep that number in the back of my head when I'm assessing any potential limitations in this area. Then my thoughts drift to the data nodes themselves. Of course, they're typically constrained to *`PAGE_SIZE`*, which, depending on the architecture, is going to have significant implications for overall file size limits and performance. Now I need to see how the system actually handles the writing of inode data. I should probably focus on how the file system writes inode data. The best way to get a solid grasp of this is to check the *`jffs2_write_inode_range`* function. I need to refresh my memory on the way data is being written.
|
| 21/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/write.c FirstLine:350 LineCount:50]
Results: map[Contents: 350: while(writelen) {
351: struct jffs2_full_dnode *fn;
352: unsigned char *comprbuf = NULL;
353: uint16_t comprtype = JFFS2_COMPR_NONE;
354: uint32_t alloclen;
355: uint32_t datalen, cdatalen;
356: int retried = 0;
357:
358: retry:
359: jffs2_dbg(2, "jffs2_commit_write() loop: 0x%x to write to 0x%x\n",
360: writelen, offset);
361:
362: ret = jffs2_reserve_space(c, sizeof(*ri) + JFFS2_MIN_DATA_LEN,
363: &alloclen, ALLOC_NORMAL, JFFS2_SUMMARY_INODE_SIZE);
364: if (ret) {
365: jffs2_dbg(1, "jffs2_reserve_space returned %d\n", ret);
366: break;
367: }
368: mutex_lock(&f->sem);
369: datalen = min_t(uint32_t, writelen,
370: PAGE_SIZE - (offset & (PAGE_SIZE-1)));
371: cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), datalen);
372:
373: comprtype = jffs2_compress(c, f, buf, &comprbuf, &datalen, &cdatalen);
374:
375: ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
376: ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
377: ri->totlen = cpu_to_je32(sizeof(*ri) + cdatalen);
378: ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4));
379:
380: ri->ino = cpu_to_je32(f->inocache->ino);
381: ri->version = cpu_to_je32(++f->highest_version);
382: ri->isize = cpu_to_je32(max(je32_to_cpu(ri->isize), offset + datalen));
383: ri->offset = cpu_to_je32(offset);
384: ri->csize = cpu_to_je32(cdatalen);
385: ri->dsize = cpu_to_je32(datalen);
386: ri->compr = comprtype & 0xff;
387: ri->usercompr = (comprtype >> 8 ) & 0xff;
388: ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8));
389: ri->data_crc = cpu_to_je32(crc32(0, comprbuf, cdatalen));
390:
391: fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, ALLOC_NORETRY);
392:
393: jffs2_free_comprbuf(comprbuf, buf);
394:
395: if (IS_ERR(fn)) {
396: ret = PTR_ERR(fn);
397: mutex_unlock(&f->sem);
398: jffs2_complete_reservation(c);
399: if (!retried) {
]
|
| 22/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 19573
output: 38
thoughts: 358
Thoughts: **Analyzing a JFFS2 Garbage Collection Bug**
Okay, so I'm looking at this `jffs2_write_inode_range` function, and it's calling `jffs2_reserve_space`. The initial call has a `minsize` of 196 bytes (68 + 128) and `sumsize` of only 14 bytes. Seems small, right? But the stack trace is the key: `jffs2_reserve_space` leads directly into the garbage collection code β specifically, `jffs2_garbage_collect_pass`, then `jffs2_garbage_collect_live`, and so on, eventually hitting `jffs2_reserve_space_gc`. So, the problem is happening *during garbage collection*. That suggests that the initial space reservation failed, causing the GC to be invoked.
In `jffs2_garbage_collect_pristine`, it's trying to reserve space for a "pristine node". The size here is determined by `rawlen = ref_totlen(c, c->gcblock, raw)`. Hmm, now the question is: how large can `rawlen` get? Could it be a really large value, maybe causing a problem? If we're talking about a malicious filesystem, I suppose it could be up to the block size, which could be an issue. But what about a *normal* filesystem? Could we have a legitimately large `rawlen` under certain circumstances? Maybe if it's a `JFFS2_NODETYPE_XATTR` or something similar? Need to dive into `jffs2_garbage_collect_pristine` and find out what's really happening.
|
| 23/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/gc.c FirstLine:600 LineCount:50]
Results: map[Contents: 600: int retried = 0;
601:
602: jffs2_dbg(1, "Going to GC REF_PRISTINE node at 0x%08x\n",
603: ref_offset(raw));
604:
605: alloclen = rawlen = ref_totlen(c, c->gcblock, raw);
606:
607: /* Ask for a small amount of space (or the totlen if smaller) because we
608: don't want to force wastage of the end of a block if splitting would
609: work. */
610: if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
611: alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN;
612:
613: ret = jffs2_reserve_space_gc(c, alloclen, &alloclen, rawlen);
614: /* 'rawlen' is not the exact summary size; it is only an upper estimation */
615:
616: if (ret)
617: return ret;
618:
619: if (alloclen < rawlen) {
620: /* Doesn't fit untouched. We'll go the old route and split it */
621: return -EBADFD;
622: }
623:
624: node = kmalloc(rawlen, GFP_KERNEL);
625: if (!node)
626: return -ENOMEM;
627:
628: ret = jffs2_flash_read(c, ref_offset(raw), rawlen, &retlen, (char *)node);
629: if (!ret && retlen != rawlen)
630: ret = -EIO;
631: if (ret)
632: goto out_node;
633:
634: crc = crc32(0, node, sizeof(struct jffs2_unknown_node)-4);
635: if (je32_to_cpu(node->u.hdr_crc) != crc) {
636: pr_warn("Header CRC failed on REF_PRISTINE node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
637: ref_offset(raw), je32_to_cpu(node->u.hdr_crc), crc);
638: goto bail;
639: }
640:
641: switch(je16_to_cpu(node->u.nodetype)) {
642: case JFFS2_NODETYPE_INODE:
643: crc = crc32(0, node, sizeof(node->i)-8);
644: if (je32_to_cpu(node->i.node_crc) != crc) {
645: pr_warn("Node CRC failed on REF_PRISTINE data node at 0x%08x: Read 0x%08x, calculated 0x%08x\n",
646: ref_offset(raw), je32_to_cpu(node->i.node_crc),
647: crc);
648: goto bail;
649: }
]
|
| 24/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 18940
output: 38
thoughts: 0
|
| 25/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:860 LineCount:50]
Results: map[Contents: 860: jeb = c->nextblock;
861: ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
862:
863: if (ret)
864: goto out;
865:
866: if (!c->summary->sum_num || !c->summary->sum_list_head) {
867: JFFS2_WARNING("Empty summary info!!!\n");
868: BUG();
869: }
870:
871: datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
872: infosize = sizeof(struct jffs2_raw_summary) + datasize;
873: padsize = jeb->free_size - infosize;
874: infosize += padsize;
875: datasize += padsize;
876:
877: ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
878:
879: out:
880: spin_lock(&c->erase_completion_lock);
881: return ret;
882: }
]
|
| 26/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 21689
output: 44
thoughts: 518
Thoughts: **Analyzing JFFS2 Space Reservation for Garbage Collection**
Okay, let's break down this `jffs2_reserve_space_gc` function call, which ultimately leads to `jffs2_do_reserve_space`. My initial thought is to trace the path and understand how space is actually reserved. Specifically, I'm trying to see if there's any potential for optimization in the GC.
So, `jffs2_do_reserve_space` is where the core logic resides. I'm focusing on this section related to the summary information and garbage collection, mainly this code block:
```c
if (jffs2_sum_active() && (sumsize != JFFS2_SUMMARY_NOSUM_SIZE)) {
if (jeb) {
reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE);
}
if (jeb && (PAD(minsize) + PAD(c->summary->sum_size + sumsize +
JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size)) {
/* Writing out the collected summary information */
ret = jffs2_sum_write_sumnode(c);
```
I see that if `jeb` (the JFFS2 eraseblock) is valid, the code determines `reserved_size`. More importantly, if the necessary size ( `PAD(minsize) + PAD(c->summary->sum_size + sumsize + JFFS2_SUMMARY_FRAME_SIZE)`) exceeds the free space on the block (`jeb->free_size`), the code likely attempts to write summary information. This is where I want to look more closely.
The key question in my mind is how `minsize` and `alloclen` are calculated. `minsize` is likely related to the data we need to write, and it seems to be related to `alloclen` which is limited. Now, I see this conditional:
```c
if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN;
```
Interesting, so `alloclen` is capped if `ic` is not NULL and exceeds a certain size. The interesting point is when `ic` is NULL, which means `alloclen` is `rawlen`.
I need to understand under which circumstances `ic` is NULL. It looks like `ic` comes from `struct jffs2_inode_cache *ic = raw->ic;`. So it comes from `raw`.
Okay, so looking back to the beginning of the function, I recall that `raw` is a `struct jffs2_raw_node_ref`. This makes sense. That `ic` field inside of `raw` is going to be NULL for node types that aren't inodes (directory entries, extended attributes, etc.). I want to know more about which nodes this applies to, and see what the implications are in determining the size. This might lead to identifying some optimization opportunities. I need to investigate the `jffs2_raw_node_ref` structure and how it relates to different node types and what they mean for space reservation. The interplay of `alloclen`, `rawlen`, and `ic`'s NULL state is crucial.
|
| 27/2 |
2026/09/04 07:36 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:fs/jffs2/gc.c Name:jffs2_raw_node_ref]
Results: map[SourceCode: 75: /*
76: This is all we need to keep in-core for each raw node during normal
77: operation. As and when we do read_inode on a particular inode, we can
78: scan the nodes which are listed for it and build up a proper map of
79: which nodes are currently valid. JFFSv1 always used to keep that whole
80: map in core for each inode.
81: */
82: struct jffs2_raw_node_ref
83: {
84: struct jffs2_raw_node_ref *next_in_ino; /* Points to the next raw_node_ref
85: for this object. If this _is_ the last, it points to the inode_cache,
86: xattr_ref or xattr_datum instead. The common part of those structures
87: has NULL in the first word. See jffs2_raw_ref_to_ic() below */
88: uint32_t flash_offset;
89: #undef TEST_TOTLEN
90: #ifdef TEST_TOTLEN
91: uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */
92: #endif
93: };
SourceFile:fs/jffs2/nodelist.h]
|
| 28/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 23389
output: 38
thoughts: 55
Thoughts: Okay, here's my interpretation of those thoughts, presented as my own mental process, given my expertise:
**My Mental Flow Through JFFS2's Data Structures**
Right, let me see... that `raw->next_in_ino` fieldβ¦ yeah, thatβs the crucial pointer in this whole JFFS2 garbage collection business. Itβs pointing to the next reference within the inode. So, it's either referencing the next item in a linked list, which could be another inode, or possibly an `xattr_ref`, maybe an `xattr_datum`... it could point to a few different places depending on the state and whatβs being tracked. Itβs the linchpin that threads these structures together, allowing the GC to efficiently navigate them.
Now, hold on. I'm trying to remember... Where exactly are we? Ah, yes, in `jffs2_garbage_collect_pristine`. Okay, good, that contextualizes what I'm looking at. Let's see how this pointer helps in garbage collection specifically, given the focus on pristine nodes.
|
| 29/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/gc.c FirstLine:580 LineCount:50]
Results: map[Contents: 580: } else {
581: jffs2_dbg_dump_node(c, ref_offset(raw));
582: BUG();
583: }
584: }
585: upnout:
586: mutex_unlock(&f->sem);
587:
588: return ret;
589: }
590:
591: static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
592: struct jffs2_inode_cache *ic,
593: struct jffs2_raw_node_ref *raw)
594: {
595: union jffs2_node_union *node;
596: size_t retlen;
597: int ret;
598: uint32_t phys_ofs, alloclen;
599: uint32_t crc, rawlen;
600: int retried = 0;
601:
602: jffs2_dbg(1, "Going to GC REF_PRISTINE node at 0x%08x\n",
603: ref_offset(raw));
604:
605: alloclen = rawlen = ref_totlen(c, c->gcblock, raw);
606:
607: /* Ask for a small amount of space (or the totlen if smaller) because we
608: don't want to force wastage of the end of a block if splitting would
609: work. */
610: if (ic && alloclen > sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN)
611: alloclen = sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN;
612:
613: ret = jffs2_reserve_space_gc(c, alloclen, &alloclen, rawlen);
614: /* 'rawlen' is not the exact summary size; it is only an upper estimation */
615:
616: if (ret)
617: return ret;
618:
619: if (alloclen < rawlen) {
620: /* Doesn't fit untouched. We'll go the old route and split it */
621: return -EBADFD;
622: }
623:
624: node = kmalloc(rawlen, GFP_KERNEL);
625: if (!node)
626: return -ENOMEM;
627:
628: ret = jffs2_flash_read(c, ref_offset(raw), rawlen, &retlen, (char *)node);
629: if (!ret && retlen != rawlen)
]
|
| 30/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 21609
output: 38
thoughts: 0
|
| 31/2 |
2026/09/04 07:36 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:800 LineCount:50]
Results: map[Contents: 800:
801: jffs2_sum_reset_collected(c->summary);
802:
803: wpage += padsize;
804:
805: sm = wpage;
806: sm->offset = cpu_to_je32(c->sector_size - jeb->free_size);
807: sm->magic = cpu_to_je32(JFFS2_SUM_MAGIC);
808:
809: isum.sum_crc = cpu_to_je32(crc32(0, c->summary->sum_buf, datasize));
810: isum.node_crc = cpu_to_je32(crc32(0, &isum, sizeof(isum) - 8));
811:
812: vecs[0].iov_base = &isum;
813: vecs[0].iov_len = sizeof(isum);
814: vecs[1].iov_base = c->summary->sum_buf;
815: vecs[1].iov_len = datasize;
816:
817: sum_ofs = jeb->offset + c->sector_size - jeb->free_size;
818:
819: dbg_summary("writing out data to flash to pos : 0x%08x\n", sum_ofs);
820:
821: ret = jffs2_flash_writev(c, vecs, 2, sum_ofs, &retlen, 0);
822:
823: if (ret || (retlen != infosize)) {
824:
825: JFFS2_WARNING("Write of %u bytes at 0x%08x failed. returned %d, retlen %zd\n",
826: infosize, sum_ofs, ret, retlen);
827:
828: if (retlen) {
829: /* Waste remaining space */
830: spin_lock(&c->erase_completion_lock);
831: jffs2_link_node_ref(c, jeb, sum_ofs | REF_OBSOLETE, infosize, NULL);
832: spin_unlock(&c->erase_completion_lock);
833: }
834:
835: c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE;
836:
837: return 0;
838: }
839:
840: spin_lock(&c->erase_completion_lock);
841: jffs2_link_node_ref(c, jeb, sum_ofs | REF_NORMAL, infosize, NULL);
842: spin_unlock(&c->erase_completion_lock);
843:
844: return 0;
845: }
846:
847: /* Write out summary information - called from jffs2_do_reserve_space */
848:
849: int jffs2_sum_write_sumnode(struct jffs2_sb_info *c)
]
|
| 32/2 |
2026/09/04 07:36 |
llm |
expert |
0m
Model:
Tokens:
input: 25454
output: 40
thoughts: 289
Thoughts: **Analyzing a Potential Vulnerability in JFFS2 Summary Writing**
Okay, let's break down this JFFS2 issue. The crux of it seems to hinge on how summary nodes are written during garbage collection, and whether a malicious filesystem could trigger an out-of-bounds write. I'm focusing on the condition where `ic` is NULL, so `alloclen` is effectively `rawlen`.
The scenario highlights a specific size mismatch. If `rawlen` is huge, say 65536, and the free space `jeb->free_size` is also 65536, the calculation gets interesting. `PAD(minsize)` plus `PAD(c->summary->sum_size + sumsize + JFFS2_SUMMARY_FRAME_SIZE)` becomes a problem. The padded sizes sum up to 131088, which exceeds the available `jeb->free_size`. This overflow then activates `jffs2_sum_write_sumnode(c)`. Because it's the first node being written, `c->summary->sum_num` is zero. Then the code hits the BUG!
Now, the critical question is, can `rawlen` actually be that large? My initial thought is that `rawlen` represents the size of the node being garbage collected. Could a crafted, malicious filesystem contain a node of excessively large size? Yes, it could. Now let's clarify that point: `rawlen` is determined by `ref_totlen(c, c->gcblock, raw)`. We need to scrutinize the `ref_totlen` function to understand where this size comes from.
|
| 33/2 |
2026/09/04 07:37 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:fs/jffs2/nodelist.h Name:ref_totlen]
Results: map[SourceCode: SourceFile:]
|
| 34/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 26161
output: 31
thoughts: 11
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Analyzing the `ref_totlen` Variable**
Okay, so the immediate inclination is to dive into the codebase and start with a `grep` for `ref_totlen`. That's the most direct and efficient way to get a handle on how this variable is being used, declared, and modified. It's the first line of attack to map out its role within the larger system. I'm assuming, of course, that this project is properly indexed and searchable; otherwise, the thought would shift to `find` with the appropriate parameters to account for case-sensitivity and file type. From there, the goal is to quickly ascertain its scope, data type, and the contexts in which it's being used. Is it a global variable? Local to a specific function or class? Is it an integer, a floating-point number, a string representing a length, or something more complex? The grep results will hopefully give me some quick answers, or at least point me to the relevant areas. My plan is to mentally build a dependency graph as I start reviewing the matches.
|
| 35/2 |
2026/09/04 07:37 |
tool |
grepper |
0m
Args: map[Expression:ref_totlen PathPrefix:fs/jffs2/]
Results: map[Output:fs/jffs2/debug.c=310=__jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
--
fs/jffs2/debug.c-318- while (ref2) {
fs/jffs2/debug.c:319: uint32_t totlen = ref_totlen(c, jeb, ref2);
fs/jffs2/debug.c-320-
--
fs/jffs2/gc.c=591=static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
--
fs/jffs2/gc.c-604-
fs/jffs2/gc.c:605: alloclen = rawlen = ref_totlen(c, c->gcblock, raw);
fs/jffs2/gc.c-606-
--
fs/jffs2/gc.c=895=static int jffs2_garbage_collect_deletion_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
--
fs/jffs2/gc.c-912- uint32_t name_crc = crc32(0, fd->name, name_len);
fs/jffs2/gc.c:913: uint32_t rawlen = ref_totlen(c, jeb, fd->raw);
fs/jffs2/gc.c-914-
--
fs/jffs2/gc.c-932- /* Any dirent with the same name is going to have the same length... */
fs/jffs2/gc.c:933: if (ref_totlen(c, NULL, raw) != rawlen)
fs/jffs2/gc.c-934- continue;
--
fs/jffs2/nodelist.c=585=struct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c,
--
fs/jffs2/nodelist.c-615- } else if (unlikely(ref_offset(ref) != jeb->offset + c->sector_size - jeb->free_size)) {
fs/jffs2/nodelist.c:616: uint32_t last_len = ref_totlen(c, jeb, jeb->last_node);
fs/jffs2/nodelist.c-617-
--
fs/jffs2/nodelist.c-655- ref->__totlen = len;
fs/jffs2/nodelist.c:656: ref_totlen(c, jeb, ref);
fs/jffs2/nodelist.c-657-#endif
--
fs/jffs2/nodelist.c=662=int jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
--
fs/jffs2/nodelist.c-691-/* Calculate totlen from surrounding nodes or eraseblock */
fs/jffs2/nodelist.c:692:static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
fs/jffs2/nodelist.c-693- struct jffs2_eraseblock *jeb,
--
fs/jffs2/nodelist.c-717-
fs/jffs2/nodelist.c:718:uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
fs/jffs2/nodelist.c-719- struct jffs2_raw_node_ref *ref)
--
fs/jffs2/nodelist.c-722-
fs/jffs2/nodelist.c:723: ret = __ref_totlen(c, jeb, ref);
fs/jffs2/nodelist.c-724-
--
fs/jffs2/nodelist.h=82=struct jffs2_raw_node_ref
--
fs/jffs2/nodelist.h-90-#ifdef TEST_TOTLEN
fs/jffs2/nodelist.h:91: uint32_t __totlen; /* This may die; use ref_totlen(c, jeb, ) below */
fs/jffs2/nodelist.h-92-#endif
--
fs/jffs2/nodelist.h=296=static inline int jffs2_blocks_use_vmalloc(struct jffs2_sb_info *c)
--
fs/jffs2/nodelist.h-300-
fs/jffs2/nodelist.h:301:#define ref_totlen(a, b, c) __jffs2_ref_totlen((a), (b), (c))
fs/jffs2/nodelist.h-302-
--
fs/jffs2/nodelist.h=375=struct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c,
--
fs/jffs2/nodelist.h-378- struct jffs2_inode_cache *ic);
fs/jffs2/nodelist.h:379:extern uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c,
fs/jffs2/nodelist.h-380- struct jffs2_eraseblock *jeb,
--
fs/jffs2/nodemgmt.c=586=void jffs2_mark_node_obsolete(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref)
--
fs/jffs2/nodemgmt.c-624-
fs/jffs2/nodemgmt.c:625: freed_len = ref_totlen(c, jeb, ref);
fs/jffs2/nodemgmt.c-626-
--
fs/jffs2/readinode.c=31=static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info *tn)
--
fs/jffs2/readinode.c-114- jeb = &c->blocks[ref->flash_offset / c->sector_size];
fs/jffs2/readinode.c:115: len = ref_totlen(c, jeb, ref);
fs/jffs2/readinode.c-116- /* If it should be REF_NORMAL, it'll get marked as such when
--
fs/jffs2/readinode.c=586=static inline int read_direntry(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
--
fs/jffs2/readinode.c-617- jeb = &c->blocks[ref->flash_offset / c->sector_size];
fs/jffs2/readinode.c:618: len = ref_totlen(c, jeb, ref);
fs/jffs2/readinode.c-619-
--
fs/jffs2/readinode.c=713=static inline int read_dnode(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *ref,
--
fs/jffs2/readinode.c-819- jeb = &c->blocks[ref->flash_offset / c->sector_size];
fs/jffs2/readinode.c:820: len = ref_totlen(c, jeb, ref);
fs/jffs2/readinode.c-821-
--
fs/jffs2/wbuf.c=275=static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
--
fs/jffs2/wbuf.c-304- ref_offset(raw), ref_flags(raw),
fs/jffs2/wbuf.c:305: (ref_offset(raw) + ref_totlen(c, jeb, raw)),
fs/jffs2/wbuf.c-306- c->wbuf_ofs);
--
fs/jffs2/wbuf.c-310- ref_offset(raw), ref_flags(raw),
fs/jffs2/wbuf.c:311: (ref_offset(raw) + ref_totlen(c, jeb, raw)));
fs/jffs2/wbuf.c-312-
--
fs/jffs2/wbuf.c-437- if (retlen)
fs/jffs2/wbuf.c:438: jffs2_add_physical_node_ref(c, ofs | REF_OBSOLETE, ref_totlen(c, jeb, first_raw), NULL);
fs/jffs2/wbuf.c-439-
--
fs/jffs2/wbuf.c-463- for (raw = first_raw; raw != jeb->last_node; raw = ref_next(raw)) {
fs/jffs2/wbuf.c:464: uint32_t rawlen = ref_totlen(c, jeb, raw);
fs/jffs2/wbuf.c-465- struct jffs2_inode_cache *ic;
--
fs/jffs2/xattr.c=132=static int do_verify_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd)
--
fs/jffs2/xattr.c-185- jeb = &c->blocks[ref_offset(raw) / c->sector_size];
fs/jffs2/xattr.c:186: totlen = PAD(ref_totlen(c, jeb, raw));
fs/jffs2/xattr.c-187- if (ref_flags(raw) == REF_UNCHECKED) {
--
fs/jffs2/xattr.c=444=static int verify_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref)
--
fs/jffs2/xattr.c-491- jeb = &c->blocks[ref_offset(raw) / c->sector_size];
fs/jffs2/xattr.c:492: totlen = PAD(ref_totlen(c, jeb, raw));
fs/jffs2/xattr.c-493- if (ref_flags(raw) == REF_UNCHECKED) {
--
fs/jffs2/xattr.c=1261=int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
--
fs/jffs2/xattr.c-1275- old_ofs = ref_offset(ref->node);
fs/jffs2/xattr.c:1276: totlen = ref_totlen(c, c->gcblock, ref->node);
fs/jffs2/xattr.c-1277-
--
fs/jffs2/xattr.c=1295=int jffs2_verify_xattr(struct jffs2_sb_info *c)
--
fs/jffs2/xattr.c-1313- jeb = &c->blocks[ref_offset(raw) / c->sector_size];
fs/jffs2/xattr.c:1314: totlen = PAD(ref_totlen(c, jeb, raw));
fs/jffs2/xattr.c-1315- c->unchecked_size -= totlen; c->used_size += totlen;
]
|
| 36/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 29598
output: 39
thoughts: 724
Thoughts: **Analyzing a Potential JFFS2 Vulnerability**
Okay, so I'm digging into this JFFS2 file system code, and a potential vulnerability just jumped out at me. I'm looking at how the `ref_totlen` function calculates the length of a node. It calculates the length by taking the difference between the offset of the current node and the offset of the next node. Basically, this is the amount of space this node occupies in the flash block.
The issue arises if a malicious image presents a node with a *very* large length β a "long" `rawlen` value. The `ref_totlen` function itself might not directly cause problems, but it feeds into how the garbage collector works. The garbage collector will call `jffs2_reserve_space_gc` with this large `rawlen` as `sumsize`.
Now, if this `rawlen` becomes large enough, the condition `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size` will be true even for a seemingly empty block! That's because the padding and summary frame size, when added to this massive `rawlen`, can easily surpass the remaining free space, even if the block appears to be empty, leading to the condition where there are no summary entries. When that happens, boom! We hit a `BUG_ON`.
But I wonder... is this just a theoretical problem, or is it exploitable in a normal filesystem? I'm thinking about the maximum node sizes we can have. Data nodes are limited to `PAGE_SIZE`, so no problem there. Inode nodes are small, so probably fine. Dirent nodes are limited to around 294 bytes which isn't huge. The real problem might be with XATTR nodes! They can be up to `sizeof(struct jffs2_raw_xattr) + XATTR_NAME_MAX + XATTR_SIZE_MAX`. XATTR_SIZE_MAX is 65536, right? That means XATTR nodes can be up to 65KB! If the block size is 64KB, an XATTR node that size will clearly be a problem, but if we're dealing with larger block sizes like 128KB or 256KB, then a single 65KB XATTR node should be fine. I need to check the JFFS2 code to see if there are any size limits on XATTR nodes. If not, then a malicious XATTR could cause this issue. Time to dig deeper!
|
| 37/2 |
2026/09/04 07:37 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/xattr.c FirstLine:990 LineCount:50]
Results: map[Contents: 990: retry = 1;
991: up_read(&c->xattr_sem);
992: down_write(&c->xattr_sem);
993: goto retry;
994: } else {
995: rc = load_xattr_datum(c, xd);
996: if (unlikely(rc > 0)) {
997: *pref = ref->next;
998: delete_xattr_ref(c, ref);
999: goto retry;
1000: } else if (unlikely(rc < 0))
1001: goto out;
1002: }
1003: }
1004:
1005: prefix = jffs2_xattr_prefix(xd->xprefix, dentry);
1006: if (!prefix)
1007: continue;
1008: prefix_len = strlen(prefix);
1009: rc = prefix_len + xd->name_len + 1;
1010:
1011: if (buffer) {
1012: if (rc > size - len) {
1013: rc = -ERANGE;
1014: goto out;
1015: }
1016: memcpy(buffer, prefix, prefix_len);
1017: buffer += prefix_len;
1018: memcpy(buffer, xd->xname, xd->name_len);
1019: buffer += xd->name_len;
1020: *buffer++ = 0;
1021: }
1022: len += rc;
1023: }
1024: rc = len;
1025: out:
1026: if (!retry) {
1027: up_read(&c->xattr_sem);
1028: } else {
1029: up_write(&c->xattr_sem);
1030: }
1031: return rc;
1032: }
1033:
1034: int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname,
1035: char *buffer, size_t size)
1036: {
1037: struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
1038: struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
1039: struct jffs2_inode_cache *ic = f->inocache;
]
|
| 38/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 31647
output: 40
thoughts: 16
Thoughts: Okay, here's my attempt at summarizing the thought process, as requested, geared toward an expert audience, and written in the first person:
**Diving into `do_jffs2_setxattr`**
Alright, time to dive into `do_jffs2_setxattr`. I know this function is crucial for extended attribute management within JFFS2, so understanding its nuances is paramount. First, I need to remind myself of the core principles of JFFS2's design β the garbage collection, the wear-leveling, and how it handles atomic updates. This function is inevitably entangled with those concerns. I'm going to quickly refresh my mental model of the data structures involved, especially the inodes and the xattr nodes. I'll need to visualize how the xattr data is stored, and how that storage affects fragmentation and potential garbage collection pressure. I need to keep in mind the various error scenarios that can occur - out of space, write errors on the flash, and potential race conditions, as I go through the source. Let me quickly go through the code, looking for the critical sections that manage the flash writes and ensuring that I'm taking the correct precautions when setting an xattr. Let me specifically check how the checksums are being handled and verify that they are being appropriately calculated. I'll also be mindful of the different `flags` passed to the function, and how they influence the xattr's persistence and behavior. This exploration needs to be thorough; any issues here could lead to serious data corruption down the line. I'll pay close attention to the lock management as well, as concurrent access to the file system is an important consideration.
|
| 39/2 |
2026/09/04 07:37 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/xattr.c FirstLine:1050 LineCount:50]
Results: map[Contents:1050: for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
1051: BUG_ON(ref->ic!=ic);
1052:
1053: xd = ref->xd;
1054: if (xd->xprefix != xprefix)
1055: continue;
1056: if (!xd->xname) {
1057: /* xdatum is unchached */
1058: if (!retry) {
1059: retry = 1;
1060: up_read(&c->xattr_sem);
1061: down_write(&c->xattr_sem);
1062: goto retry;
1063: } else {
1064: rc = load_xattr_datum(c, xd);
1065: if (unlikely(rc > 0)) {
1066: *pref = ref->next;
1067: delete_xattr_ref(c, ref);
1068: goto retry;
1069: } else if (unlikely(rc < 0)) {
1070: goto out;
1071: }
1072: }
1073: }
1074: if (!strcmp(xname, xd->xname)) {
1075: rc = xd->value_len;
1076: if (buffer) {
1077: if (size < rc) {
1078: rc = -ERANGE;
1079: } else {
1080: memcpy(buffer, xd->xvalue, rc);
1081: }
1082: }
1083: goto out;
1084: }
1085: }
1086: rc = -ENODATA;
1087: out:
1088: if (!retry) {
1089: up_read(&c->xattr_sem);
1090: } else {
1091: up_write(&c->xattr_sem);
1092: }
1093: return rc;
1094: }
1095:
1096: int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname,
1097: const char *buffer, size_t size, int flags)
1098: {
1099: struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
]
|
| 40/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 32767
output: 40
thoughts: 0
|
| 41/2 |
2026/09/04 07:37 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/xattr.c FirstLine:1100 LineCount:50]
Results: map[Contents:1100: struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb);
1101: struct jffs2_inode_cache *ic = f->inocache;
1102: struct jffs2_xattr_datum *xd;
1103: struct jffs2_xattr_ref *ref, *newref, **pref;
1104: uint32_t length, request;
1105: int rc;
1106:
1107: rc = check_xattr_ref_inode(c, ic);
1108: if (unlikely(rc))
1109: return rc;
1110:
1111: request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size);
1112: if (request > c->sector_size - c->cleanmarker_size)
1113: return -ERANGE;
1114:
1115: rc = jffs2_reserve_space(c, request, &length,
1116: ALLOC_NORMAL, JFFS2_SUMMARY_XATTR_SIZE);
1117: if (rc) {
1118: JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", rc, request);
1119: return rc;
1120: }
1121:
1122: /* Find existing xattr */
1123: down_write(&c->xattr_sem);
1124: retry:
1125: for (ref=ic->xref, pref=&ic->xref; ref; pref=&ref->next, ref=ref->next) {
1126: xd = ref->xd;
1127: if (xd->xprefix != xprefix)
1128: continue;
1129: if (!xd->xname) {
1130: rc = load_xattr_datum(c, xd);
1131: if (unlikely(rc > 0)) {
1132: *pref = ref->next;
1133: delete_xattr_ref(c, ref);
1134: goto retry;
1135: } else if (unlikely(rc < 0))
1136: goto out;
1137: }
1138: if (!strcmp(xd->xname, xname)) {
1139: if (flags & XATTR_CREATE) {
1140: rc = -EEXIST;
1141: goto out;
1142: }
1143: if (!buffer) {
1144: ref->ino = ic->ino;
1145: ref->xid = xd->xid;
1146: ref->xseqno |= XREF_DELETE_MARKER;
1147: rc = save_xattr_ref(c, ref);
1148: if (!rc) {
1149: *pref = ref->next;
]
|
| 42/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 33640
output: 40
thoughts: 431
Thoughts: **My JFFS2 Xattr Node Dilemma**
Okay, so I'm looking at `do_jffs2_setxattr` and something's bugging me. It looks like an extended attribute (xattr) node can be *almost* as big as an entire sector, specifically up to `c->sector_size - c->cleanmarker_size`. That's a huge potential size, practically 64KB if `c->sector_size` is 64KB!
The problem is what happens during garbage collection with this large node. A user creates a near-64KB xattr. It gets written as one giant node. Later, the garbage collector, specifically `jffs2_garbage_collect_pristine`, comes along with `rawlen` equal to roughly 64KB. This kicks off `jffs2_reserve_space_gc` with `sumsize` also at about 64KB.
Then in `jffs2_do_reserve_space`, the calculation goes sideways. Let's say we're dealing with a freshly allocated block. Its `jeb->free_size` is 64KB. Then we calculate:
`PAD(minsize) + PAD(c->summary->sum_size + sumsize + JFFS2_SUMMARY_FRAME_SIZE)` which becomes roughly `PAD(64KB) + PAD(0 + 64KB + 14)`. This turns into, roughly, 128KB + 14. That's *way* larger than the free space in the block (64KB). The garbage collector will try to write the summary node!
The killer here is the fact `c->summary->sum_num` is zero. That causes this to hit a BUG!
Now, the `minsize` in `jffs2_garbage_collect_pristine` comes from `alloclen`. What about the `ic`? It seems like `ic` is NULL for xattr nodes in this case? I need to check `jffs2_garbage_collect_xattr_datum` to be sure.
|
| 43/2 |
2026/09/04 07:37 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/xattr.c FirstLine:1200 LineCount:50]
Results: map[Contents:1200: ic->xref = ref;
1201: }
1202: rc = PTR_ERR(newref);
1203: unrefer_xattr_datum(c, xd);
1204: } else if (ref) {
1205: delete_xattr_ref(c, ref);
1206: }
1207: out:
1208: up_write(&c->xattr_sem);
1209: jffs2_complete_reservation(c);
1210: return rc;
1211: }
1212:
1213: /* -------- garbage collector functions -------------
1214: * jffs2_garbage_collect_xattr_datum(c, xd, raw)
1215: * is used to move xdatum into new node.
1216: * jffs2_garbage_collect_xattr_ref(c, ref, raw)
1217: * is used to move xref into new node.
1218: * jffs2_verify_xattr(c)
1219: * is used to call do_verify_xattr_datum() before garbage collecting.
1220: * jffs2_release_xattr_datum(c, xd)
1221: * is used to release an in-memory object of xdatum.
1222: * jffs2_release_xattr_ref(c, ref)
1223: * is used to release an in-memory object of xref.
1224: * -------------------------------------------------- */
1225: int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd,
1226: struct jffs2_raw_node_ref *raw)
1227: {
1228: uint32_t totlen, length, old_ofs;
1229: int rc = 0;
1230:
1231: down_write(&c->xattr_sem);
1232: if (xd->node != raw)
1233: goto out;
1234: if (xd->flags & (JFFS2_XFLAGS_DEAD|JFFS2_XFLAGS_INVALID))
1235: goto out;
1236:
1237: rc = load_xattr_datum(c, xd);
1238: if (unlikely(rc)) {
1239: rc = (rc > 0) ? 0 : rc;
1240: goto out;
1241: }
1242: old_ofs = ref_offset(xd->node);
1243: totlen = PAD(sizeof(struct jffs2_raw_xattr)
1244: + xd->name_len + 1 + xd->value_len);
1245: rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
1246: if (rc) {
1247: JFFS2_WARNING("jffs2_reserve_space_gc()=%d, request=%u\n", rc, totlen);
1248: goto out;
1249: }
]
|
| 44/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 35479
output: 38
thoughts: 142
Thoughts: Okay, let me think this through...
**Garbage Collection and XATTRs - A Quick Review**
Right, so I'm looking at `jffs2_garbage_collect_xattr_datum`. I see that it calls `jffs2_reserve_space_gc`, and immediately my attention is drawn to that `JFFS2_SUMMARY_XATTR_SIZE`. It's clear that it's being used as `sumsize` within `jffs2_reserve_space_gc`. And that size, 14 bytes in the example, is definitely small, confirming this isn't about the *raw* length, this `sumsize` is a smaller constant. Makes sense so far.
Now the question... What about `jffs2_garbage_collect_pristine`? Does *that* come into play with xattr nodes at all? I need to clarify that. Okay, I'll check `jffs2_garbage_collect_pass`. That seems to be the logical place to start investigating.
|
| 45/2 |
2026/09/04 07:37 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/gc.c FirstLine:400 LineCount:50]
Results: map[Contents: 400: to do the GC. However, sometimes read_inode() needs to get
401: the alloc_sem() (for marking nodes invalid) so we must
402: drop the alloc_sem before sleeping. */
403:
404: mutex_unlock(&c->alloc_sem);
405: jffs2_dbg(1, "%s(): waiting for ino #%u in state %d\n",
406: __func__, ic->ino, ic->state);
407: sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
408: /* And because we dropped the alloc_sem we must start again from the
409: beginning. Ponder chance of livelock here -- we're returning success
410: without actually making any progress.
411:
412: Q: What are the chances that the inode is back in INO_STATE_READING
413: again by the time we next enter this function? And that this happens
414: enough times to cause a real delay?
415:
416: A: Small enough that I don't care :)
417: */
418: return 0;
419: }
420:
421: /* OK. Now if the inode is in state INO_STATE_GC, we are going to copy the
422: node intact, and we don't have to muck about with the fragtree etc.
423: because we know it's not in-core. If it _was_ in-core, we go through
424: all the iget() crap anyway */
425:
426: if (ic->state == INO_STATE_GC) {
427: spin_unlock(&c->inocache_lock);
428:
429: ret = jffs2_garbage_collect_pristine(c, ic, raw);
430:
431: spin_lock(&c->inocache_lock);
432: ic->state = INO_STATE_CHECKEDABSENT;
433: wake_up(&c->inocache_wq);
434:
435: if (ret != -EBADFD) {
436: spin_unlock(&c->inocache_lock);
437: goto test_gcnode;
438: }
439:
440: /* Fall through if it wanted us to, with inocache_lock held */
441: }
442:
443: /* Prevent the fairly unlikely race where the gcblock is
444: entirely obsoleted by the final close of a file which had
445: the only valid nodes in the block, followed by erasure,
446: followed by freeing of the ic because the erased block(s)
447: held _all_ the nodes of that inode.... never been seen but
448: it's vaguely possible. */
449:
]
|
| 46/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 36738
output: 38
thoughts: 136
Thoughts: **Garbage Collection Conundrums**
Okay, so `jffs2_garbage_collect_pristine` is triggered when an inode's `ic->state` is set to `INO_STATE_GC`. That tells me it's a node β inode or dirent, probably β that's not currently in core memory. Fine. If it's an inode, its size is limited to a single page, maybe a little more. But hang on... what if it's a dirent? Those things are generally much smaller, at around 294 bytes max, right? A significant size difference could impact the optimization assumptions. This changes things. What about these "unknown" nodes? I need to check how the garbage collection handles those, so let me dive into `jffs2_garbage_collect_pass`.
|
| 47/2 |
2026/09/04 07:37 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/gc.c FirstLine:300 LineCount:50]
Results: map[Contents: 300: jeb->offset, jeb->free_size,
301: jeb->dirty_size, jeb->used_size);
302: jeb->gc_node = raw;
303: spin_unlock(&c->erase_completion_lock);
304: mutex_unlock(&c->alloc_sem);
305: BUG();
306: }
307: }
308: jeb->gc_node = raw;
309:
310: jffs2_dbg(1, "Going to garbage collect node at 0x%08x\n",
311: ref_offset(raw));
312:
313: if (!raw->next_in_ino) {
314: /* Inode-less node. Clean marker, snapshot or something like that */
315: spin_unlock(&c->erase_completion_lock);
316: if (ref_flags(raw) == REF_PRISTINE) {
317: /* It's an unknown node with JFFS2_FEATURE_RWCOMPAT_COPY */
318: jffs2_garbage_collect_pristine(c, NULL, raw);
319: } else {
320: /* Just mark it obsolete */
321: jffs2_mark_node_obsolete(c, raw);
322: }
323: mutex_unlock(&c->alloc_sem);
324: goto eraseit_lock;
325: }
326:
327: ic = jffs2_raw_ref_to_ic(raw);
328:
329: #ifdef CONFIG_JFFS2_FS_XATTR
330: /* When 'ic' refers xattr_datum/xattr_ref, this node is GCed as xattr.
331: * We can decide whether this node is inode or xattr by ic->class. */
332: if (ic->class == RAWNODE_CLASS_XATTR_DATUM
333: || ic->class == RAWNODE_CLASS_XATTR_REF) {
334: spin_unlock(&c->erase_completion_lock);
335:
336: if (ic->class == RAWNODE_CLASS_XATTR_DATUM) {
337: ret = jffs2_garbage_collect_xattr_datum(c, (struct jffs2_xattr_datum *)ic, raw);
338: } else {
339: ret = jffs2_garbage_collect_xattr_ref(c, (struct jffs2_xattr_ref *)ic, raw);
340: }
341: goto test_gcnode;
342: }
343: #endif
344:
345: /* We need to hold the inocache. Either the erase_completion_lock or
346: the inocache_lock are sufficient; we trade down since the inocache_lock
347: causes less contention. */
348: spin_lock(&c->inocache_lock);
349:
]
|
| 48/2 |
2026/09/04 07:37 |
llm |
expert |
0m
Model:
Tokens:
input: 37960
output: 38
thoughts: 1449
Thoughts: **Analyzing the JFFS2 Garbage Collection Vulnerability**
Okay, so here's the breakdown of this JFFS2 garbage collection issue as I see it. It looks like `jffs2_garbage_collect_pristine` gets called when dealing with a pristine (meaning it hasn't been modified yet) node, specifically when `!raw->next_in_ino` and `ref_flags(raw) == REF_PRISTINE` are true. This generally surfaces with "unknown nodes" that use the `JFFS2_FEATURE_RWCOMPAT_COPY` feature.
My initial concern was if this could be triggered legitimately, without a maliciously crafted filesystem image. The scenario is this: a filesystem image contains an unknown node with that feature, and if its size is very large (say, 64KB), `jffs2_garbage_collect_pristine` is called with `ic = NULL` and `rawlen` set to 64KB. This kicks off `jffs2_reserve_space_gc` with `sumsize = rawlen` (also 64KB) - bingo! That's where the bug gets hit.
The first question I wanted to answer was if this was possible to trigger without a malicious image. Specifically, could a standard JFFS2 filesystem generate such a node? Nope, normal JFFS2 doesn't create these unknown nodes. I then looked at the case where `ic->state == INO_STATE_GC`. If *that* condition were true, `jffs2_garbage_collect_pristine` is called with `ic != NULL`. In this case, `alloclen` is limited to `sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN` (around 196 bytes), which makes the `rawlen` much smaller. But, `sumsize` is still determined from `rawlen`!
Looking closer at `jffs2_garbage_collect_pristine`, I see that `alloclen` is initially set to `rawlen` (which also becomes `ref_totlen(c, c->gcblock, raw)`) and then, if `ic` isn't `NULL` and `alloclen` is larger than 196 bytes, `alloclen` is capped at that same limit. The `sumsize` value in `jffs2_reserve_space_gc` remains at the value of `rawlen`.
I needed to see if `rawlen` can be large for an inode node? Well, yes, if the data node is large. But, data nodes are limited to `PAGE_SIZE` (4KB). That means the largest `rawlen` is around 4KB + 68 bytes, right? If `rawlen` is approximately 4KB, `sumsize` would be around 4KB too. Let's consider that the block is 64KB, with `jeb->free_size` being 64KB. Then `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE)` (which I believe is a padding or alignment value) is about 4KB + 4KB, meaning about 8KB. That's *way* less than 64KB, so that won't trigger the bug on an empty block. The bug triggers when that calculation exceeds `jeb->free_size`.
If the block is nearly full (say `jeb->free_size` is around 8KB), and `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE)` is 8.5KB, then we would trigger `jffs2_sum_write_sumnode`. But! If it's nearly full, there *must* be some existing nodes in the block! That would mean `c->summary->sum_num` is *not* zero, and the problem will *not* be hit.
The problem only occurs when `c->summary->sum_num` *is* zero, which means the block is empty. For the block to be empty, `jeb->free_size` must be the full block size (like 64KB). For `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size` to be true on an empty block, `minsize + sumsize` must be greater than the block size. Since `minsize` is at most 196 bytes (from `alloclen` if `ic != NULL`), the `sumsize` must be *almost* the size of the block. Therefore, `rawlen` must
|
| 49/2 |
2026/09/04 07:38 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:400 LineCount:50]
Results: map[Contents: 400: cond_resched();
401:
402: /* Make sure there's a spare ref for dirty space */
403: err = jffs2_prealloc_raw_node_refs(c, jeb, 2);
404: if (err)
405: return err;
406:
407: switch (je16_to_cpu(((struct jffs2_sum_unknown_flash *)sp)->nodetype)) {
408: case JFFS2_NODETYPE_INODE: {
409: struct jffs2_sum_inode_flash *spi;
410: spi = sp;
411:
412: ino = je32_to_cpu(spi->inode);
413:
414: dbg_summary("Inode at 0x%08x-0x%08x\n",
415: jeb->offset + je32_to_cpu(spi->offset),
416: jeb->offset + je32_to_cpu(spi->offset) + je32_to_cpu(spi->totlen));
417:
418: ic = jffs2_scan_make_ino_cache(c, ino);
419: if (!ic) {
420: JFFS2_NOTICE("scan_make_ino_cache failed\n");
421: return -ENOMEM;
422: }
423:
424: sum_link_node_ref(c, jeb, je32_to_cpu(spi->offset) | REF_UNCHECKED,
425: PAD(je32_to_cpu(spi->totlen)), ic);
426:
427: *pseudo_random += je32_to_cpu(spi->version);
428:
429: sp += JFFS2_SUMMARY_INODE_SIZE;
430:
431: break;
432: }
433:
434: case JFFS2_NODETYPE_DIRENT: {
435: struct jffs2_sum_dirent_flash *spd;
436: int checkedlen;
437: spd = sp;
438:
439: dbg_summary("Dirent at 0x%08x-0x%08x\n",
440: jeb->offset + je32_to_cpu(spd->offset),
441: jeb->offset + je32_to_cpu(spd->offset) + je32_to_cpu(spd->totlen));
442:
443:
444: /* This should never happen, but https://dev.laptop.org/ticket/4184 */
445: checkedlen = strnlen(spd->name, spd->nsize);
446: if (!checkedlen) {
447: pr_err("Dirent at %08x has zero at start of name. Aborting mount.\n",
448: jeb->offset +
449: je32_to_cpu(spd->offset));
]
|
| 50/2 |
2026/09/04 07:38 |
llm |
expert |
0m
Model:
Tokens:
input: 35240
output: 38
thoughts: 0
|
| 51/2 |
2026/09/04 07:38 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:860 LineCount:50]
Results: map[Contents: 860: jeb = c->nextblock;
861: ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
862:
863: if (ret)
864: goto out;
865:
866: if (!c->summary->sum_num || !c->summary->sum_list_head) {
867: JFFS2_WARNING("Empty summary info!!!\n");
868: BUG();
869: }
870:
871: datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
872: infosize = sizeof(struct jffs2_raw_summary) + datasize;
873: padsize = jeb->free_size - infosize;
874: infosize += padsize;
875: datasize += padsize;
876:
877: ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
878:
879: out:
880: spin_lock(&c->erase_completion_lock);
881: return ret;
882: }
]
|
| 52/2 |
2026/09/04 07:38 |
llm |
expert |
0m
Model:
Tokens:
input: 41760
output: 38
thoughts: 39
Thoughts: Here's a summary of my thought process, as requested:
**Diving into JFFS2 Node Writing**
Okay, so I'm trying to trace down exactly when `jffs2_sum_add_kvec` gets called in this JFFS2 implementation. My initial thought is it's related to node writing, specifically the node summaries. So, I need to confirm that suspicion and understand the context better. I'm going to start by diving into the `jffs2_sum_add_kvec` function itself. I need to understand its parameters, its purpose, and especially *when* it's invoked during the node writing process. This should give me a solid clue whether my initial hunch is correct, or if I need to back up and look elsewhere.
|
| 53/2 |
2026/09/04 07:38 |
tool |
grepper |
0m
Args: map[Expression:jffs2_sum_add_kvec PathPrefix:fs/jffs2/]
Results: map[Output:fs/jffs2/summary.c=231=void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s)
--
fs/jffs2/summary.c-247-
fs/jffs2/summary.c:248:int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
fs/jffs2/summary.c-249- unsigned long count, uint32_t ofs)
--
fs/jffs2/summary.h=180=void jffs2_sum_move_collected(struct jffs2_sb_info *c, struct jffs2_summary *s);
fs/jffs2/summary.h:181:int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
fs/jffs2/summary.h-182- unsigned long count, uint32_t to);
--
fs/jffs2/summary.h=189=int jffs2_sum_scan_sumnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
--
fs/jffs2/summary.h-200-#define jffs2_sum_reset_collected(a) do { } while (0)
fs/jffs2/summary.h:201:#define jffs2_sum_add_kvec(a,b,c,d) (0)
fs/jffs2/summary.h-202-#define jffs2_sum_move_collected(a,b) do { } while (0)
--
fs/jffs2/wbuf.c=794=int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs,
--
fs/jffs2/wbuf.c-905- if (jffs2_sum_active()) {
fs/jffs2/wbuf.c:906: int res = jffs2_sum_add_kvec(c, invecs, count, (uint32_t) to);
fs/jffs2/wbuf.c-907- if (res)
--
fs/jffs2/writev.c=16=int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs,
--
fs/jffs2/writev.c-21- int res;
fs/jffs2/writev.c:22: res = jffs2_sum_add_kvec(c, vecs, count, (uint32_t) to);
fs/jffs2/writev.c-23- if (res) {
--
fs/jffs2/writev.c=32=int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len,
--
fs/jffs2/writev.c-44-
fs/jffs2/writev.c:45: res = jffs2_sum_add_kvec(c, vecs, 1, (uint32_t) ofs);
fs/jffs2/writev.c-46- if (res) {
]
|
| 54/2 |
2026/09/04 07:38 |
llm |
expert |
0m
Model:
Tokens:
input: 42910
output: 37
thoughts: 313
Thoughts: **Analyzing JFFS2 Summary Calculation and Potential Vulnerabilities**
Okay, so it looks like `jffs2_sum_add_kvec` gets called by both `jffs2_flash_writev` and `jffs2_flash_direct_writev`. Right, that makes sense. It means every time a node is actually written to flash, its summary information gets added to the `c->summary` structure. But the really interesting part is that `jffs2_do_reserve_space` is called *before* the actual write. It's supposed to reserve space for the node. Now, if the space check fails, meaning there isn't enough space for the node *and* the summary, it triggers the block to be closed, and the summary node to be written.
The thing that has me focused is this: If the block is empty, `c->summary->sum_num` is zero, so the initial condition. Then it looks like the check `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size` determines whether the summary node will be written. We already know that can happen if `minsize + sumsize` is very large, and it's clear `sumsize` can blow up if `rawlen` is very large. That's a classic DoS vector β a malicious filesystem image with a node containing an incredibly large length, and we're sunk.
But wait. Is there *any* other way `sumsize` gets big? I need to consider all the angles. `sumsize` is passed as an argument to `jffs2_reserve_space`. That's the key. I need to trace all the call paths to `jffs2_reserve_space` and `jffs2_reserve_space_gc` and see how the `sumsize` parameter is calculated. That's the next step to ensuring this isn't exploitable via some other calculation.
|
| 55/2 |
2026/09/04 07:38 |
tool |
grepper |
0m
Args: map[Expression:jffs2_reserve_space_gc PathPrefix:fs/jffs2/]
Results: map[Output:fs/jffs2/gc.c=591=static int jffs2_garbage_collect_pristine(struct jffs2_sb_info *c,
--
fs/jffs2/gc.c-612-
fs/jffs2/gc.c:613: ret = jffs2_reserve_space_gc(c, alloclen, &alloclen, rawlen);
fs/jffs2/gc.c-614- /* 'rawlen' is not the exact summary size; it is only an upper estimation */
--
fs/jffs2/gc.c-722-
fs/jffs2/gc.c:723: ret = jffs2_reserve_space_gc(c, rawlen, &dummy, rawlen);
fs/jffs2/gc.c-724- /* this is not the exact summary size of it,
--
fs/jffs2/gc.c=758=static int jffs2_garbage_collect_metadata(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
--
fs/jffs2/gc.c-795-
fs/jffs2/gc.c:796: ret = jffs2_reserve_space_gc(c, sizeof(ri) + mdatalen, &alloclen,
fs/jffs2/gc.c-797- JFFS2_SUMMARY_INODE_SIZE);
fs/jffs2/gc.c-798- if (ret) {
fs/jffs2/gc.c:799: pr_warn("jffs2_reserve_space_gc of %zd bytes for garbage_collect_metadata failed: %d\n",
fs/jffs2/gc.c-800- sizeof(ri) + mdatalen, ret);
--
fs/jffs2/gc.c=850=static int jffs2_garbage_collect_dirent(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
--
fs/jffs2/gc.c-876-
fs/jffs2/gc.c:877: ret = jffs2_reserve_space_gc(c, sizeof(rd)+rd.nsize, &alloclen,
fs/jffs2/gc.c-878- JFFS2_SUMMARY_DIRENT_SIZE(rd.nsize));
fs/jffs2/gc.c-879- if (ret) {
fs/jffs2/gc.c:880: pr_warn("jffs2_reserve_space_gc of %zd bytes for garbage_collect_dirent failed: %d\n",
fs/jffs2/gc.c-881- sizeof(rd)+rd.nsize, ret);
--
fs/jffs2/gc.c=1013=static int jffs2_garbage_collect_hole(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
--
fs/jffs2/gc.c-1100-
fs/jffs2/gc.c:1101: ret = jffs2_reserve_space_gc(c, sizeof(ri), &alloclen,
fs/jffs2/gc.c-1102- JFFS2_SUMMARY_INODE_SIZE);
fs/jffs2/gc.c-1103- if (ret) {
fs/jffs2/gc.c:1104: pr_warn("jffs2_reserve_space_gc of %zd bytes for garbage_collect_hole failed: %d\n",
fs/jffs2/gc.c-1105- sizeof(ri), ret);
--
fs/jffs2/gc.c=1164=static int jffs2_garbage_collect_dnode(struct jffs2_sb_info *c, struct jffs2_eraseblock *orig_jeb,
--
fs/jffs2/gc.c-1346-
fs/jffs2/gc.c:1347: ret = jffs2_reserve_space_gc(c, sizeof(ri) + JFFS2_MIN_DATA_LEN,
fs/jffs2/gc.c-1348- &alloclen, JFFS2_SUMMARY_INODE_SIZE);
--
fs/jffs2/gc.c-1350- if (ret) {
fs/jffs2/gc.c:1351: pr_warn("jffs2_reserve_space_gc of %zd bytes for garbage_collect_dnode failed: %d\n",
fs/jffs2/gc.c-1352- sizeof(ri) + JFFS2_MIN_DATA_LEN, ret);
--
fs/jffs2/nodelist.h=385=int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
fs/jffs2/nodelist.h-386- uint32_t *len, int prio, uint32_t sumsize);
fs/jffs2/nodelist.h:387:int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
fs/jffs2/nodelist.h-388- uint32_t *len, uint32_t sumsize);
--
fs/jffs2/nodemgmt.c=78=int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
--
fs/jffs2/nodemgmt.c-215-
fs/jffs2/nodemgmt.c:216:int jffs2_reserve_space_gc(struct jffs2_sb_info *c, uint32_t minsize,
fs/jffs2/nodemgmt.c-217- uint32_t *len, uint32_t sumsize)
--
fs/jffs2/wbuf.c=275=static void jffs2_wbuf_recover(struct jffs2_sb_info *c)
--
fs/jffs2/wbuf.c-388- /* ... and get an allocation of space from a shiny new block instead */
fs/jffs2/wbuf.c:389: ret = jffs2_reserve_space_gc(c, end-start, &len, JFFS2_SUMMARY_NOSUM_SIZE);
fs/jffs2/wbuf.c-390- if (ret) {
--
fs/jffs2/write.c=59=struct jffs2_full_dnode *jffs2_write_dnode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
--
fs/jffs2/write.c-140- if (alloc_mode == ALLOC_GC) {
fs/jffs2/write.c:141: ret = jffs2_reserve_space_gc(c, sizeof(*ri) + datalen, &dummy,
fs/jffs2/write.c-142- JFFS2_SUMMARY_INODE_SIZE);
--
fs/jffs2/write.c=205=struct jffs2_full_dirent *jffs2_write_dirent(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
--
fs/jffs2/write.c-292- if (alloc_mode == ALLOC_GC) {
fs/jffs2/write.c:293: ret = jffs2_reserve_space_gc(c, sizeof(*rd) + namelen, &dummy,
fs/jffs2/write.c-294- JFFS2_SUMMARY_DIRENT_SIZE(namelen));
--
fs/jffs2/xattr.c=1225=int jffs2_garbage_collect_xattr_datum(struct jffs2_sb_info *c, struct jffs2_xattr_datum *xd,
--
fs/jffs2/xattr.c-1244- + xd->name_len + 1 + xd->value_len);
fs/jffs2/xattr.c:1245: rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XATTR_SIZE);
fs/jffs2/xattr.c-1246- if (rc) {
fs/jffs2/xattr.c:1247: JFFS2_WARNING("jffs2_reserve_space_gc()=%d, request=%u\n", rc, totlen);
fs/jffs2/xattr.c-1248- goto out;
--
fs/jffs2/xattr.c=1261=int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref,
--
fs/jffs2/xattr.c-1277-
fs/jffs2/xattr.c:1278: rc = jffs2_reserve_space_gc(c, totlen, &length, JFFS2_SUMMARY_XREF_SIZE);
fs/jffs2/xattr.c-1279- if (rc) {
fs/jffs2/xattr.c:1280: JFFS2_WARNING("%s: jffs2_reserve_space_gc() = %d, request = %u\n",
fs/jffs2/xattr.c-1281- __func__, rc, totlen);
]
|
| 56/2 |
2026/09/04 07:38 |
llm |
expert |
0m
Model:
Tokens:
input: 46247
output: 38
thoughts: 1764
Thoughts: **Analysis of JFFS2 Garbage Collection Vulnerability**
Okay, here's how I'm thinking through this JFFS2 garbage collection issue. I'm starting by looking at the callers of `jffs2_reserve_space_gc`. I see `sumsize` comes from different sources: `rawlen`, the summary node sizes, and XATTR sizes. I need to figure out which of these can get large enough to cause problems. My initial thought is that `rawlen` seems like the most likely candidate for significant size.
Now, if `rawlen` is large, it means a node on flash is large. We discussed that standard nodes shouldn't have excessively large lengths in a normal filesystem that would trip this up when reserving space on an otherwise empty block. But wait, what if `jeb->free_size` isn't the full block size? What if the block is *partially* filled? Crucially, what if `c->summary->sum_num` is zero? How can that happen if a block is partially filled? Unless... the block was partially filled in the past and then `jffs2_sum_reset_collected` was called. And when is `jffs2_sum_reset_collected` called? Itβs called when opening a new block, writing a summary node, or when erasing a block. So, `c->summary->sum_num` is zero when the block is empty.
But what if a node is written but `jffs2_sum_add_kvec` fails? If that fails, it disables the summary for that block, and `c->summary->sum_size = JFFS2_SUMMARY_NOSUM_SIZE`. If the summary is disabled, `jffs2_sum_is_disabled(c->summary)` is true, and it won't call `jffs2_sum_write_sumnode`. So `c->summary->sum_num` *can* only be zero if no nodes are successfully added to the summary. This would mean that the block is *completely* empty.
If the block is empty, then `jeb->free_size` should be the full block size. To trigger the bug, we need `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size`. This means `minsize + sumsize` has to be greater than the block size. `minsize` is small (at most 196 bytes for `ic != NULL`), so `sumsize` must be almost the block size. This means `rawlen` has to be almost the block size. Can `rawlen` be that large? We canβt have normal data nodes with lengths almost as big as the block, because JFFS2 limits data nodes to 4KB and dirents to ~300 bytes. XATTR nodes can be large, but they are garbage collected with the standard summary size, not `rawlen`. So, `rawlen` can only be large if we have a malicious filesystem image, an unknown node with `JFFS2_FEATURE_RWCOMPAT_COPY` and a large length.
Wait, what if `ic == NULL` in `jffs2_garbage_collect_pristine`? Then, `alloclen` is `rawlen`. Therefore, `minsize` becomes `rawlen`, and `sumsize` is also `rawlen`. So, we get `2 * rawlen + 14`. If `2 * rawlen + 14 > jeb->free_size`, the bug triggers. This is good because `rawlen` only has to be greater than half the block size. If the block size is 64KB, `rawlen` has to be > 32KB. Can a normal filesystem have a node with `rawlen > 32KB` and `ic == NULL`? Nope. Normal JFFS2 doesn't generate unknown nodes. What about xattr nodes? They're garbage collected via `jffs2_garbage_collect_xattr_datum`, which doesn't call `jffs2_garbage_collect_pristine`. So, this bug is ONLY triggered by a malicious filesystem image.
Alright, the bug report says `jffs2_write_end` triggers this. `jffs2_write_end` calls garbage collection. Garbage collection finds a live node and calls `jffs2_garbage_collect_pristine`. This means the filesystem was mounted and a write triggered the GC and the bug. So, the filesystem image must have a malicious node in it. Therefore, it's a Malicious Filesystem Trigger.
|
| 57/2 |
2026/09/04 07:38 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/erase.c FirstLine:400 LineCount:50]
Results: map[Contents: 400: int ret;
401: uint32_t bad_offset;
402:
403: switch (jffs2_block_check_erase(c, jeb, &bad_offset)) {
404: case -EAGAIN: goto refile;
405: case -EIO: goto filebad;
406: }
407:
408: /* Write the erase complete marker */
409: jffs2_dbg(1, "Writing erased marker to block at 0x%08x\n", jeb->offset);
410: bad_offset = jeb->offset;
411:
412: /* Cleanmarker in oob area or no cleanmarker at all ? */
413: if (jffs2_cleanmarker_oob(c) || c->cleanmarker_size == 0) {
414:
415: if (jffs2_cleanmarker_oob(c)) {
416: if (jffs2_write_nand_cleanmarker(c, jeb))
417: goto filebad;
418: }
419: } else {
420:
421: struct kvec vecs[1];
422: struct jffs2_unknown_node marker = {
423: .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
424: .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
425: .totlen = cpu_to_je32(c->cleanmarker_size)
426: };
427:
428: ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
429: if (ret)
430: goto filebad;
431:
432: marker.hdr_crc = cpu_to_je32(crc32(0, &marker, sizeof(struct jffs2_unknown_node)-4));
433:
434: vecs[0].iov_base = (unsigned char *) ▮
435: vecs[0].iov_len = sizeof(marker);
436: ret = jffs2_flash_direct_writev(c, vecs, 1, jeb->offset, &retlen);
437:
438: if (ret || retlen != sizeof(marker)) {
439: if (ret)
440: pr_warn("Write clean marker to block at 0x%08x failed: %d\n",
441: jeb->offset, ret);
442: else
443: pr_warn("Short write to newly-erased block at 0x%08x: Wanted %zd, got %zd\n",
444: jeb->offset, sizeof(marker), retlen);
445:
446: goto filebad;
447: }
448: }
449: /* Everything else got zeroed before the erase */
]
|
| 58/2 |
2026/09/04 07:38 |
llm |
expert |
0m
Model:
Tokens:
input: 41713
output: 38
thoughts: 0
|
| 59/2 |
2026/09/04 07:38 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:860 LineCount:50]
Results: map[Contents: 860: jeb = c->nextblock;
861: ret = jffs2_prealloc_raw_node_refs(c, jeb, 1);
862:
863: if (ret)
864: goto out;
865:
866: if (!c->summary->sum_num || !c->summary->sum_list_head) {
867: JFFS2_WARNING("Empty summary info!!!\n");
868: BUG();
869: }
870:
871: datasize = c->summary->sum_size + sizeof(struct jffs2_sum_marker);
872: infosize = sizeof(struct jffs2_raw_summary) + datasize;
873: padsize = jeb->free_size - infosize;
874: infosize += padsize;
875: datasize += padsize;
876:
877: ret = jffs2_sum_write_data(c, jeb, infosize, datasize, padsize);
878:
879: out:
880: spin_lock(&c->erase_completion_lock);
881: return ret;
882: }
]
|
| 60/2 |
2026/09/04 07:38 |
llm |
expert |
0m
Model:
Tokens:
input: 50349
output: 38
thoughts: 110
Thoughts: **Investigating JFFS2 Block Erasing and Cleanmarker Placement**
Okay, so I'm looking at `jffs2_mark_erased_block`. The code seems to be using `jffs2_flash_direct_writev` to actually write the cleanmarker. That makes sense, a direct write is what you'd expect. Now, `jffs2_flash_direct_writev` then calls `jffs2_sum_add_kvec`. Hmm, hold on a second... is the cleanmarker getting included in the checksum calculation within `jffs2_sum_add_kvec`? That doesn't seem right. It doesn't seem correct to include it; it should be calculated independently from the rest. Let me go double-check `jffs2_sum_add_kvec` itself and verify this behavior. I need to make sure the cleanmarker isn't inadvertently influencing the summary. I'll get to the bottom of this.
|
| 61/2 |
2026/09/04 07:39 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/summary.c FirstLine:240 LineCount:50]
Results: map[Contents: 240: c->summary->sum_list_head = s->sum_list_head;
241: c->summary->sum_list_tail = s->sum_list_tail;
242:
243: s->sum_list_head = s->sum_list_tail = NULL;
244: }
245:
246: /* Called from wbuf.c to collect writed node info */
247:
248: int jffs2_sum_add_kvec(struct jffs2_sb_info *c, const struct kvec *invecs,
249: unsigned long count, uint32_t ofs)
250: {
251: union jffs2_node_union *node;
252: struct jffs2_eraseblock *jeb;
253:
254: if (c->summary->sum_size == JFFS2_SUMMARY_NOSUM_SIZE) {
255: dbg_summary("Summary is disabled for this jeb! Skipping summary info!\n");
256: return 0;
257: }
258:
259: node = invecs[0].iov_base;
260: jeb = &c->blocks[ofs / c->sector_size];
261: ofs -= jeb->offset;
262:
263: switch (je16_to_cpu(node->u.nodetype)) {
264: case JFFS2_NODETYPE_INODE: {
265: struct jffs2_sum_inode_mem *temp =
266: kmalloc_obj(struct jffs2_sum_inode_mem);
267:
268: if (!temp)
269: goto no_mem;
270:
271: temp->nodetype = node->i.nodetype;
272: temp->inode = node->i.ino;
273: temp->version = node->i.version;
274: temp->offset = cpu_to_je32(ofs);
275: temp->totlen = node->i.totlen;
276: temp->next = NULL;
277:
278: return jffs2_sum_add_mem(c->summary, (union jffs2_sum_mem *)temp);
279: }
280:
281: case JFFS2_NODETYPE_DIRENT: {
282: struct jffs2_sum_dirent_mem *temp =
283: kmalloc(sizeof(struct jffs2_sum_dirent_mem) + node->d.nsize, GFP_KERNEL);
284:
285: if (!temp)
286: goto no_mem;
287:
288: temp->nodetype = node->d.nodetype;
289: temp->totlen = node->d.totlen;
]
|
| 62/2 |
2026/09/04 07:39 |
llm |
expert |
0m
Model:
Tokens:
input: 51554
output: 40
thoughts: 3944
Thoughts: **Vulnerability Analysis: JFFS2 Summary Node Bug**
Okay, so it looks like I've found a potentially critical bug in JFFS2's summary node handling. The core of the problem lies within how `jffs2_sum_add_kvec` deals with different node types. It only considers inodes, dirents, xattrs, and xrefs, ignoring cleanmarkers and padding. This is a critical oversight.
The immediate consequence is that if a block *only* contains a cleanmarker, the summary counter (`c->summary->sum_num`) will be zero. This becomes a major problem during block allocation. Let's see: if the block only contains a cleanmarker, `jeb->free_size` becomes `sector_size - cleanmarker_size`. The crux is this: if we try to write something that's close to filling that block, the padding calculations become problematic. If `PAD(minsize) + PAD(sumsize + JFFS2_SUMMARY_FRAME_SIZE)` exceeds `jeb->free_size`, we hit the bug.
Crucially, this can happen without needing a malicious filesystem image. If a block is freshly erased and *only* has a cleanmarker, and we try to write a node that's *just* too large, it will trigger the bug. I went through the size limits for different node types. Data nodes are at most PAGE_SIZE (4KB). Xattrs can be much larger, potentially up to 64KB, while dirents are in the hundreds of bytes. If the `sector_size` is 64KB, a 64KB xattr node could cause a conflict.
Let me examine the code in `do_jffs2_setxattr`: The size calculation here is critical. It's clear, that the `request = PAD(sizeof(struct jffs2_raw_xattr) + strlen(xname) + 1 + size)` and a check `request > c->sector_size - c->cleanmarker_size` is done. However, this check is the key: it guarantees that `request` will be small enough. Therefore, `jffs2_reserve_space` is subsequently called with this pre-checked `request`, along with `JFFS2_SUMMARY_XATTR_SIZE` (14 bytes) as the `sumsize`. In `jffs2_do_reserve_space`: `PAD(minsize) + PAD(c->summary->sum_size + sumsize + JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size` is checked. The critical moment is when `minsize` equals the `request`. If we craft the right xattr size so that `PAD(request)` is very close to `jeb->free_size`, the padding from the summary calculations can push the check over the edge.
It seems achievable with a 65536-byte `sector_size` and a 12-byte `cleanmarker_size`, if the `request` can be crafted to 65524. `jffs2_do_reserve_space` will be called, then the check `PAD(request) + PAD(28) > jeb->free_size` goes true, and the process decides it needs to write the summary node. But here's the catch: the block is still empty (except for the cleanmarker), so `c->summary->sum_num` is zero. That's the bug trigger.
This is exploitable! An unprivileged user can create an xattr of a specific size to make `PAD(request) == c->sector_size - c->cleanmarker_size`. The maximum xattr value size is 65536 bytes. With this, the user can control the size of `request`. Since `request = PAD(32 + strlen(xname) + 1 + size)`. An attacker can manipulate `size` to make this work. There is a check: `if (request > c->sector_size - c->cleanmarker_size)`. But we're in a situation where `request` *equals* `sector_size - cleanmarker_size`, passing the gatekeeper check. `jffs2_reserve_space` with calls `jffs2_do_reserve_space`. In this case: `65524 + PAD(0 + 14 + 14) = 65524 + 28 = 65552`. But `jeb->free_size` is 65524! The check `65552 > 65524` is true
|
| 63/2 |
2026/09/04 07:39 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/nodemgmt.c FirstLine:70 LineCount:50]
Results: map[Contents: 70: * If it returns %0, jffs2_reserve_space() also downs the per-filesystem
71: * allocation semaphore, to prevent more than one allocation from being
72: * active at any time. The semaphore is later released by jffs2_commit_allocation().
73: *
74: * jffs2_reserve_space() may trigger garbage collection in order to make room
75: * for the requested allocation.
76: */
77:
78: int jffs2_reserve_space(struct jffs2_sb_info *c, uint32_t minsize,
79: uint32_t *len, int prio, uint32_t sumsize)
80: {
81: int ret = -EAGAIN;
82: int blocksneeded = c->resv_blocks_write;
83: /* align it */
84: minsize = PAD(minsize);
85:
86: jffs2_dbg(1, "%s(): Requested 0x%x bytes\n", __func__, minsize);
87: mutex_lock(&c->alloc_sem);
88:
89: jffs2_dbg(1, "%s(): alloc sem got\n", __func__);
90:
91: spin_lock(&c->erase_completion_lock);
92:
93: /*
94: * Check if the free space is greater then size of the reserved pool.
95: * If not, only allow root to proceed with writing.
96: */
97: if (prio != ALLOC_DELETION && !jffs2_rp_can_write(c)) {
98: ret = -ENOSPC;
99: goto out;
100: }
101:
102: /* this needs a little more thought (true <tglx> :)) */
103: while(ret == -EAGAIN) {
104: while(c->nr_free_blocks + c->nr_erasing_blocks < blocksneeded) {
105: uint32_t dirty, avail;
106:
107: /* calculate real dirty size
108: * dirty_size contains blocks on erase_pending_list
109: * those blocks are counted in c->nr_erasing_blocks.
110: * If one block is actually erased, it is not longer counted as dirty_space
111: * but it is counted in c->nr_erasing_blocks, so we add it and subtract it
112: * with c->nr_erasing_blocks * c->sector_size again.
113: * Blocks on erasable_list are counted as dirty_size, but not in c->nr_erasing_blocks
114: * This helps us to force gc and pick eventually a clean block to spread the load.
115: * We add unchecked_size here, as we hopefully will find some space to use.
116: * This will affect the sum only once, as gc first finishes checking
117: * of nodes.
118: */
119: dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size + c->unchecked_size;
]
|
| 64/2 |
2026/09/04 07:39 |
llm |
expert |
0m
Model:
Tokens:
input: 45176
output: 41
thoughts: 0
|
| 65/2 |
2026/09/04 07:39 |
tool |
read-file |
0m
Args: map[File:fs/jffs2/nodemgmt.c FirstLine:120 LineCount:50]
Results: map[Contents: 120: if (dirty < c->nospc_dirty_size) {
121: if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) {
122: jffs2_dbg(1, "%s(): Low on dirty space to GC, but it's a deletion. Allowing...\n",
123: __func__);
124: break;
125: }
126: jffs2_dbg(1, "dirty size 0x%08x + unchecked_size 0x%08x < nospc_dirty_size 0x%08x, returning -ENOSPC\n",
127: dirty, c->unchecked_size,
128: c->sector_size);
129:
130: spin_unlock(&c->erase_completion_lock);
131: mutex_unlock(&c->alloc_sem);
132: return -ENOSPC;
133: }
134:
135: /* Calc possibly available space. Possibly available means that we
136: * don't know, if unchecked size contains obsoleted nodes, which could give us some
137: * more usable space. This will affect the sum only once, as gc first finishes checking
138: * of nodes.
139: + Return -ENOSPC, if the maximum possibly available space is less or equal than
140: * blocksneeded * sector_size.
141: * This blocks endless gc looping on a filesystem, which is nearly full, even if
142: * the check above passes.
143: */
144: avail = c->free_size + c->dirty_size + c->erasing_size + c->unchecked_size;
145: if ( (avail / c->sector_size) <= blocksneeded) {
146: if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) {
147: jffs2_dbg(1, "%s(): Low on possibly available space, but it's a deletion. Allowing...\n",
148: __func__);
149: break;
150: }
151:
152: jffs2_dbg(1, "max. available size 0x%08x < blocksneeded * sector_size 0x%08x, returning -ENOSPC\n",
153: avail, blocksneeded * c->sector_size);
154: spin_unlock(&c->erase_completion_lock);
155: mutex_unlock(&c->alloc_sem);
156: return -ENOSPC;
157: }
158:
159: mutex_unlock(&c->alloc_sem);
160:
161: jffs2_dbg(1, "Triggering GC pass. nr_free_blocks %d, nr_erasing_blocks %d, free_size 0x%08x, dirty_size 0x%08x, wasted_size 0x%08x, used_size 0x%08x, erasing_size 0x%08x, bad_size 0x%08x (total 0x%08x of 0x%08x)\n",
162: c->nr_free_blocks, c->nr_erasing_blocks,
163: c->free_size, c->dirty_size, c->wasted_size,
164: c->used_size, c->erasing_size, c->bad_size,
165: c->free_size + c->dirty_size +
166: c->wasted_size + c->used_size +
167: c->erasing_size + c->bad_size,
168: c->flash_size);
169: spin_unlock(&c->erase_completion_lock);
]
|
| 66/2 |
2026/09/04 07:39 |
llm |
expert |
0m
Model:
Tokens:
input: 58612
output: 66
thoughts: 799
Thoughts: **My Analysis of the JFFS2 Vulnerability**
Okay, let's break this down. In `jffs2_reserve_space`, the `jffs2_rp_can_write(c)` check is key. It's essentially the gatekeeper, verifying root privileges or sufficient space. An unprivileged user can hit a snag here if the filesystem is almost full, but they are allowed if space is available. This check then leads to a call to `jffs2_do_reserve_space`. If that function returns `-EAGAIN`, there is a loop.
Here's where it gets interesting: `jffs2_do_reserve_space` is called with `minsize = request` and `sumsize = JFFS2_SUMMARY_XATTR_SIZE`. If `request` is large, that's what triggers the bug. So, yes, an unprivileged user can trigger this condition, even when the initial check permits the write.
**Vulnerability Summary:**
* Exploitable: No.
* Denial Of Service: Yes.
* Accessible From Unprivileged Processes: Yes.
* Accessible From User Namespaces: Yes.
* VM Guest Trigger: No.
* VM Host Trigger in The Confidential Computing Context: No.
* Ethernet Network Trigger: No.
* Other Remote Trigger: No.
* Peripheral Trigger: No.
* Malicious Filesystem Trigger: Yes.
Now, let's dig deeper into the code. I had a hunch and I think I've found it: Is `jffs2_sum_write_sumnode` being skipped if `jeb` is NULL?
In `jffs2_do_reserve_space`: the code has a conditional check:
```c
if (jffs2_sum_active() && (sumsize != JFFS2_SUMMARY_NOSUM_SIZE)) {
if (jeb) {
reserved_size = PAD(sumsize + c->summary->sum_size + JFFS2_SUMMARY_FRAME_SIZE);
}
if (jeb && (PAD(minsize) + PAD(c->summary->sum_size + sumsize +
JFFS2_SUMMARY_FRAME_SIZE) > jeb->free_size)) {
```
If `jeb` is NULL, the check skips this summary block calculation. Where is `jeb` assigned?
```c
struct jffs2_eraseblock *jeb = c->nextblock;
```
Aha! If `c->nextblock` is NULL, it *skips* the summary check and goes to `jffs2_find_nextblock(c)`. This finds the next block.
```c
if (!jeb) {
ret = jffs2_find_nextblock(c);
if (ret)
return ret;
jeb = c->nextblock;
}
```
Then, the code loops back to the `restart:` label!
```c
restart:
reserved_size = 0;
if (jffs2_sum_active() && (sumsize != JFFS2_SUMMARY_NOSUM_SIZE)) {
if (jeb) {
```
Crucially, on the *second* iteration, `jeb` is no longer NULL - it's the *newly* allocated block. The code then checks the condition: `PAD(minsize) + PAD(...) > jeb->free_size`.
Since `jeb` is newly allocated, `jeb->free_size` is calculated from the sector size: `c->sector_size - c->cleanmarker_size`. Now, if `PAD(minsize) + 28 > jeb->free_size`, we trigger the call to `jffs2_sum_write_sumnode(c)`. On a newly allocated block, `c->summary->sum_num` is 0.
That's it! It hits the BUG! This logic is solid. I'm quite confident in this analysis.
|
| 67/2 |
2026/09/04 07:39 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:true NetworkTrigger:false PeripheralTrigger:false RemoteTrigger:false Unprivileged:true UserNamespace:true VMGuestTrigger:false VMHostTrigger:false]
|
| 68/2 |
2026/09/04 07:39 |
llm |
expert |
0m
Model:
Tokens:
input: 47359
output: 502
thoughts: 793
Thoughts: **Analyzing the JFFS2 Filesystem Bug**
Okay, so here's what I've got. There's a `BUG()` in `jffs2_sum_write_sumnode`, specifically in `fs/jffs2/summary.c:868`. The critical check here is:
```c
if (!c->summary->sum_num || !c->summary->sum_list_head) {
JFFS2_WARNING("Empty summary info!!!\n");
BUG();
}
```
Essentially, the code's getting tripped up when it *expects* summary information to be present (i.e., `sum_num` or `sum_list_head` are not zero/NULL) but finds that it's empty. This happens within the context of garbage collection, triggered by `jffs2_reserve_space` called from a write operation. The full call path is `generic_perform_write` -> `jffs2_write_end` -> `jffs2_write_inode_range` -> `jffs2_reserve_space`. Ultimately, it winds up in `jffs2_do_reserve_space` and the problematic conditional statement within that function.
The key thing is that this results in a kernel panic because of the `BUG()` macro. No privilege escalation or information leakage β just a hard kernel halt, a classic Denial of Service. My initial assessment is correct: this is a DoS, not an exploit in the traditional sense.
The big question is, who can trigger it? An unprivileged user can absolutely trigger this. Any write operation on a JFFS2 filesystem could set things in motion, triggering garbage collection, and potentially hitting this bug. Moreover, a malicious JFFS2 filesystem image could be crafted to trigger this scenario on mount, bypassing the need for a user to perform an action on a mounted volume.
Therefore, the exploit scenario is mounting a malicious image or normal filesystem operation.
|
| 69/1 |
2026/09/04 07:40 |
action |
format-explanation |
0m
Results: map[Explanation:**Exploitable:** No
The bug is a `BUG()` macro invocation in `jffs2_sum_write_sumnode()` which is
triggered when the JFFS2 summary information is empty (`!c->summary->sum_num ||
!c->summary->sum_list_head`). Hitting a `BUG()` macro immediately halts the
kernel (or the current task, depending on configuration, but typically panics in
this context). It does not cause memory corruption, use-after-free, or
information leaks, so it cannot be exploited for privilege escalation or
arbitrary code execution.
**Denial of Service:** Yes
Because the bug triggers a `BUG()` macro, it will crash the kernel, resulting in
a complete system Denial of Service (DoS).
**Accessible From Unprivileged Processes:** Yes
The crash is triggered during a standard file write operation
(`generic_perform_write` -> `jffs2_write_end` -> `jffs2_reserve_space` ->
garbage collection). Any unprivileged user with write access to a file on a
JFFS2 filesystem can potentially trigger this bug by writing data that forces
the filesystem into garbage collection under specific conditions.
**Accessible From User Namespaces:** Yes
Since it only requires standard filesystem write access, it is accessible from
within a user namespace, provided the user has access to a mounted JFFS2
filesystem.
**VM Guest Trigger:** No
This is a filesystem-level bug and does not involve KVM guest-to-host escapes or
paravirtualized devices.
**VM Host Trigger in The Confidential Computing Context:** No
This is a filesystem-level bug and does not involve host-to-guest attacks in
confidential computing.
**Ethernet Network Trigger:** No
The bug is in the JFFS2 filesystem and is not reachable via network packet
processing.
**Other Remote Trigger:** No
The bug is not reachable via other remote protocols (Bluetooth, WiFi, etc.).
**Peripheral Trigger:** No
The bug is not triggered by plugging in a malicious peripheral device (unless
the device contains a malicious JFFS2 image that is auto-mounted).
**Malicious Filesystem Trigger:** Yes
The bug can be triggered by mounting a maliciously crafted JFFS2 filesystem
image and interacting with it (e.g., writing to it), which forces the filesystem
into the inconsistent state that triggers the `BUG()`.]
|