| 0/0 |
2026/09/11 00:20 |
flow |
assessment-security |
2m
Error:
|
| 1/1 |
2026/09/11 00:20 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_mkdirat
#define __NR_mkdirat 323
#endif
#ifndef __NR_mmap
#define __NR_mmap 192
#endif
#ifndef __NR_mount
#define __NR_mount 21
#endif
#ifndef __NR_openat
#define __NR_openat 322
#endif
#ifndef __NR_write
#define __NR_write 4
#endif
#undef __NR_mmap
#define __NR_mmap __NR_mmap2
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffff000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32, /*fd=*/(intptr_t)-1, /*offset=*/0);
syscall(__NR_mmap, /*addr=*/0x20000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32, /*fd=*/(intptr_t)-1, /*offset=*/0);
syscall(__NR_mmap, /*addr=*/0x21000000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32, /*fd=*/(intptr_t)-1, /*offset=*/0);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// mkdirat arguments: [
// fd: fd_dir (resource)
// path: ptr[in, buffer] {
// buffer: {2e 2f 73 79 73 00} (length 0x6)
// }
// mode: open_mode = 0x1ff (4 bytes)
// ]
memcpy((void*)0x20000000, "./sys\000", 6);
syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x20000000, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/0x1ff);
// mount arguments: [
// src: nil
// dst: ptr[in, buffer] {
// buffer: {2e 2f 73 79 73 00} (length 0x6)
// }
// type: ptr[in, buffer] {
// buffer: {73 79 73 66 73 00} (length 0x6)
// }
// flags: mount_flags = 0x0 (4 bytes)
// data: nil
// ]
memcpy((void*)0x20000000, "./sys\000", 6);
memcpy((void*)0x20000100, "sysfs\000", 6);
syscall(__NR_mount, /*src=*/0, /*dst=*/0x20000000, /*type=*/0x20000100, /*flags=*/0, /*data=*/0);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 73 79 73 2f 62 6c 6f 63 6b 2f 7a 72 61 6d 30 2f 64 69 73 6b 73 69 7a 65 00} (length 0x1b)
// }
// flags: open_flags = 0x1 (4 bytes)
// mode: open_mode = 0x0 (2 bytes)
// ]
// returns fd
memcpy((void*)0x20000400, "./sys/block/zram0/disksize\000", 27);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000400, /*flags=O_WRONLY*/1, /*mode=*/0);
if (res != -1)
r[0] = res;
// write arguments: [
// fd: fd (resource)
// buf: ptr[in, buffer] {
// buffer: {31 45} (length 0x2)
// }
// count: len = 0x2 (4 bytes)
// ]
memcpy((void*)0x20000140, "1E", 2);
syscall(__NR_write, /*fd=*/(intptr_t)r[0], /*buf=*/0x20000140, /*count=*/2);
return 0;
}
]
|
| 2/1 |
2026/09/11 00:20 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/2be1aeb1f5ee0ceace15b0e71b019d9d3c2b9a13]
|
| 3/1 |
2026/09/11 00:20 |
action |
kernel-builder |
0m
Results: map[KernelObj:/app/workdir/cache/build/299bfa966caf8fd5149fd16429dbaea1fdefc0d2]
|
| 4/1 |
2026/09/11 00:20 |
action |
codesearch-prepare |
0m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/09/11 00:21 |
agent |
expert |
2m
Model:
Error:
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:
------------[ cut here ]------------
WARNING: mm/vmalloc.c:4037 at __vmalloc_node_range_noprof+0x610/0x6a4 mm/vmalloc.c:4037, CPU#1: syz.2.17/4039
Modules linked in:
Kernel panic - not syncing: kernel: panic_on_warn set ...
CPU: 1 UID: 0 PID: 4039 Comm: syz.2.17 Not tainted syzkaller #0 PREEMPT
Hardware name: ARM-Versatile Express
Call trace:
[<80201998>] (dump_backtrace) from [<80201a8c>] (show_stack+0x18/0x1c arch/arm/kernel/traps.c:257)
r7:82a20f78 r6:00000000 r5:82336570 r4:00000001
[<80201a74>] (show_stack) from [<8021ec68>] (__dump_stack lib/dump_stack.c:94 [inline])
[<80201a74>] (show_stack) from [<8021ec68>] (dump_stack_lvl+0x5c/0x70 lib/dump_stack.c:120)
[<8021ec0c>] (dump_stack_lvl) from [<8021ec94>] (dump_stack+0x18/0x1c lib/dump_stack.c:129)
r7:82a20f78 r6:00000000 r5:8400bd40 r4:82c85d40
[<8021ec7c>] (dump_stack) from [<80202590>] (vpanic+0x114/0x320 kernel/panic.c:651)
[<8020247c>] (vpanic) from [<802027d0>] (trace_suspend_resume+0x0/0x100 kernel/panic.c:788)
r7:805241d4
[<8020279c>] (panic) from [<80251b50>] (check_panic_on_warn kernel/panic.c:525 [inline])
[<8020279c>] (panic) from [<80251b50>] (get_taint+0x0/0x1c kernel/panic.c:520)
r3:82a0b144 r2:00000001 r1:8231c298 r0:82323c10
[<80251ad8>] (check_panic_on_warn) from [<80251ccc>] (__warn+0x98/0x1a4 kernel/panic.c:1104)
[<80251c34>] (__warn) from [<80251f50>] (warn_slowpath_fmt+0x178/0x1f4 kernel/panic.c:1136)
r8:00000009 r7:82352930 r6:ea3e5d4c r5:8400bd40 r4:00000000
[<80251ddc>] (warn_slowpath_fmt) from [<805241d4>] (__vmalloc_node_range_noprof+0x610/0x6a4 mm/vmalloc.c:4037)
r10:ffffffff r9:ff800000 r8:00000dc0 r7:00000002 r6:10000000 r5:df800000
r4:00000000
[<80523bc4>] (__vmalloc_node_range_noprof) from [<805244d0>] (__vmalloc_node_noprof mm/vmalloc.c:4165 [inline])
[<80523bc4>] (__vmalloc_node_range_noprof) from [<805244d0>] (vzalloc_noprof+0x6c/0x74 mm/vmalloc.c:4243)
r10:84c4bf10 r9:00000000 r8:84142564 r7:00000002 r6:10000000 r5:84142540
r4:00000000
[<80524464>] (vzalloc_noprof) from [<80c2086c>] (zram_meta_alloc drivers/block/zram/zram_drv.c:1990 [inline])
[<80524464>] (vzalloc_noprof) from [<80c2086c>] (disksize_store+0x80/0x1dc drivers/block/zram/zram_drv.c:2880)
r4:00000000
[<80c207ec>] (disksize_store) from [<80bd68c0>] (dev_attr_store+0x1c/0x28 drivers/base/core.c:2505)
r10:84c4bf10 r9:00000000 r8:83578078 r7:86433dc0 r6:81d5b598 r5:80bd68a4
r4:80c207ec r3:00000002
[<80bd68a4>] (dev_attr_store) from [<8067e3b4>] (sysfs_kf_write+0x70/0x7c fs/sysfs/file.c:145)
r5:80bd68a4 r4:00000002
[<8067e344>] (sysfs_kf_write) from [<8067c450>] (kernfs_fop_write_iter+0x134/0x214 fs/kernfs/file.c:345)
r9:00000000 r8:00000000 r7:ea3e5f08 r6:84c4bf00 r5:00000002 r4:86433dc0
[<8067c31c>] (kernfs_fop_write_iter) from [<805a1390>] (new_sync_write fs/read_write.c:595 [inline])
[<8067c31c>] (kernfs_fop_write_iter) from [<805a1390>] (vfs_write fs/read_write.c:687 [inline])
[<8067c31c>] (kernfs_fop_write_iter) from [<805a1390>] (vfs_write+0x27c/0x42c fs/read_write.c:667)
r10:81c2d60c r9:8400bd40 r8:8067c31c r7:ea3e5f68 r6:20000140 r5:85cfc800
r4:00000002
[<805a1114>] (vfs_write) from [<805a16b4>] (ksys_write+0x74/0xec fs/read_write.c:739)
r10:00000004 r9:8400bd40 r8:8020029c r7:00000000 r6:00000000 r5:85cfc800
r4:85cfc800
[<805a1640>] (ksys_write) from [<805a173c>] (__do_sys_write fs/read_write.c:750 [inline])
[<805a1640>] (ksys_write) from [<805a173c>] (sys_write+0x10/0x14 fs/read_write.c:747)
r7:00000004 r6:00356310 r5:00000000 r4:00000000
[<805a172c>] (sys_write) from [<80200060>] (ret_fast_syscall+0x0/0x1c arch/arm/mm/proc-v7.S:67)
Exception stack(0xea3e5fa8 to 0xea3e5ff0)
5fa0: 00000000 00000000 00000003 20000140 00000002 00000000
5fc0: 00000000 00000000 00356310 00000004 003562d8 00000000 00000008 00000000
5fe0: 7eb047a0 7eb04790 00018fa0 00130a50
Rebooting in 86400 seconds..
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#ifndef __NR_mkdirat
#define __NR_mkdirat 323
#endif
#ifndef __NR_mmap
#define __NR_mmap 192
#endif
#ifndef __NR_mount
#define __NR_mount 21
#endif
#ifndef __NR_openat
#define __NR_openat 322
#endif
#ifndef __NR_write
#define __NR_write 4
#endif
#undef __NR_mmap
#define __NR_mmap __NR_mmap2
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffff000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32, /*fd=*/(intptr_t)-1, /*offset=*/0);
syscall(__NR_mmap, /*addr=*/0x20000000, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32, /*fd=*/(intptr_t)-1, /*offset=*/0);
syscall(__NR_mmap, /*addr=*/0x21000000, /*len=*/0x1000, /*prot=*/0, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32, /*fd=*/(intptr_t)-1, /*offset=*/0);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// mkdirat arguments: [
// fd: fd_dir (resource)
// path: ptr[in, buffer] {
// buffer: {2e 2f 73 79 73 00} (length 0x6)
// }
// mode: open_mode = 0x1ff (4 bytes)
// ]
memcpy((void*)0x20000000, "./sys\000", 6);
syscall(__NR_mkdirat, /*fd=*/0xffffff9c, /*path=*/0x20000000, /*mode=S_IXOTH|S_IWOTH|S_IROTH|S_IXGRP|S_IWGRP|S_IRGRP|S_IXUSR|S_IWUSR|0x100*/0x1ff);
// mount arguments: [
// src: nil
// dst: ptr[in, buffer] {
// buffer: {2e 2f 73 79 73 00} (length 0x6)
// }
// type: ptr[in, buffer] {
// buffer: {73 79 73 66 73 00} (length 0x6)
// }
// flags: mount_flags = 0x0 (4 bytes)
// data: nil
// ]
memcpy((void*)0x20000000, "./sys\000", 6);
memcpy((void*)0x20000100, "sysfs\000", 6);
syscall(__NR_mount, /*src=*/0, /*dst=*/0x20000000, /*type=*/0x20000100, /*flags=*/0, /*data=*/0);
// openat arguments: [
// fd: fd_dir (resource)
// file: ptr[in, buffer] {
// buffer: {2e 2f 73 79 73 2f 62 6c 6f 63 6b 2f 7a 72 61 6d 30 2f 64 69 73 6b 73 69 7a 65 00} (length 0x1b)
// }
// flags: open_flags = 0x1 (4 bytes)
// mode: open_mode = 0x0 (2 bytes)
// ]
// returns fd
memcpy((void*)0x20000400, "./sys/block/zram0/disksize\000", 27);
res = syscall(__NR_openat, /*fd=*/0xffffff9c, /*file=*/0x20000400, /*flags=O_WRONLY*/1, /*mode=*/0);
if (res != -1)
r[0] = res;
// write arguments: [
// fd: fd (resource)
// buf: ptr[in, buffer] {
// buffer: {31 45} (length 0x2)
// }
// count: len = 0x2 (4 bytes)
// ]
memcpy((void*)0x20000140, "1E", 2);
syscall(__NR_write, /*fd=*/(intptr_t)r[0], /*buf=*/0x20000140, /*count=*/2);
return 0;
}
|
| 6/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 9952
output: 25
thoughts: 157
Thoughts: **Investigating a Kernel Warning**
Okay, so I've got a kernel warning pointing me right at `mm/vmalloc.c:4037` within `__vmalloc_node_range_noprof`. That's not ideal, but at least I know exactly where to start. The call trace is interesting – let's break it down: `__vmalloc_node_range_noprof` leads to `__vmalloc_node_noprof`, which then calls `vzalloc_noprof`. From there, it dives into `zram_meta_alloc`, subsequently going through `disksize_store`, then `dev_attr_store`, and then `sysfs_kf_write`. That then calls `kernfs_fop_write_iter`, which calls `vfs_write`, eventually hitting `ksys_write` and, finally, `sys_write`. That's a pretty standard path for a write operation ultimately. This looks like a write operation that is trying to allocate memory through `vmalloc`, which is obviously what's giving me grief. Time to take a closer look at the code at `mm/vmalloc.c:4037` and see what the heck is going on there.
|
| 7/2 |
2026/09/11 00:21 |
tool |
grepper |
0m
Args: map[Expression:__vmalloc_node_range_noprof]
Results: map[Output:include/linux/vmalloc.h=171=extern void *__vmalloc_noprof(unsigned long size, gfp_t gfp_mask) __alloc_size(1);
--
include/linux/vmalloc.h-173-
include/linux/vmalloc.h:174:extern void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
include/linux/vmalloc.h-175- unsigned long start, unsigned long end, gfp_t gfp_mask,
--
include/linux/vmalloc.h-177- const void *caller) __alloc_size(1);
include/linux/vmalloc.h:178:#define __vmalloc_node_range(...) alloc_hooks(__vmalloc_node_range_noprof(__VA_ARGS__))
include/linux/vmalloc.h-179-
--
mm/nommu.c=122=void *vrealloc_node_align_noprof(const void *p, size_t size, unsigned long align,
--
mm/nommu.c-127-
mm/nommu.c:128:void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
mm/nommu.c-129- unsigned long start, unsigned long end, gfp_t gfp_mask,
--
mm/slub.c=6890=void *__kvmalloc_node_noprof(DECL_KMALLOC_PARAMS(size, b, token), unsigned long align,
--
mm/slub.c-6932- */
mm/slub.c:6933: return __vmalloc_node_range_noprof(size, align, VMALLOC_START, VMALLOC_END,
mm/slub.c-6934- flags, PAGE_KERNEL, allow_block ? VM_ALLOW_HUGE_VMAP:0,
--
mm/vmalloc.c=3865=static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
--
mm/vmalloc.c-3910- *
mm/vmalloc.c:3911: * Please note, the __vmalloc_node_range_noprof() falls-back
mm/vmalloc.c-3912- * to order-0 pages if high-order attempt is unsuccessful.
--
mm/vmalloc.c=3980=static gfp_t vmalloc_fix_flags(gfp_t flags)
--
mm/vmalloc.c-4024- */
mm/vmalloc.c:4025:void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
mm/vmalloc.c-4026- unsigned long start, unsigned long end, gfp_t gfp_mask,
--
mm/vmalloc.c-4157- * Semantics of @gfp_mask (including reclaim/retry modifiers such as
mm/vmalloc.c:4158: * __GFP_NOFAIL) are the same as in __vmalloc_node_range_noprof().
mm/vmalloc.c-4159- *
--
mm/vmalloc.c=4162=void *__vmalloc_node_noprof(unsigned long size, unsigned long align,
--
mm/vmalloc.c-4164-{
mm/vmalloc.c:4165: return __vmalloc_node_range_noprof(size, align, VMALLOC_START, VMALLOC_END,
mm/vmalloc.c-4166- gfp_mask, PAGE_KERNEL, 0, node, caller);
--
mm/vmalloc.c=4218=void *vmalloc_huge_node_noprof(unsigned long size, gfp_t gfp_mask, int node)
--
mm/vmalloc.c-4221- gfp_mask = vmalloc_fix_flags(gfp_mask);
mm/vmalloc.c:4222: return __vmalloc_node_range_noprof(size, 1, VMALLOC_START, VMALLOC_END,
mm/vmalloc.c-4223- gfp_mask, PAGE_KERNEL, VM_ALLOW_HUGE_VMAP,
--
mm/vmalloc.c=4257=void *vmalloc_user_noprof(unsigned long size)
mm/vmalloc.c-4258-{
mm/vmalloc.c:4259: return __vmalloc_node_range_noprof(size, SHMLBA, VMALLOC_START, VMALLOC_END,
mm/vmalloc.c-4260- GFP_KERNEL | __GFP_ZERO, PAGE_KERNEL,
--
mm/vmalloc.c=4504=void *vmalloc_32_user_noprof(unsigned long size)
mm/vmalloc.c-4505-{
mm/vmalloc.c:4506: return __vmalloc_node_range_noprof(size, SHMLBA, VMALLOC_START, VMALLOC_END,
mm/vmalloc.c-4507- GFP_VMALLOC32 | __GFP_ZERO, PAGE_KERNEL,
]
|
| 8/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 11717
output: 35
thoughts: 20
Thoughts: Here's a summary of my thought process:
**Diving into the Memory Allocation Plumbing**
Okay, time to get my hands dirty. I need to take a look at the `mm/vmalloc.c` file. Specifically, I'm going to start my investigation around line 4037. That's usually a good spot to begin when troubleshooting or understanding how vmalloc works, because of the interactions in the `_vm_area_alloc` and `__vm_area_alloc` functions. I'll be looking for clues there.
|
| 9/2 |
2026/09/11 00:21 |
tool |
read-file |
0m
Args: map[File:mm/vmalloc.c FirstLine:4025 LineCount:50]
Results: map[Contents:4025: void *__vmalloc_node_range_noprof(unsigned long size, unsigned long align,
4026: unsigned long start, unsigned long end, gfp_t gfp_mask,
4027: pgprot_t prot, unsigned long vm_flags, int node,
4028: const void *caller)
4029: {
4030: struct vm_struct *area;
4031: void *ret;
4032: kasan_vmalloc_flags_t kasan_flags = KASAN_VMALLOC_NONE;
4033: unsigned long original_align = align;
4034: unsigned int shift = PAGE_SHIFT;
4035: bool skip_vmalloc_kasan = kasan_hw_tags_enabled() && (gfp_mask & __GFP_SKIP_KASAN);
4036:
4037: if (WARN_ON_ONCE(!size))
4038: return NULL;
4039:
4040: if ((size >> PAGE_SHIFT) > totalram_pages()) {
4041: warn_alloc(gfp_mask, NULL,
4042: "vmalloc error: size %lu, exceeds total pages",
4043: size);
4044: return NULL;
4045: }
4046:
4047: if (vmap_allow_huge && (vm_flags & VM_ALLOW_HUGE_VMAP)) {
4048: /*
4049: * Try huge pages. Only try for PAGE_KERNEL allocations,
4050: * others like modules don't yet expect huge pages in
4051: * their allocations due to apply_to_page_range not
4052: * supporting them.
4053: */
4054:
4055: if (arch_vmap_pmd_supported(prot) && size >= PMD_SIZE)
4056: shift = PMD_SHIFT;
4057: else
4058: shift = arch_vmap_pte_supported_shift(size);
4059:
4060: align = max(original_align, 1UL << shift);
4061: }
4062:
4063: again:
4064: area = __get_vm_area_node(size, align, shift, VM_ALLOC |
4065: VM_UNINITIALIZED | vm_flags, start, end, node,
4066: gfp_mask & ~__GFP_SKIP_KASAN, caller);
4067: if (!area) {
4068: bool nofail = gfp_mask & __GFP_NOFAIL;
4069: warn_alloc(gfp_mask, NULL,
4070: "vmalloc error: size %lu, vm_struct allocation failed%s",
4071: size, (nofail) ? ". Retrying." : "");
4072: if (nofail) {
4073: schedule_timeout_uninterruptible(1);
4074: goto again;
]
|
| 10/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 12724
output: 20
thoughts: 118
Thoughts: **Investigating a Potential Zero-Size Allocation in zram**
Okay, so I've got this warning popping up, specifically at `mm/vmalloc.c:4037`, with the code `if (WARN_ON_ONCE(!size))`. That's a classic sign – `size` is getting passed as zero, which is definitely not what we want.
Looking at the call stack, it seems to be originating from `zram_meta_alloc`, going through `vzalloc_noprof`, then down to `__vmalloc_node_noprof`, and finally to `__vmalloc_node_range_noprof`. Right, so the root cause is most likely within `zram_meta_alloc` itself, as that is the first point in the call stack related to the ZRAM driver. I'll need to dig into `drivers/block/zram/zram_drv.c` and figure out what's going on with the memory allocation there. I'll need to check the logic around how the `size` parameter is being calculated or passed to the allocation function. A zero-size allocation is usually a bug; it's a sign that we're missing an edge case, have a logic error, or maybe a calculation is wrong. Time to get to the code!
|
| 11/2 |
2026/09/11 00:21 |
tool |
grepper |
0m
Args: map[Expression:zram_meta_alloc]
Results: map[Output:drivers/block/zram/zram_drv.c=1968=static void zram_meta_free(struct zram *zram, u64 disksize)
--
drivers/block/zram/zram_drv.c-1984-
drivers/block/zram/zram_drv.c:1985:static bool zram_meta_alloc(struct zram *zram, u64 disksize)
drivers/block/zram/zram_drv.c-1986-{
--
drivers/block/zram/zram_drv.c=2860=static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
--
drivers/block/zram/zram_drv.c-2879- disksize = PAGE_ALIGN(disksize);
drivers/block/zram/zram_drv.c:2880: if (!zram_meta_alloc(zram, disksize))
drivers/block/zram/zram_drv.c-2881- return -ENOMEM;
]
|
| 12/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 13423
output: 42
thoughts: 19
Thoughts: Here's my take on those thoughts:
**Analyzing `zram_meta_alloc` and `disksize_store`**
Okay, time to dive in. I need to make sure I'm solid on these two, `zram_meta_alloc` and `disksize_store`. These are critical for understanding how our ZRAM implementation is behaving. I need to check both the allocation and sizing mechanisms. Is the metadata allocation behaving as expected? Are there any potential bottlenecks there? What about `disksize_store`? Is the disk size being stored consistently and correctly? Are there any potential race conditions I need to be aware of? I'll probably start with the allocation logic, trace through the code, and make sure memory management and error handling are robust. Then, I'll move on to storage. I need to review any recent changes to those specific functions, cross-reference with the latest performance data, and verify that things are working as planned, especially under load. This will reveal if any problems are present.
|
| 13/2 |
2026/09/11 00:21 |
tool |
read-file |
0m
Args: map[File:drivers/block/zram/zram_drv.c FirstLine:1985 LineCount:50]
Results: map[Contents:1985: static bool zram_meta_alloc(struct zram *zram, u64 disksize)
1986: {
1987: size_t num_pages, index;
1988:
1989: num_pages = disksize >> PAGE_SHIFT;
1990: zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
1991: if (!zram->table)
1992: return false;
1993:
1994: zram->mem_pool = zs_create_pool(zram->disk->disk_name);
1995: if (!zram->mem_pool) {
1996: vfree(zram->table);
1997: zram->table = NULL;
1998: return false;
1999: }
2000:
2001: if (!huge_class_size)
2002: huge_class_size = zs_huge_class_size(zram->mem_pool);
2003:
2004: for (index = 0; index < num_pages; index++)
2005: slot_lock_init(zram, index);
2006:
2007: return true;
2008: }
2009:
2010: static void slot_free(struct zram *zram, u32 index)
2011: {
2012: unsigned long handle;
2013:
2014: #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
2015: zram->table[index].attr.ac_time = 0;
2016: #endif
2017:
2018: clear_slot_flag(zram, index, ZRAM_IDLE);
2019: clear_slot_flag(zram, index, ZRAM_INCOMPRESSIBLE);
2020: clear_slot_flag(zram, index, ZRAM_PP_SLOT);
2021: set_slot_comp_priority(zram, index, 0);
2022:
2023: if (test_slot_flag(zram, index, ZRAM_HUGE)) {
2024: /*
2025: * Writeback completion decrements ->huge_pages but keeps
2026: * ZRAM_HUGE flag for deferred decompression path.
2027: */
2028: if (!test_slot_flag(zram, index, ZRAM_WB))
2029: atomic64_dec(&zram->stats.huge_pages);
2030: clear_slot_flag(zram, index, ZRAM_HUGE);
2031: }
2032:
2033: if (test_slot_flag(zram, index, ZRAM_WB)) {
2034: clear_slot_flag(zram, index, ZRAM_WB);
]
|
| 14/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 14505
output: 42
thoughts: 83
Thoughts: **My Initial Analysis of `zram_meta_alloc`**
Okay, so I'm looking at `zram_meta_alloc`, and the first thing that jumps out is how the allocation is handled. Specifically, it's calculating `num_pages` by right-shifting `disksize` by `PAGE_SHIFT`. That's standard stuff for determining the number of pages, but then the allocation happens with `vzalloc` using `array_size` based on this `num_pages`.
The concerning thing is that if `disksize` happens to be small, and I mean really small, then `num_pages` could become zero. If that's the case, we'd be trying to allocate an array of zero-length, which could lead to… well, undefined behavior, or possibly a very subtle bug down the line. I want to check how the code deals with this possible issue. It's time to investigate how `disksize` itself is determined and what constraints are put on it. Let's dig into `disksize_store`.
|
| 15/2 |
2026/09/11 00:21 |
tool |
read-file |
0m
Args: map[File:drivers/block/zram/zram_drv.c FirstLine:2860 LineCount:50]
Results: map[Contents:2860: static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
2861: const char *buf, size_t len)
2862: {
2863: u64 disksize;
2864: struct zcomp *comp;
2865: struct zram *zram = dev_to_zram(dev);
2866: int err;
2867: u32 prio;
2868:
2869: disksize = memparse(buf, NULL);
2870: if (!disksize)
2871: return -EINVAL;
2872:
2873: guard(rwsem_write)(&zram->dev_lock);
2874: if (init_done(zram)) {
2875: pr_info("Cannot change disksize for initialized device\n");
2876: return -EBUSY;
2877: }
2878:
2879: disksize = PAGE_ALIGN(disksize);
2880: if (!zram_meta_alloc(zram, disksize))
2881: return -ENOMEM;
2882:
2883: for (prio = ZRAM_PRIMARY_COMP; prio < ZRAM_MAX_COMPS; prio++) {
2884: if (!zram->comp_algs[prio])
2885: continue;
2886:
2887: comp = zcomp_create(zram->comp_algs[prio],
2888: &zram->params[prio]);
2889: if (IS_ERR(comp)) {
2890: pr_err("Cannot initialise %s compressing backend\n",
2891: zram->comp_algs[prio]);
2892: err = PTR_ERR(comp);
2893: goto out_free_comps;
2894: }
2895:
2896: zram->comps[prio] = comp;
2897: }
2898: zram->disksize = disksize;
2899: set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT);
2900:
2901: return len;
2902:
2903: out_free_comps:
2904: zram_destroy_comps(zram);
2905: zram_meta_free(zram, disksize);
2906: return err;
2907: }
2908:
2909: static ssize_t reset_store(struct device *dev,
]
|
| 16/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 15599
output: 16
thoughts: 199
Thoughts: **Analyzing the `disksize_store` Function**
Okay, so I'm looking at this `disksize_store` function, and it seems like it's responsible for setting the disk size for a zram block device. The code first tries to parse the input buffer `buf` into a size using `memparse`. Now, if I understand this correctly, `memparse` should be able to handle suffixes like "K", "M", "G", etc., which are common for memory sizes.
However, a potential issue jumps out at me. If the input is something small, like, say, "1E", which might be the equivalent of 30 bytes, the code then aligns the disk size to a page boundary using `PAGE_ALIGN`. So, after the parse, `disksize` becomes 30. Then `PAGE_ALIGN(30)` would result in a value equal to `PAGE_SIZE`, which is 4096.
But wait, the reproducer uses "1E" to set the disk size via `/sys/block/zram0/disksize`. If `memparse` sees "1E", it would parse the "1" and then fail on the invalid "E" suffix, making `disksize` equal to 30. This seems wrong. It seems like the suffix is getting misparsed. I should definitely double-check the `memparse` function documentation and implementation to see what's really happening with that "E".
|
| 17/2 |
2026/09/11 00:21 |
tool |
grepper |
0m
Args:
Results: map[Output:
Full output is too long, showing 500 out of 927 lines.
Use more precise expression if possible.
Documentation/dev-tools/checkpatch.rst=1087=Spacing and Brackets
--
Documentation/dev-tools/checkpatch.rst-1164- char *linux_banner;
Documentation/dev-tools/checkpatch.rst:1165: unsigned long long memparse(char *ptr, char **retptr);
Documentation/dev-tools/checkpatch.rst-1166- char *match_strdup(substring_t *s);
--
Documentation/process/coding-style.rst=265=adjacent to the type name. Examples:
--
Documentation/process/coding-style.rst-270- char *linux_banner;
Documentation/process/coding-style.rst:271: unsigned long long memparse(char *ptr, char **retptr);
Documentation/process/coding-style.rst-272- char *match_strdup(substring_t *s);
--
Documentation/translations/it_IT/process/coding-style.rst=278=variabile o della funzione, e non adiacente al nome del tipo. Esempi:
--
Documentation/translations/it_IT/process/coding-style.rst-283- char *linux_banner;
Documentation/translations/it_IT/process/coding-style.rst:284: unsigned long long memparse(char *ptr, char **retptr);
Documentation/translations/it_IT/process/coding-style.rst-285- char *match_strdup(substring_t *s);
--
Documentation/translations/sp_SP/process/coding-style.rst=275=función y no junto al nombre del tipo. Ejemplos:
--
Documentation/translations/sp_SP/process/coding-style.rst-280- char *linux_banner;
Documentation/translations/sp_SP/process/coding-style.rst:281: unsigned long long memparse(char *ptr, char **retptr);
Documentation/translations/sp_SP/process/coding-style.rst-282- char *match_strdup(substring_t *s);
--
Documentation/translations/zh_CN/process/coding-style.rst=219=Linux 内核的空格使用方式 (主要) 取决于它是用于函数还是关键字。(大多数) 关键字
--
Documentation/translations/zh_CN/process/coding-style.rst-247- char *linux_banner;
Documentation/translations/zh_CN/process/coding-style.rst:248: unsigned long long memparse(char *ptr, char **retptr);
Documentation/translations/zh_CN/process/coding-style.rst-249- char *match_strdup(substring_t *s);
--
Documentation/translations/zh_TW/process/coding-style.rst=222=Linux 內核的空格使用方式 (主要) 取決於它是用於函數還是關鍵字。(大多數) 關鍵字
--
Documentation/translations/zh_TW/process/coding-style.rst-250- char *linux_banner;
Documentation/translations/zh_TW/process/coding-style.rst:251: unsigned long long memparse(char *ptr, char **retptr);
Documentation/translations/zh_TW/process/coding-style.rst-252- char *match_strdup(substring_t *s);
--
arch/arc/mm/init.c=40=static int __init setup_mem_sz(char *str)
arch/arc/mm/init.c-41-{
arch/arc/mm/init.c:42: low_mem_sz = memparse(str, NULL) & PAGE_MASK;
arch/arc/mm/init.c-43-
--
arch/arm/kernel/setup.c=826=static int __init early_mem(char *p)
--
arch/arm/kernel/setup.c-844- start = PHYS_OFFSET;
arch/arm/kernel/setup.c:845: size = memparse(p, &endp);
arch/arm/kernel/setup.c-846- if (*endp == '@')
arch/arm/kernel/setup.c:847: start = memparse(endp + 1, NULL);
arch/arm/kernel/setup.c-848-
--
arch/arm/mm/dma-mapping.c=190=static int __init early_coherent_pool(char *p)
arch/arm/mm/dma-mapping.c-191-{
arch/arm/mm/dma-mapping.c:192: atomic_pool_size = memparse(p, &p);
arch/arm/mm/dma-mapping.c-193- return 0;
--
arch/arm/mm/mmu.c=1153=static int __init early_vmalloc(char *arg)
arch/arm/mm/mmu.c-1154-{
arch/arm/mm/mmu.c:1155: unsigned long vmalloc_reserve = memparse(arg, NULL);
arch/arm/mm/mmu.c-1156- unsigned long vmalloc_max;
--
arch/arm64/mm/init.c=181=static int __init early_mem(char *p)
--
arch/arm64/mm/init.c-185-
arch/arm64/mm/init.c:186: memory_limit = memparse(p, &p) & PAGE_MASK;
arch/arm64/mm/init.c-187- pr_notice("Memory limited to %lldMB\n", memory_limit >> 20);
--
arch/hexagon/mm/init.c=89=static int __init early_mem(char *p)
--
arch/hexagon/mm/init.c-93-
arch/hexagon/mm/init.c:94: size = memparse(p, &endp);
arch/hexagon/mm/init.c-95-
--
arch/loongarch/kernel/relocate.c=225=static unsigned long __init determine_initrd_address(unsigned long *size)
--
arch/loongarch/kernel/relocate.c-241- p += key_length;
arch/loongarch/kernel/relocate.c:242: start = memparse(p, &endp);
arch/loongarch/kernel/relocate.c-243- if (*endp == ',')
arch/loongarch/kernel/relocate.c:244: *size = memparse(endp + 1, NULL);
arch/loongarch/kernel/relocate.c-245- }
--
arch/loongarch/kernel/setup.c=191=static int __init early_parse_mem(char *p)
--
arch/loongarch/kernel/setup.c-200- start = 0;
arch/loongarch/kernel/setup.c:201: size = memparse(p, &p);
arch/loongarch/kernel/setup.c-202- if (*p == '@') /* Every mem=... should contain '@' */
arch/loongarch/kernel/setup.c:203: start = memparse(p + 1, &p);
arch/loongarch/kernel/setup.c-204- else { /* Only one mem=... is allowed if no '@' */
--
arch/m68k/atari/stram.c=52=static int __init atari_stram_setup(char *arg)
--
arch/m68k/atari/stram.c-56-
arch/m68k/atari/stram.c:57: pool_size = memparse(arg, NULL);
arch/m68k/atari/stram.c-58- return 0;
--
arch/microblaze/mm/init.c=119=static void __init mm_cmdline_setup(void)
--
arch/microblaze/mm/init.c-127- p += 4;
arch/microblaze/mm/init.c:128: maxmem = memparse(p, &p);
arch/microblaze/mm/init.c-129- if (maxmem && memory_size > maxmem) {
--
arch/mips/cavium-octeon/setup.c=659=void __init prom_init(void)
--
arch/mips/cavium-octeon/setup.c-859- if (arg) {
arch/mips/cavium-octeon/setup.c:860: max_memory = memparse(arg + 4, &p);
arch/mips/cavium-octeon/setup.c-861- if (max_memory == 0)
--
arch/mips/cavium-octeon/setup.c-863- if (*p == '@')
arch/mips/cavium-octeon/setup.c:864: reserve_low_mem = memparse(p + 1, &p);
arch/mips/cavium-octeon/setup.c-865- }
--
arch/mips/cavium-octeon/setup.c-873- (strncmp(arg, "mem=", 4) == 0)) {
arch/mips/cavium-octeon/setup.c:874: max_memory = memparse(arg + 4, &p);
arch/mips/cavium-octeon/setup.c-875- if (max_memory == 0)
--
arch/mips/cavium-octeon/setup.c-877- if (*p == '@')
arch/mips/cavium-octeon/setup.c:878: reserve_low_mem = memparse(p + 1, &p);
arch/mips/cavium-octeon/setup.c-879-#ifdef CONFIG_KEXEC
arch/mips/cavium-octeon/setup.c-880- } else if (strncmp(arg, "crashkernel=", 12) == 0) {
arch/mips/cavium-octeon/setup.c:881: crashk_size = memparse(arg+12, &p);
arch/mips/cavium-octeon/setup.c-882- if (*p == '@')
arch/mips/cavium-octeon/setup.c:883: crashk_base = memparse(p+1, &p);
arch/mips/cavium-octeon/setup.c-884- strcat(arcs_cmdline, " ");
--
arch/mips/generic/yamon-dt.c=75=__init int yamon_dt_append_memory(void *fdt,
--
arch/mips/generic/yamon-dt.c-114-
arch/mips/generic/yamon-dt.c:115: memsize = memparse(var + strlen(param_name), NULL);
arch/mips/generic/yamon-dt.c-116- }
--
arch/mips/kernel/setup.c=122=static int __init rd_start_early(char *p)
arch/mips/kernel/setup.c-123-{
arch/mips/kernel/setup.c:124: unsigned long start = memparse(p, &p);
arch/mips/kernel/setup.c-125-
--
arch/mips/kernel/setup.c=137=static int __init rd_size_early(char *p)
arch/mips/kernel/setup.c-138-{
arch/mips/kernel/setup.c:139: initrd_end += memparse(p, &p);
arch/mips/kernel/setup.c-140- return 0;
--
arch/mips/kernel/setup.c=346=static int __init early_parse_mem(char *p)
--
arch/mips/kernel/setup.c-365- start = 0;
arch/mips/kernel/setup.c:366: size = memparse(p, &p);
arch/mips/kernel/setup.c-367- if (*p == '@')
arch/mips/kernel/setup.c:368: start = memparse(p + 1, &p);
arch/mips/kernel/setup.c-369-
--
arch/mips/kernel/setup.c=379=static int __init early_parse_memmap(char *p)
--
arch/mips/kernel/setup.c-392- oldp = p;
arch/mips/kernel/setup.c:393: mem_size = memparse(p, &p);
arch/mips/kernel/setup.c-394- if (p == oldp)
--
arch/mips/kernel/setup.c-397- if (*p == '@') {
arch/mips/kernel/setup.c:398: start_at = memparse(p+1, &p);
arch/mips/kernel/setup.c-399- memblock_add(start_at, mem_size);
--
arch/mips/kernel/setup.c-403- } else if (*p == '$') {
arch/mips/kernel/setup.c:404: start_at = memparse(p+1, &p);
arch/mips/kernel/setup.c-405- memblock_add(start_at, mem_size);
--
arch/mips/mti-malta/malta-dtshim.c=131=static void __init append_memory(void *fdt, int root_off)
--
arch/mips/mti-malta/malta-dtshim.c-184-
arch/mips/mti-malta/malta-dtshim.c:185: memsize = memparse(var + strlen(param_name), NULL);
arch/mips/mti-malta/malta-dtshim.c-186- }
--
arch/parisc/mm/init.c=83=static void __init mem_limit_func(void)
--
arch/parisc/mm/init.c-93- cp += 4;
arch/parisc/mm/init.c:94: limit = memparse(cp, &end);
arch/parisc/mm/init.c-95- if (end != cp)
--
arch/powerpc/kernel/fadump.c=675=static int __init early_fadump_reserve_mem(char *p)
--
arch/powerpc/kernel/fadump.c-677- if (p)
arch/powerpc/kernel/fadump.c:678: fw_dump.reserve_bootvar = memparse(p, &p);
arch/powerpc/kernel/fadump.c-679- return 0;
--
arch/powerpc/kernel/prom.c=81=static int __init early_parse_mem(char *p)
--
arch/powerpc/kernel/prom.c-85-
arch/powerpc/kernel/prom.c:86: memory_limit = PAGE_ALIGN(memparse(p, &p));
arch/powerpc/kernel/prom.c-87- DBG("memory limit = 0x%llx\n", memory_limit);
--
arch/powerpc/kernel/prom_init.c=727=static unsigned long __init prom_strtoul(const char *cp, const char **endp)
--
arch/powerpc/kernel/prom_init.c-751-
arch/powerpc/kernel/prom_init.c:752:static unsigned long __init prom_memparse(const char *ptr, const char **retptr)
arch/powerpc/kernel/prom_init.c-753-{
--
arch/powerpc/kernel/prom_init.c=783=static void __init early_cmdline_parse(void)
--
arch/powerpc/kernel/prom_init.c-817- opt += 4;
arch/powerpc/kernel/prom_init.c:818: prom_memory_limit = prom_memparse(opt, (const char **)&opt);
arch/powerpc/kernel/prom_init.c-819-#ifdef CONFIG_PPC64
--
arch/powerpc/mm/numa.c=89=static int __init fake_numa_create_new_node(unsigned long end_pfn,
--
arch/powerpc/mm/numa.c-110-
arch/powerpc/mm/numa.c:111: mem = memparse(p, &p);
arch/powerpc/mm/numa.c-112- if (!mem)
--
arch/powerpc/platforms/ps3/setup.c=135=static int __init early_parse_ps3fb(char *p)
--
arch/powerpc/platforms/ps3/setup.c-139-
arch/powerpc/platforms/ps3/setup.c:140: ps3fb_videomemory.size = ALIGN(memparse(p, &p),
arch/powerpc/platforms/ps3/setup.c-141- ps3fb_videomemory.align);
--
arch/riscv/mm/init.c=201=static int __init early_mem(char *p)
--
arch/riscv/mm/init.c-207-
arch/riscv/mm/init.c:208: size = memparse(p, &p) & PAGE_MASK;
arch/riscv/mm/init.c-209- memory_limit = min_t(u64, size, memory_limit);
--
arch/s390/boot/ipl_parm.c=249=void parse_boot_command_line(void)
--
arch/s390/boot/ipl_parm.c-262- if (!strcmp(param, "mem") && val)
arch/s390/boot/ipl_parm.c:263: memory_limit = round_down(memparse(val, NULL), PAGE_SIZE);
arch/s390/boot/ipl_parm.c-264-
arch/s390/boot/ipl_parm.c-265- if (!strcmp(param, "vmalloc") && val) {
arch/s390/boot/ipl_parm.c:266: vmalloc_size = round_up(memparse(val, NULL), _SEGMENT_SIZE);
arch/s390/boot/ipl_parm.c-267- vmalloc_size_set = 1;
--
arch/sh/kernel/setup.c=104=static int __init early_parse_mem(char *p)
--
arch/sh/kernel/setup.c-108-
arch/sh/kernel/setup.c:109: memory_limit = PAGE_ALIGN(memparse(p, &p));
arch/sh/kernel/setup.c-110-
--
arch/sh/mm/consistent.c=20=static void __init memchunk_cmdline_override(char *name, unsigned long *sizep)
--
arch/sh/mm/consistent.c-28- p += k + 1;
arch/sh/mm/consistent.c:29: *sizep = memparse(p, NULL);
arch/sh/mm/consistent.c-30- pr_info("%s: forcing memory chunk size to 0x%08lx\n",
--
arch/sparc/kernel/setup_64.c=120=static void __init boot_flags_init(char *commands)
--
arch/sparc/kernel/setup_64.c-136- if (!strncmp(commands, "mem=", 4))
arch/sparc/kernel/setup_64.c:137: cmdline_memory_size = memparse(commands + 4, &commands);
arch/sparc/kernel/setup_64.c-138-
--
arch/um/drivers/mconsole_kern.c=290=static int mem_config(char *str, char **error_out)
--
arch/um/drivers/mconsole_kern.c-312- str++;
arch/um/drivers/mconsole_kern.c:313: diff = memparse(str, &ret);
arch/um/drivers/mconsole_kern.c-314- if (*ret != '\0') {
--
arch/um/kernel/physmem.c=113=static int __init uml_mem_setup(char *line, int *add)
--
arch/um/kernel/physmem.c-117- *add = 0;
arch/um/kernel/physmem.c:118: physmem_size = memparse(line,&retptr);
arch/um/kernel/physmem.c-119- return 0;
--
arch/x86/boot/compressed/kaslr.c=119=parse_memmap(char *p, u64 *start, u64 *size)
--
arch/x86/boot/compressed/kaslr.c-130- oldp = p;
arch/x86/boot/compressed/kaslr.c:131: *size = memparse(p, &p);
arch/x86/boot/compressed/kaslr.c-132- if (p == oldp)
--
arch/x86/boot/compressed/kaslr.c-138- case '!':
arch/x86/boot/compressed/kaslr.c:139: *start = memparse(p + 1, &p);
arch/x86/boot/compressed/kaslr.c-140- return 0;
--
arch/x86/boot/compressed/kaslr.c=202=static void parse_gb_huge_pages(char *param, char *val)
--
arch/x86/boot/compressed/kaslr.c-208- p = val;
arch/x86/boot/compressed/kaslr.c:209: if (memparse(p, &p) != PUD_SIZE) {
arch/x86/boot/compressed/kaslr.c-210- gbpage_sz = false;
--
arch/x86/boot/compressed/kaslr.c=228=static void handle_mem_options(void)
--
arch/x86/boot/compressed/kaslr.c-265- continue;
arch/x86/boot/compressed/kaslr.c:266: mem_size = memparse(p, &p);
arch/x86/boot/compressed/kaslr.c-267- if (mem_size == 0)
--
arch/x86/kernel/apic/x2apic_uv_x.c=533=static int __init parse_mem_block_size(char *ptr)
arch/x86/kernel/apic/x2apic_uv_x.c-534-{
arch/x86/kernel/apic/x2apic_uv_x.c:535: unsigned long size = memparse(ptr, NULL);
arch/x86/kernel/apic/x2apic_uv_x.c-536-
--
arch/x86/kernel/check.c=72=static __init int set_corruption_check_size(char *arg)
--
arch/x86/kernel/check.c-81-
arch/x86/kernel/check.c:82: size = memparse(arg, &end);
arch/x86/kernel/check.c-83-
--
arch/x86/kernel/cpu/mtrr/cleanup.c=414=static int __init parse_mtrr_chunk_size_opt(char *p)
--
arch/x86/kernel/cpu/mtrr/cleanup.c-417- return -EINVAL;
arch/x86/kernel/cpu/mtrr/cleanup.c:418: mtrr_chunk_size = memparse(p, &p);
arch/x86/kernel/cpu/mtrr/cleanup.c-419- return 0;
--
arch/x86/kernel/cpu/mtrr/cleanup.c=426=static int __init parse_mtrr_gran_size_opt(char *p)
--
arch/x86/kernel/cpu/mtrr/cleanup.c-429- return -EINVAL;
arch/x86/kernel/cpu/mtrr/cleanup.c:430: mtrr_gran_size = memparse(p, &p);
arch/x86/kernel/cpu/mtrr/cleanup.c-431- return 0;
--
arch/x86/kernel/e820.c=909=__init static int parse_memopt(char *p)
--
arch/x86/kernel/e820.c-926- userdef = 1;
arch/x86/kernel/e820.c:927: mem_size = memparse(p, &p);
arch/x86/kernel/e820.c-928-
--
arch/x86/kernel/e820.c=943=__init static int parse_memmap_one(char *p)
--
arch/x86/kernel/e820.c-957- oldp = p;
arch/x86/kernel/e820.c:958: mem_size = memparse(p, &p);
arch/x86/kernel/e820.c-959- if (p == oldp)
--
arch/x86/kernel/e820.c-963- if (*p == '@') {
arch/x86/kernel/e820.c:964: start_at = memparse(p+1, &p);
arch/x86/kernel/e820.c-965- e820__range_add(start_at, mem_size, E820_TYPE_RAM);
arch/x86/kernel/e820.c-966- } else if (*p == '#') {
arch/x86/kernel/e820.c:967: start_at = memparse(p+1, &p);
arch/x86/kernel/e820.c-968- e820__range_add(start_at, mem_size, E820_TYPE_ACPI);
arch/x86/kernel/e820.c-969- } else if (*p == '$') {
arch/x86/kernel/e820.c:970: start_at = memparse(p+1, &p);
arch/x86/kernel/e820.c-971- e820__range_add(start_at, mem_size, E820_TYPE_RESERVED);
arch/x86/kernel/e820.c-972- } else if (*p == '!') {
arch/x86/kernel/e820.c:973: start_at = memparse(p+1, &p);
arch/x86/kernel/e820.c-974- e820__range_add(start_at, mem_size, E820_TYPE_PRAM);
--
arch/x86/kernel/e820.c-977-
arch/x86/kernel/e820.c:978: start_at = memparse(p + 1, &p);
arch/x86/kernel/e820.c-979- if (*p == '-')
--
arch/x86/kernel/mpparse.c=815=static int __init parse_alloc_mptable_opt(char *p)
--
arch/x86/kernel/mpparse.c-823- return 0;
arch/x86/kernel/mpparse.c:824: mpc_new_length = memparse(p, &p);
arch/x86/kernel/mpparse.c-825- return 0;
--
arch/x86/mm/init_32.c=517=static int __init parse_highmem(char *arg)
--
arch/x86/mm/init_32.c-521-
arch/x86/mm/init_32.c:522: highmem_pages = memparse(arg, &arg) >> PAGE_SHIFT;
arch/x86/mm/init_32.c-523- return 0;
--
arch/x86/mm/pgtable_32.c=76=static int __init parse_vmalloc(char *arg)
--
arch/x86/mm/pgtable_32.c-81- /* Add VMALLOC_OFFSET to the parsed value due to vm area guard hole*/
arch/x86/mm/pgtable_32.c:82: __VMALLOC_RESERVE = memparse(arg, &arg) + VMALLOC_OFFSET;
arch/x86/mm/pgtable_32.c-83- return 0;
--
arch/x86/mm/pgtable_32.c=92=static int __init parse_reservetop(char *arg)
--
arch/x86/mm/pgtable_32.c-98-
arch/x86/mm/pgtable_32.c:99: address = memparse(arg, &arg);
arch/x86/mm/pgtable_32.c-100- reserve_top_address(address);
--
arch/x86/xen/time.c=649=static int __init parse_xen_timer_slop(char *ptr)
arch/x86/xen/time.c-650-{
arch/x86/xen/time.c:651: unsigned long slop = memparse(ptr, NULL);
arch/x86/xen/time.c-652-
--
arch/xtensa/mm/init.c=132=static void __init parse_memmap_one(char *p)
--
arch/xtensa/mm/init.c-140- oldp = p;
arch/xtensa/mm/init.c:141: mem_size = memparse(p, &p);
arch/xtensa/mm/init.c-142- if (p == oldp)
--
arch/xtensa/mm/init.c-146- case '@':
arch/xtensa/mm/init.c:147: start_at = memparse(p + 1, &p);
arch/xtensa/mm/init.c-148- memblock_add(start_at, mem_size);
--
arch/xtensa/mm/init.c-151- case '$':
arch/xtensa/mm/init.c:152: start_at = memparse(p + 1, &p);
arch/xtensa/mm/init.c-153- memblock_reserve(start_at, mem_size);
--
block/partitions/cmdline.c=42=static int parse_subpart(struct cmdline_subpart **subpart, char *partdef)
--
block/partitions/cmdline.c-56- } else {
block/partitions/cmdline.c:57: new_subpart->size = (sector_t)memparse(partdef, &partdef);
block/partitions/cmdline.c-58- if (new_subpart->size < (sector_t)PAGE_SIZE) {
--
block/partitions/cmdline.c-66- partdef++;
block/partitions/cmdline.c:67: new_subpart->from = (sector_t)memparse(partdef, &partdef);
block/partitions/cmdline.c-68- } else {
--
drivers/block/ps3vram.c=605=static int ps3vram_probe(struct ps3_system_bus_device *dev)
--
drivers/block/ps3vram.c-645- status = -1;
drivers/block/ps3vram.c:646: ddr_size = ALIGN(memparse(size, &rest), 1024*1024);
drivers/block/ps3vram.c-647- if (!ddr_size) {
--
drivers/block/zram/zram_drv.c=383=static ssize_t mem_limit_store(struct device *dev,
--
drivers/block/zram/zram_drv.c-390-
drivers/block/zram/zram_drv.c:391: limit = memparse(buf, &tmp);
drivers/block/zram/zram_drv.c-392- if (buf == tmp) /* no chars parsed, invalid input */
--
drivers/block/zram/zram_drv.c=2860=static ssize_t disksize_store(struct device *dev, struct device_attribute *attr,
--
drivers/block/zram/zram_drv.c-2868-
drivers/block/zram/zram_drv.c:2869: disksize = memparse(buf, NULL);
drivers/block/zram/zram_drv.c-2870- if (!disksize)
--
drivers/char/agp/uninorth-agp.c=38=static int uninorth_fetch_size(void)
--
drivers/char/agp/uninorth-agp.c-46-
drivers/char/agp/uninorth-agp.c:47: size = memparse(aperture, &aperture) >> 20;
drivers/char/agp/uninorth-agp.c-48- aperture = save;
--
drivers/firmware/qemu_fw_cfg.c=796=static int fw_cfg_cmdline_set(const char *arg, const struct kernel_param *kp)
--
drivers/firmware/qemu_fw_cfg.c-814- /* consume "<size>" portion of command line argument */
drivers/firmware/qemu_fw_cfg.c:815: size = memparse(arg, &str);
drivers/firmware/qemu_fw_cfg.c-816-
--
drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c=1218=static int s5p_mfc_configure_common_memory(struct s5p_mfc_dev *mfc_dev)
--
drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c-1226- if (mfc_mem_size)
drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c:1227: mem_size = memparse(mfc_mem_size, NULL);
drivers/media/platform/samsung/s5p-mfc/s5p_mfc.c-1228-
--
drivers/mtd/parsers/cmdlinepart.c=74=static struct mtd_partition * newpart(char *s,
--
drivers/mtd/parsers/cmdlinepart.c-94- } else {
drivers/mtd/parsers/cmdlinepart.c:95: size = memparse(s, &s);
drivers/mtd/parsers/cmdlinepart.c-96- if (!size) {
--
drivers/mtd/parsers/cmdlinepart.c-109- s++;
drivers/mtd/parsers/cmdlinepart.c:110: offset = memparse(s, &s);
drivers/mtd/parsers/cmdlinepart.c-111- }
--
drivers/pci/pci.c=6743=static int __init pci_setup(char *str)
--
drivers/pci/pci.c-6775- } else if (!strncmp(str, "hpiosize=", 9)) {
drivers/pci/pci.c:6776: pci_hotplug_io_size = memparse(str + 9, &str);
drivers/pci/pci.c-6777- } else if (!strncmp(str, "hpmmiosize=", 11)) {
drivers/pci/pci.c:6778: pci_hotplug_mmio_size = memparse(str + 11, &str);
drivers/pci/pci.c-6779- } else if (!strncmp(str, "hpmmioprefsize=", 15)) {
drivers/pci/pci.c:6780: pci_hotplug_mmio_pref_size = memparse(str + 15, &str);
drivers/pci/pci.c-6781- } else if (!strncmp(str, "hpmemsize=", 10)) {
drivers/pci/pci.c:6782: pci_hotplug_mmio_size = memparse(str + 10, &str);
drivers/pci/pci.c-6783- pci_hotplug_mmio_pref_size = pci_hotplug_mmio_size;
--
drivers/pci/setup-cardbus.c=182=int pci_setup_cardbus(char *str)
--
drivers/pci/setup-cardbus.c-184- if (!strncmp(str, "cbiosize=", 9)) {
drivers/pci/setup-cardbus.c:185: pci_cardbus_io_size = memparse(str + 9, &str);
drivers/pci/setup-cardbus.c-186- return 0;
drivers/pci/setup-cardbus.c-187- } else if (!strncmp(str, "cbmemsize=", 10)) {
drivers/pci/setup-cardbus.c:188: pci_cardbus_mem_size = memparse(str + 10, &str);
drivers/pci/setup-cardbus.c-189- return 0;
--
drivers/s390/char/vmcp.c=43=static int __init early_parse_vmcp_cma(char *p)
--
drivers/s390/char/vmcp.c-46- return 1;
drivers/s390/char/vmcp.c:47: vmcp_cma_size = ALIGN(memparse(p, NULL), PAGE_SIZE);
drivers/s390/char/vmcp.c-48- return 0;
--
drivers/video/fbdev/gbefb.c=1088=static int gbefb_setup(char *options)
--
drivers/video/fbdev/gbefb.c-1107- } else if (!strncmp(this_opt, "mem:", 4)) {
drivers/video/fbdev/gbefb.c:1108: gbe_mem_size = memparse(this_opt + 4, &this_opt);
drivers/video/fbdev/gbefb.c-1109- if (gbe_mem_size > CONFIG_FB_GBE_MEM * 1024 * 1024)
--
drivers/video/fbdev/omap/omapfb_main.c=1839=static int __init omapfb_setup(char *options)
--
drivers/video/fbdev/omap/omapfb_main.c-1855-
drivers/video/fbdev/omap/omapfb_main.c:1856: vram = memparse(this_opt + 5, &suffix);
drivers/video/fbdev/omap/omapfb_main.c-1857- switch (suffix[0]) {
--
drivers/video/fbdev/omap2/omapfb/omapfb-main.c=1471=static int omapfb_parse_vram_param(const char *param, int max_entries,
--
drivers/video/fbdev/omap2/omapfb/omapfb-main.c-1494-
drivers/video/fbdev/omap2/omapfb/omapfb-main.c:1495: size = memparse(p + 1, &p);
drivers/video/fbdev/omap2/omapfb/omapfb-main.c-1496-
--
drivers/video/fbdev/pxafb.c=1898=static int parse_opt(struct device *dev, char *this_opt,
--
drivers/video/fbdev/pxafb.c-1906- if (!strncmp(this_opt, "vmem:", 5)) {
drivers/video/fbdev/pxafb.c:1907: video_mem_size = memparse(this_opt + 5, NULL);
drivers/video/fbdev/pxafb.c-1908- } else if (!strncmp(this_opt, "mode:", 5)) {
--
drivers/virtio/virtio_mmio.c=670=static int vm_cmdline_set(const char *device,
--
drivers/virtio/virtio_mmio.c-680- /* Consume "size" part of the command line parameter */
drivers/virtio/virtio_mmio.c:681: size = memparse(device, &str);
drivers/virtio/virtio_mmio.c-682-
--
drivers/xen/xen-balloon.c=188=static ssize_t target_store(struct device *dev,
--
drivers/xen/xen-balloon.c-197-
drivers/xen/xen-balloon.c:198: target_bytes = memparse(buf, &endchar);
drivers/xen/xen-balloon.c-199-
--
fs/btrfs/ioctl.c=985=static noinline int btrfs_ioctl_resize(struct file *file,
--
fs/btrfs/ioctl.c-1072- }
fs/btrfs/ioctl.c:1073: new_size = memparse(sizestr, &retptr);
fs/btrfs/ioctl.c-1074- if (*retptr != '\0' || new_size == 0) {
--
fs/btrfs/super.c=342=static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
--
fs/btrfs/super.c-445- case Opt_max_inline:
fs/btrfs/super.c:446: ctx->max_inline = memparse(param->string, NULL);
fs/btrfs/super.c-447- break;
]
|
| 18/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 27053
output: 34
thoughts: 255
Thoughts: **Analyzing a Potential Memory Allocation Issue**
Okay, so I'm looking at this code and trying to figure out what's happening. `memparse` is the key function here; it's supposed to take a string and spit out an `unsigned long long` representing a memory size. The example "1E" is throwing me off, though. It parses to 1, then the code calls `PAGE_ALIGN(1)`. But wait, `memparse` utilizes `simple_strtoull`! `simple_strtoull` defaults to base 10 unless it encounters a "0x" prefix, so "1E" correctly parses as 1.
Then, the `disksize` becomes `PAGE_SIZE`, which is 4096. Fine, so far so good. We end up calling `zram_meta_alloc` with `disksize = 4096`. Next, `num_pages` becomes `disksize >> PAGE_SHIFT`. If `PAGE_SHIFT` is the usual 12, this results in `num_pages` being 1.
But here's where I start to get a bit nervous. This is running on ARM-Versatile Express. I know ARM is generally 4KB, `PAGE_SHIFT` of 12. But what if there's some interaction here between how `memparse` is *supposed* to work, and how it's actually interpreting the input that is causing an unintended value to be passed. Let's dig deeper into the implementation of `memparse` itself to be completely sure.
|
| 19/2 |
2026/09/11 00:21 |
tool |
read-file |
0m
Args: map[File:lib/cmdline.c FirstLine:143 LineCount:50]
Results: map[Contents: 143: * @ptr: Where parse begins
144: * @retptr: (output) Optional pointer to next char after parse completes
145: *
146: * Parses a string into a number. The number stored at @ptr is
147: * potentially suffixed with K, M, G, T, P, E.
148: *
149: * Return: The value as recognized by simple_strtoull() multiplied
150: * by the value as specified by suffix, if any.
151: */
152:
153: unsigned long long memparse(const char *ptr, char **retptr)
154: {
155: char *endptr; /* local pointer to end of parsed string */
156: unsigned long long ret = simple_strtoull(ptr, &endptr, 0);
157: unsigned int shl = 0;
158:
159: /* Consume valid suffix even in case of overflow. */
160: switch (*endptr) {
161: case 'E':
162: case 'e':
163: shl += 10;
164: fallthrough;
165: case 'P':
166: case 'p':
167: shl += 10;
168: fallthrough;
169: case 'T':
170: case 't':
171: shl += 10;
172: fallthrough;
173: case 'G':
174: case 'g':
175: shl += 10;
176: fallthrough;
177: case 'M':
178: case 'm':
179: shl += 10;
180: fallthrough;
181: case 'K':
182: case 'k':
183: shl += 10;
184: fallthrough;
185: default:
186: break;
187: }
188:
189: if (shl && likely(ptr != endptr)) {
190: /* Have valid suffix with preceding number. */
191: if (unlikely(check_shl_overflow(ret, shl, &ret)))
192: ret = ULLONG_MAX;
]
|
| 20/2 |
2026/09/11 00:21 |
llm |
expert |
0m
Model:
Tokens:
input: 28378
output: 42
thoughts: 357
Thoughts: **My Analysis of the `memparse` and `zram_meta_alloc` Code**
Okay, so `memparse` supports suffixes, that's good to know. The 'E' suffix signifies Exabytes, and I remember `shl` for 'E' is 60 (10 + 10 + 10 + 10 + 10 + 10). So, the initial value calculated is `1ULL << 60`, which I know from experience is `1152921504606846976`.
Then, it's aligned with `PAGE_ALIGN`, which I recall is essentially adding `PAGE_SIZE - 1` and then bitwise AND-ing with `PAGE_MASK`. Since my input is going to be a multiple of `PAGE_SIZE`, this is going to be a no-op, meaning `disksize` will simply be `1ULL << 60`. `disksize` is a `u64`, so that's all good.
Now, `zram_meta_alloc` gets called with `disksize`. Inside, it calculates `num_pages` as `disksize >> PAGE_SHIFT`. If `PAGE_SHIFT` is 12, then `num_pages` becomes `1ULL << 48`. But wait a minute... `num_pages` is a `size_t`! And I'm pretty sure this is ARM-Versatile Express, which means it's a 32-bit system. That means `size_t` is 32 bits, and therefore `num_pages` becomes `(1ULL << 48) & 0xFFFFFFFF`, which, by bitwise arithmetic, is going to be *zero*!
Aha! `num_pages` is overflowing to zero! This is a classic bug that could lead to serious problems in memory allocation, or worse. I need to revisit `zram_meta_alloc` and see how this potential zero value for `num_pages` is handled. This is definitely something to investigate further.
|
| 21/2 |
2026/09/11 00:22 |
tool |
read-file |
0m
Args: map[File:drivers/block/zram/zram_drv.c FirstLine:1985 LineCount:20]
Results: map[Contents:1985: static bool zram_meta_alloc(struct zram *zram, u64 disksize)
1986: {
1987: size_t num_pages, index;
1988:
1989: num_pages = disksize >> PAGE_SHIFT;
1990: zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
1991: if (!zram->table)
1992: return false;
1993:
1994: zram->mem_pool = zs_create_pool(zram->disk->disk_name);
1995: if (!zram->mem_pool) {
1996: vfree(zram->table);
1997: zram->table = NULL;
1998: return false;
1999: }
2000:
2001: if (!huge_class_size)
2002: huge_class_size = zs_huge_class_size(zram->mem_pool);
2003:
2004: for (index = 0; index < num_pages; index++)
]
|
| 22/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 29557
output: 22
thoughts: 446
Thoughts: **Analyzing the ZRAM Allocation Issue**
Okay, so `num_pages` is a `size_t`, got it. On this 32-bit ARM system, that means it's a 32-bit integer. Now, the `disksize` is a `u64`. I see, `disksize >> PAGE_SHIFT` results in a very large number, specifically `1ULL << 48`. When that's assigned to `num_pages`, it's truncated, and becomes zero. That explains it.
So, `array_size(0, sizeof(*zram->table))` evaluates to zero. Then `vzalloc(0)` is called. And, of course, `vzalloc` eventually calls `__vmalloc_node_range_noprof` with a size of zero. Right, and in that function, there's that `WARN_ON_ONCE` check. Bingo. That's what triggers the warning message. And, then `vzalloc` returns `NULL`.
Alright, then `zram_meta_alloc` checks if the table is allocated and returns `false`. `disksize_store` receives `false` and returns `-ENOMEM`, which is the expected behavior, given this situation.
Hold on, the warning is just a `WARN_ON_ONCE`, so it doesn't cause a crash unless `panic_on_warn` is set, as it is in syzkaller. That's why it's showing up there but not necessarily in a production environment.
But, are there any other consequences? If `vzalloc(0)` returns `NULL`, `zram_meta_alloc` fails gracefully and returns `-ENOMEM`. There isn't any memory corruption, because it returns `-ENOMEM`, and handles the null return.
Wait, is there any way to overflow `array_size` and get a non-zero `num_pages` to evaluate to zero? Looking at how `array_size` works, it uses `SIZE_MAX / sizeof(*zram->table)`. If `num_pages` is larger than that, then it evaluates to `SIZE_MAX`. Okay, got it. It's defined in `include/linux/overflow.h`.
|
| 23/2 |
2026/09/11 00:22 |
tool |
grepper |
0m
Error:
Args: map[Expression:static inline size_t array_size]
Results:
|
| 24/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 30524
output: 19
thoughts: 11
Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience:
**Investigating `array_size`**
Okay, I need to understand this `array_size` definition before I proceed. It's a key variable or constant likely used to manage memory allocation or bounds checking in this section of code. I need to be sure I understand *exactly* how it's defined and what context it operates within. This could be defined in a header file, through a macro, or even dynamically determined. I need to check its origin, scope, and possible impact on the program's behavior. A clear understanding of how `array_size` is calculated, or where it's declared, is crucial. Is this a compile-time constant? Is it dynamically calculated? This determination is critical to understanding memory usage and bounds checking.
|
| 25/2 |
2026/09/11 00:22 |
tool |
grepper |
0m
Args: map[Expression:#define array_size]
Results: map[Output:include/linux/overflow.h=370=static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
--
include/linux/overflow.h-390- */
include/linux/overflow.h:391:#define array_size(a, b) size_mul(a, b)
include/linux/overflow.h-392-
]
|
| 26/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 30844
output: 35
thoughts: 9
Thoughts: Okay, here's my attempt at summarizing that thought process, keeping in mind I'm speaking to a fellow expert:
**Checking `size_mul`**
Alright, let's take a quick look at `size_mul`. It's crucial for understanding... well, a whole bunch of things. I'm probably thinking about performance implications, potential overflow issues, or maybe its role in some specific memory allocation scheme. Without more context, it's tough to be specific. But I immediately understand that this variable, `size_mul`, is a critical factor in how something is sized or scaled in this context. I'm likely gearing up for a deeper dive; maybe I'm troubleshooting a bug, optimizing some code, or just trying to understand the overall design better. Ultimately, checking `size_mul` is a necessary step towards understanding a larger process.
|
| 27/2 |
2026/09/11 00:22 |
tool |
read-file |
0m
Args: map[File:include/linux/overflow.h FirstLine:330 LineCount:50]
Results: map[Contents: 330: static __always_inline size_t __must_check size_mul(size_t factor1, size_t factor2)
331: {
332: size_t bytes;
333:
334: if (check_mul_overflow(factor1, factor2, &bytes))
335: return SIZE_MAX;
336:
337: return bytes;
338: }
339:
340: /**
341: * size_add() - Calculate size_t addition with saturation at SIZE_MAX
342: * @addend1: first addend
343: * @addend2: second addend
344: *
345: * Returns: calculate @addend1 + @addend2, both promoted to size_t,
346: * with any overflow causing the return value to be SIZE_MAX. The
347: * lvalue must be size_t to avoid implicit type conversion.
348: */
349: static __always_inline size_t __must_check size_add(size_t addend1, size_t addend2)
350: {
351: size_t bytes;
352:
353: if (check_add_overflow(addend1, addend2, &bytes))
354: return SIZE_MAX;
355:
356: return bytes;
357: }
358:
359: /**
360: * size_sub() - Calculate size_t subtraction with saturation at SIZE_MAX
361: * @minuend: value to subtract from
362: * @subtrahend: value to subtract from @minuend
363: *
364: * Returns: calculate @minuend - @subtrahend, both promoted to size_t,
365: * with any overflow causing the return value to be SIZE_MAX. For
366: * composition with the size_add() and size_mul() helpers, neither
367: * argument may be SIZE_MAX (or the result with be forced to SIZE_MAX).
368: * The lvalue must be size_t to avoid implicit type conversion.
369: */
370: static __always_inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
371: {
372: size_t bytes;
373:
374: if (minuend == SIZE_MAX || subtrahend == SIZE_MAX ||
375: check_sub_overflow(minuend, subtrahend, &bytes))
376: return SIZE_MAX;
377:
378: return bytes;
379: }
]
|
| 28/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 31854
output: 19
thoughts: 542
Thoughts: **Analyzing Potential Denial-of-Service and Out-of-Bounds Scenarios in ZRAM Initialization**
Okay, so I'm diving into this ZRAM code, and I'm seeing a potential vulnerability. If `num_pages * sizeof(*zram->table)` overflows, `array_size` will correctly return `SIZE_MAX`. `vzalloc(SIZE_MAX)` will fail, which is expected behavior (returning `NULL` because `SIZE_MAX` is too large). That’s fine. The real issue arises when `num_pages` ends up being *exactly* zero.
This zero condition happens when `disksize >> PAGE_SHIFT` evaluates to zero. I need to be careful with bit shifts and data type sizes here. Let's see... If `disksize` is, say, `1ULL << 60`, then right-shifting it by 12 (PAGE_SHIFT) results in `1ULL << 48`. On a 32-bit system, `size_t` is 32 bits, so that gets truncated to zero. So, what if `disksize` is `1ULL << 44`? The right-shift becomes `1ULL << 32`, which, when truncated to 32 bits, is also zero. This means `num_pages` is zero, and `vzalloc(0)` triggers `WARN_ON_ONCE(!size)`. That's a simple denial-of-service, assuming `panic_on_warn` isn’t set, which it isn't in production.
But wait, does this zero case cause *any* other problems? If `vzalloc(0)` returns `NULL`, `zram_meta_alloc` returns `false`, and `disksize_store` returns `-ENOMEM`. No memory corruption there. So the only real harm is the DoS, which seems pretty benign.
Now, here's a more interesting scenario to look at. What if `disksize` is *not* zero after the right shift, but it’s still huge? Imagine `disksize = (1ULL << 32) + 4096`. `disksize >> 12` becomes `(1ULL << 20) + 1`, meaning `num_pages` is `(1ULL << 20) + 1`. `vzalloc` will allocate memory for this number of entries. Then, `zram->disksize` gets set to `disksize`, which is a `u64`. I need to think about this... later when accessing ZRAM, `zram->disksize` is used. This *could* lead to out-of-bounds access if the table allocation size is smaller than the access size. Let's check how the `zram->table` is accessed. I need to trace this access...
|
| 29/2 |
2026/09/11 00:22 |
tool |
grepper |
0m
Args: map[Expression:zram->table\[]
Results: map[Output:drivers/block/zram/zram_drv.c=62=static void slot_lock_init(struct zram *zram, u32 index)
--
drivers/block/zram/zram_drv.c-65-
drivers/block/zram/zram_drv.c:66: lockdep_init_map(slot_dep_map(zram, index), "zram->table[index].lock",
drivers/block/zram/zram_drv.c-67- &__key, 0);
--
drivers/block/zram/zram_drv.c=82=static __must_check bool slot_trylock(struct zram *zram, u32 index)
drivers/block/zram/zram_drv.c-83-{
drivers/block/zram/zram_drv.c:84: unsigned long *lock = &zram->table[index].__lock;
drivers/block/zram/zram_drv.c-85-
--
drivers/block/zram/zram_drv.c=95=static void slot_lock(struct zram *zram, u32 index)
drivers/block/zram/zram_drv.c-96-{
drivers/block/zram/zram_drv.c:97: unsigned long *lock = &zram->table[index].__lock;
drivers/block/zram/zram_drv.c-98-
--
drivers/block/zram/zram_drv.c=104=static void slot_unlock(struct zram *zram, u32 index)
drivers/block/zram/zram_drv.c-105-{
drivers/block/zram/zram_drv.c:106: unsigned long *lock = &zram->table[index].__lock;
drivers/block/zram/zram_drv.c-107-
--
drivers/block/zram/zram_drv.c=122=static unsigned long get_slot_handle(struct zram *zram, u32 index)
drivers/block/zram/zram_drv.c-123-{
drivers/block/zram/zram_drv.c:124: return zram->table[index].handle;
drivers/block/zram/zram_drv.c-125-}
--
drivers/block/zram/zram_drv.c=127=static void set_slot_handle(struct zram *zram, u32 index, unsigned long handle)
drivers/block/zram/zram_drv.c-128-{
drivers/block/zram/zram_drv.c:129: zram->table[index].handle = handle;
drivers/block/zram/zram_drv.c-130-}
--
drivers/block/zram/zram_drv.c=132=static bool test_slot_flag(struct zram *zram, u32 index,
--
drivers/block/zram/zram_drv.c-134-{
drivers/block/zram/zram_drv.c:135: return zram->table[index].attr.flags & BIT(flag);
drivers/block/zram/zram_drv.c-136-}
--
drivers/block/zram/zram_drv.c=138=static void set_slot_flag(struct zram *zram, u32 index,
--
drivers/block/zram/zram_drv.c-140-{
drivers/block/zram/zram_drv.c:141: zram->table[index].attr.flags |= BIT(flag);
drivers/block/zram/zram_drv.c-142-}
--
drivers/block/zram/zram_drv.c=144=static void clear_slot_flag(struct zram *zram, u32 index,
--
drivers/block/zram/zram_drv.c-146-{
drivers/block/zram/zram_drv.c:147: zram->table[index].attr.flags &= ~BIT(flag);
drivers/block/zram/zram_drv.c-148-}
--
drivers/block/zram/zram_drv.c=150=static size_t get_slot_size(struct zram *zram, u32 index)
drivers/block/zram/zram_drv.c-151-{
drivers/block/zram/zram_drv.c:152: return zram->table[index].attr.flags & (BIT(ZRAM_FLAG_SHIFT) - 1);
drivers/block/zram/zram_drv.c-153-}
--
drivers/block/zram/zram_drv.c=155=static void set_slot_size(struct zram *zram, u32 index, size_t size)
drivers/block/zram/zram_drv.c-156-{
drivers/block/zram/zram_drv.c:157: unsigned long flags = zram->table[index].attr.flags >> ZRAM_FLAG_SHIFT;
drivers/block/zram/zram_drv.c-158-
drivers/block/zram/zram_drv.c:159: zram->table[index].attr.flags = (flags << ZRAM_FLAG_SHIFT) | size;
drivers/block/zram/zram_drv.c-160-}
--
drivers/block/zram/zram_drv.c=169=static inline void set_slot_comp_priority(struct zram *zram, u32 index,
--
drivers/block/zram/zram_drv.c-176- */
drivers/block/zram/zram_drv.c:177: zram->table[index].attr.flags &= ~(ZRAM_COMP_PRIORITY_MASK <<
drivers/block/zram/zram_drv.c-178- ZRAM_COMP_PRIORITY_BIT1);
drivers/block/zram/zram_drv.c:179: zram->table[index].attr.flags |= (prio << ZRAM_COMP_PRIORITY_BIT1);
drivers/block/zram/zram_drv.c-180-}
--
drivers/block/zram/zram_drv.c=182=static inline u32 get_slot_comp_priority(struct zram *zram, u32 index)
drivers/block/zram/zram_drv.c-183-{
drivers/block/zram/zram_drv.c:184: u32 prio = zram->table[index].attr.flags >> ZRAM_COMP_PRIORITY_BIT1;
drivers/block/zram/zram_drv.c-185-
--
drivers/block/zram/zram_drv.c=189=static void mark_slot_accessed(struct zram *zram, u32 index)
--
drivers/block/zram/zram_drv.c-193-#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
drivers/block/zram/zram_drv.c:194: zram->table[index].attr.ac_time = (u32)ktime_get_boottime_seconds();
drivers/block/zram/zram_drv.c-195-#endif
--
drivers/block/zram/zram_drv.c=426=static void mark_idle(struct zram *zram, ktime_t cutoff)
--
drivers/block/zram/zram_drv.c-449- is_idle = !cutoff ||
drivers/block/zram/zram_drv.c:450: ktime_after(cutoff, zram->table[index].attr.ac_time);
drivers/block/zram/zram_drv.c-451-#endif
--
drivers/block/zram/zram_drv.c=1546=static ssize_t read_block_state(struct file *file, char __user *buf,
--
drivers/block/zram/zram_drv.c-1572- "%12zd %12u.%06d %c%c%c%c%c%c\n",
drivers/block/zram/zram_drv.c:1573: index, zram->table[index].attr.ac_time, 0,
drivers/block/zram/zram_drv.c-1574- test_slot_flag(zram, index, ZRAM_SAME) ? 's' : '.',
--
drivers/block/zram/zram_drv.c=2010=static void slot_free(struct zram *zram, u32 index)
--
drivers/block/zram/zram_drv.c-2014-#ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
drivers/block/zram/zram_drv.c:2015: zram->table[index].attr.ac_time = 0;
drivers/block/zram/zram_drv.c-2016-#endif
]
|
| 30/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 35313
output: 42
thoughts: 27
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Memory Allocation Deep Dive**
Right, hang on a second... the `index` variable, specifically the one we're using in that section, is declared as a `u32`. Okay, that's crucial. I need to make sure I'm not overlooking something obvious, especially with the allocation routines.
Let's double-check how we're using that `index` within `zram_meta_alloc`. Gotta go back over that function, look at the allocation algorithm again, and especially the calculations that are happening with that unsigned 32-bit integer. I need to refresh my understanding of how it's being used within the larger context of the zram metadata management. Potential integer overflows or unexpected wrapping behavior are definitely something I need to rule out, particularly with the block size in play.
|
| 31/2 |
2026/09/11 00:22 |
tool |
read-file |
0m
Args: map[File:drivers/block/zram/zram_drv.c FirstLine:1985 LineCount:30]
Results: map[Contents:1985: static bool zram_meta_alloc(struct zram *zram, u64 disksize)
1986: {
1987: size_t num_pages, index;
1988:
1989: num_pages = disksize >> PAGE_SHIFT;
1990: zram->table = vzalloc(array_size(num_pages, sizeof(*zram->table)));
1991: if (!zram->table)
1992: return false;
1993:
1994: zram->mem_pool = zs_create_pool(zram->disk->disk_name);
1995: if (!zram->mem_pool) {
1996: vfree(zram->table);
1997: zram->table = NULL;
1998: return false;
1999: }
2000:
2001: if (!huge_class_size)
2002: huge_class_size = zs_huge_class_size(zram->mem_pool);
2003:
2004: for (index = 0; index < num_pages; index++)
2005: slot_lock_init(zram, index);
2006:
2007: return true;
2008: }
2009:
2010: static void slot_free(struct zram *zram, u32 index)
2011: {
2012: unsigned long handle;
2013:
2014: #ifdef CONFIG_ZRAM_TRACK_ENTRY_ACTIME
]
|
| 32/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 36016
output: 20
thoughts: 50
Thoughts: Okay, here's my take on those thoughts, framed as my own mental processing:
**Inconsistency Alert! Memory Allocation Investigation**
Hmm, something feels off. I was just reviewing the `zram_meta_alloc` function, and I'm seeing that the `index` variable, which represents a position within the zram metadata, is defined as a `size_t`. That makes sense in the context of allocation, given that it needs to handle potentially large address spaces. But, then I jump over to `slot_free`… and now `index` is a `u32`! That's a significantly smaller data type. This immediate type mismatch makes me nervous. There's a potential risk of an integer truncation here, right? We might be losing data or creating a pointer to an incorrect metadata location during free. I need to understand if the memory allocation index and the freeing index are handled the same way.
Let's not jump to conclusions, I'll check `zram_rw_page` and get more context. I'll see how `index` is used, specifically in the context of read/write operations. That will help me better grasp where the types are being marshalled, if at all, and whether any implicit casting is happening. It feels like an important detail I need to fully understand.
|
| 33/2 |
2026/09/11 00:22 |
tool |
grepper |
0m
Error:
Args: map[Expression:zram_rw_page]
Results:
|
| 34/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 36380
output: 20
thoughts: 16
Thoughts: Here's my summary, as though I'm thinking through it:
**Digging into the Block Layer Performance**
Okay, so I'm trying to diagnose this performance bottleneck. Let's see... where's the most likely culprit? I need to focus on the block layer, and I'm thinking the `zram_bvec_rw` function (or something similar related to zram) is a good place to start. That's usually where I'd begin tracing data flow and performance issues when dealing with compressed RAM or block device interactions, especially when seeing sluggishness. I know I have a good handle on that section of code, and it provides a decent entry point to follow up on the read or write path.
|
| 35/2 |
2026/09/11 00:22 |
tool |
grepper |
0m
Args: map[Expression:zram_bvec_]
Results: map[Output:drivers/block/zram/zram_drv.c=2159=static int zram_read_page(struct zram *zram, struct page *page, u32 index,
--
drivers/block/zram/zram_drv.c-2190- */
drivers/block/zram/zram_drv.c:2191:static int zram_bvec_read_partial(struct zram *zram, struct bio_vec *bvec,
drivers/block/zram/zram_drv.c-2192- u32 index, int offset)
--
drivers/block/zram/zram_drv.c-2205-
drivers/block/zram/zram_drv.c:2206:static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
drivers/block/zram/zram_drv.c-2207- u32 index, int offset, struct bio *bio)
--
drivers/block/zram/zram_drv.c-2209- if (is_partial_io(bvec))
drivers/block/zram/zram_drv.c:2210: return zram_bvec_read_partial(zram, bvec, index, offset);
drivers/block/zram/zram_drv.c-2211- return zram_read_page(zram, bvec->bv_page, index, bio);
--
drivers/block/zram/zram_drv.c=2270=static int zram_write_page(struct zram *zram, struct page *page, u32 index)
--
drivers/block/zram/zram_drv.c-2335- */
drivers/block/zram/zram_drv.c:2336:static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec,
drivers/block/zram/zram_drv.c-2337- u32 index, int offset)
--
drivers/block/zram/zram_drv.c-2353-
drivers/block/zram/zram_drv.c:2354:static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec,
drivers/block/zram/zram_drv.c-2355- u32 index, int offset)
--
drivers/block/zram/zram_drv.c-2357- if (is_partial_io(bvec))
drivers/block/zram/zram_drv.c:2358: return zram_bvec_write_partial(zram, bvec, index, offset);
drivers/block/zram/zram_drv.c-2359- return zram_write_page(zram, bvec->bv_page, index);
--
drivers/block/zram/zram_drv.c=2711=static void zram_bio_read(struct zram *zram, struct bio *bio)
--
drivers/block/zram/zram_drv.c-2723-
drivers/block/zram/zram_drv.c:2724: if (zram_bvec_read(zram, &bv, index, offset, bio) < 0) {
drivers/block/zram/zram_drv.c-2725- atomic64_inc(&zram->stats.failed_reads);
--
drivers/block/zram/zram_drv.c=2742=static void zram_bio_write(struct zram *zram, struct bio *bio)
--
drivers/block/zram/zram_drv.c-2754-
drivers/block/zram/zram_drv.c:2755: if (zram_bvec_write(zram, &bv, index, offset) < 0) {
drivers/block/zram/zram_drv.c-2756- atomic64_inc(&zram->stats.failed_writes);
]
|
| 36/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 37608
output: 42
thoughts: 237
Thoughts: **My Zram Indexing Conundrum**
Okay, so I'm diving into this Zram code, and the first thing that jumps out is that the `index` variable, which is used all over the place, is consistently a `u32`. No surprises there. But then I started thinking about the implications. If the `disksize` of the Zram device is really massive, significantly larger than `(u64)U32_MAX << PAGE_SHIFT`, then the derived `num_pages` variable will, of course, exceed the capacity of a `u32` (i.e. larger than `U32_MAX`).
Now, this is where things get interesting and architecture-dependent. On a 32-bit system, the `size_t` type is 32 bits wide, so `num_pages` is inherently limited to `U32_MAX`, which keeps things somewhat sane. However, on a 64-bit system, `size_t` is 64 bits, allowing `num_pages` to grow much larger. This means we *can* have a `num_pages` value larger than `U32_MAX`.
If this happens, the `zram->table` is allocated with `num_pages` entries – that's the setup. But the real problem hits me: `index` is *still* a `u32`. This creates a critical vulnerability: When we access `zram->table` using `index`, we're going to get *wrap-around* issues if `num_pages` exceeds the maximum value that `index` can represent. This could lead to a massive data corruption!
Wait a second...I need to trace where this `index` variable comes from. Ah, it's calculated from the `bio->bi_iter.bi_sector` field. Okay, that's the key. Now, I need to understand how `zram_bio_read` and `zram_bio_write` use this `index`, which is how it affects the `zram->table`. That's where I need to focus my attention.
|
| 37/2 |
2026/09/11 00:22 |
tool |
read-file |
0m
Args: map[File:drivers/block/zram/zram_drv.c FirstLine:2711 LineCount:50]
Results: map[Contents:2711: static void zram_bio_read(struct zram *zram, struct bio *bio)
2712: {
2713: unsigned long start_time = bio_start_io_acct(bio);
2714: struct bvec_iter iter = bio->bi_iter;
2715:
2716: do {
2717: u32 index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;
2718: u32 offset = (iter.bi_sector & (SECTORS_PER_PAGE - 1)) <<
2719: SECTOR_SHIFT;
2720: struct bio_vec bv = bio_iter_iovec(bio, iter);
2721:
2722: bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset);
2723:
2724: if (zram_bvec_read(zram, &bv, index, offset, bio) < 0) {
2725: atomic64_inc(&zram->stats.failed_reads);
2726: bio->bi_status = BLK_STS_IOERR;
2727: break;
2728: }
2729: flush_dcache_page(bv.bv_page);
2730:
2731: slot_lock(zram, index);
2732: mark_slot_accessed(zram, index);
2733: slot_unlock(zram, index);
2734:
2735: bio_advance_iter_single(bio, &iter, bv.bv_len);
2736: } while (iter.bi_size);
2737:
2738: bio_end_io_acct(bio, start_time);
2739: bio_endio(bio);
2740: }
2741:
2742: static void zram_bio_write(struct zram *zram, struct bio *bio)
2743: {
2744: unsigned long start_time = bio_start_io_acct(bio);
2745: struct bvec_iter iter = bio->bi_iter;
2746:
2747: do {
2748: u32 index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;
2749: u32 offset = (iter.bi_sector & (SECTORS_PER_PAGE - 1)) <<
2750: SECTOR_SHIFT;
2751: struct bio_vec bv = bio_iter_iovec(bio, iter);
2752:
2753: bv.bv_len = min_t(u32, bv.bv_len, PAGE_SIZE - offset);
2754:
2755: if (zram_bvec_write(zram, &bv, index, offset) < 0) {
2756: atomic64_inc(&zram->stats.failed_writes);
2757: bio->bi_status = BLK_STS_IOERR;
2758: break;
2759: }
2760:
]
|
| 38/2 |
2026/09/11 00:22 |
llm |
expert |
0m
Model:
Tokens:
input: 39215
output: 431
thoughts: 969
Thoughts: **Zram Addressing Wrap-Around Vulnerability Analysis**
Okay, so I'm digging into this `zram` code, and I need to make sure I understand how memory is addressed. Let's see... the `index` variable, crucial for indexing the `zram->table`, is a `u32`, right? Confirmed. Now, `iter.bi_sector` is a `sector_t`, which is a `u64`. I also remember that `SECTORS_PER_PAGE_SHIFT` is calculated as `PAGE_SHIFT - SECTOR_SHIFT`, which makes sense. Therefore, the `index` calculation is simply `iter.bi_sector >> 3`.
Aha! This is where things get interesting. If `iter.bi_sector` gets larger than `U32_MAX << 3`, the value of `index` will be truncated down to 32 bits. This means, if a `zram` device's physical size is over `U32_MAX` pages (around 16TB with 4KB pages), any attempts to access pages beyond that will *wrap around* and try to access the beginning of the `zram->table`!
Is this a security issue? Initially, I'm thinking, could a user create a large zram device, write beyond its supposed size, and cause memory corruption? But wait. This is really just aliasing *within* the zram device itself. It's *data* corruption, not kernel memory corruption, as the access remains within the bounds of the `zram->table` allocation. Writing to a certain offset within the device overwrites data at another offset. That said, it's still a pretty serious data corruption concern for the user!
Now, let's consider another scenario. What if `num_pages` is *smaller* than `U32_MAX`, but `disksize` is large? No, because `num_pages` is computed directly from `disksize >> PAGE_SHIFT`. If, say, `disksize` is 32TB, `num_pages` will be `2 * U32_MAX`. Even though the table is allocated with `2 * U32_MAX` entries (on a 64-bit system), the `index` variable *still* wraps at `U32_MAX`. So the second half of the table is never accessed.
What if `num_pages` is intentionally smaller than `U32_MAX`? I quickly realize that this can't happen because the block layer will prevent access beyond the "advertised" capacity. The capacity is determined by `set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT)`. That means the block layer will always check `iter.bi_sector < capacity`. If the `capacity` is large (say, greater than `U32_MAX << 3`), then `iter.bi_sector` can also be large, which will cause `index` to wrap around. But in this situation, it will wrap around to a *valid* index in the `zram->table`, because `num_pages` will also be large.
However, I'm now thinking about the effects on 32-bit systems! On a 32-bit system, `size_t` is 32-bit. So, if `disksize` is, say, 32TB, then `disksize >> PAGE_SHIFT` will be `2 * U32_MAX`. When it's truncated to 32-bit, `num_pages` will be 0! Since `vzalloc(0)` returns `NULL` and errors, the device's size won't change.
But what if `disksize` is something like `16TB + 4KB`? Then `disksize >> PAGE_SHIFT` becomes `U32_MAX + 1`. After truncation to 32-bits, `num_pages` is now 1. So, `vzalloc` *allocates* a single entry. The `zram->disksize` is updated to be `16TB + 4KB`. `set_capacity_and_notify` will set the capacity to `(16TB + 4KB) >> 9`, making the device's advertised size 16TB + 4KB!
Here's the problem. The zram table *only has one entry*. If a user does a read or write operation to sector 8, which corresponds to page 1, `iter.bi_sector` will be 8 and `index` will be `8 >> 3 = 1`. But the `zram->table` has only one entry
|
| 39/2 |
2026/09/11 00:23 |
tool |
codeexpert |
0m
Error:
Args: map[Question:In drivers/block/zram/zram_drv.c, `disksize_store` parses `disksize` as `u64`.
Then it calls `zram_meta_alloc(zram, disksize)`.
In `zram_meta_alloc`, `num_pages = disksize >> PAGE_SHIFT;` where `num_pages` is `size_t`.
On a 32-bit system, `size_t` is 32-bit.
If `disksize` is `(1ULL << 44) + 4096` (which is 16TB + 4KB), then `disksize >> 12` is `(1ULL << 32) + 1`.
When assigned to `size_t num_pages`, it truncates to 1.
So `vzalloc` allocates an array of 1 entry.
Then `zram_meta_alloc` succeeds.
Then `disksize_store` sets `zram->disksize = disksize;` and calls `set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT);`.
Now the block device has a capacity of 16TB + 4KB.
If a user reads/writes to the block device at offset 4096, `iter.bi_sector` is 8.
In `zram_bio_read`/`zram_bio_write`, `index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;` which is `8 >> 3 = 1`.
Then it accesses `zram->table[1]`, which is out-of-bounds because the table only has 1 entry!
Is this analysis correct? Can an unprivileged user trigger this if they have write access to `/sys/block/zram0/disksize`?]
|
| 40/3 |
2026/09/11 00:23 |
agent |
codeexpert |
0m
Model:
Error:
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
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: In drivers/block/zram/zram_drv.c, `disksize_store` parses `disksize` as `u64`.
Then it calls `zram_meta_alloc(zram, disksize)`.
In `zram_meta_alloc`, `num_pages = disksize >> PAGE_SHIFT;` where `num_pages` is `size_t`.
On a 32-bit system, `size_t` is 32-bit.
If `disksize` is `(1ULL << 44) + 4096` (which is 16TB + 4KB), then `disksize >> 12` is `(1ULL << 32) + 1`.
When assigned to `size_t num_pages`, it truncates to 1.
So `vzalloc` allocates an array of 1 entry.
Then `zram_meta_alloc` succeeds.
Then `disksize_store` sets `zram->disksize = disksize;` and calls `set_capacity_and_notify(zram->disk, zram->disksize >> SECTOR_SHIFT);`.
Now the block device has a capacity of 16TB + 4KB.
If a user reads/writes to the block device at offset 4096, `iter.bi_sector` is 8.
In `zram_bio_read`/`zram_bio_write`, `index = iter.bi_sector >> SECTORS_PER_PAGE_SHIFT;` which is `8 >> 3 = 1`.
Then it accesses `zram->table[1]`, which is out-of-bounds because the table only has 1 entry!
Is this analysis correct? Can an unprivileged user trigger this if they have write access to `/sys/block/zram0/disksize`?
|
| 41/4 |
2026/09/11 00:23 |
llm |
codeexpert |
0m
Model:
Error:
|