| 0/0 |
2026/09/26 00:03 |
flow |
moderation |
42m
Results: map[Actionable:true Explanation:The bug report is **actionable** and **self-consistent**.
### Detailed Analysis:
1. **Presence of All Three Required Stack Traces**:
- **Bad Memory Access Stack**: Task 6764 encounters a slab-use-after-free in
`rb_is_reader_page` (inlined in `rb_move_tail` at
`kernel/trace/ring_buffer.c:3964`) while reserving space for an event in the
ring buffer (`__rb_reserve_next` via `trace_lock_release`).
- **Allocation Stack**: Task 6453 allocated the object in
`__rb_allocate_pages` (`kernel/trace/ring_buffer.c:2483`) via
`alloc_cpu_page()` during ring buffer expansion (`ring_buffer_resize`).
- **Free Stack**: Task 10552 freed the object in `free_buffer_page`
(`kernel/trace/ring_buffer.c:418`) called by `rb_remove_pages`
(`kernel/trace/ring_buffer.c:3169`) during ring buffer downsizing
(`ring_buffer_resize`).
2. **Subsystem and Object Type Consistency**:
- All three stacks belong to the exact same kernel subsystem: the tracing
ring buffer (`kernel/trace/ring_buffer.c`).
- All three stacks manipulate the exact same struct: `struct buffer_page`.
- `struct buffer_page` has a size of 64 bytes and is allocated from the
`kmalloc-64` slab cache.
- The reported access is a read of 8 bytes at offset 0 (`ffff888033712280`,
located 0 bytes inside the freed 64-byte region `[ffff888033712280,
ffff8880337122c0)`). This precisely matches `list.next` (the first field in
`struct buffer_page` / `struct list_head`) being dereferenced by
`rb_is_reader_page()`:
```c
struct list_head *list = page->list.prev;
return rb_list_head(list->next) != &page->list;
```
3. **Plausible Bug Mechanism**:
- Resizing the ring buffer down via `tracing_entries_write` /
`ring_buffer_resize` removes pages via `rb_remove_pages()` and frees them
(`free_buffer_page()`).
- Concurrently, an active writer interrupted or preempted during
reserve/commit operations (`__rb_reserve_next` / `rb_move_tail`) traverses or
references page pointers (such as `cpu_buffer->commit_page`), accessing a
`struct buffer_page` that has already been unlinked and freed.
Because the report contains all three coherent stack traces with matching data
structures, offsets, and a clear race condition mechanism, it provides
sufficient information to root-cause and fix the bug.]
|
| 1/1 |
2026/09/26 00:03 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/5c487f62272787bede28938e5ebcf7402956d688]
|
| 2/1 |
2026/09/26 00:04 |
action |
kernel-builder |
17m
Results: map[KernelObj:/app/workdir/cache/build/442e08fd4e8b00c63cc832833648d96b0e60f423]
|
| 3/1 |
2026/09/26 00:21 |
action |
codesearch-prepare |
12m
Results: map[Index:codesearch-index]
|
| 4/1 |
2026/09/26 00:33 |
agent |
expert |
12m
Model:
Results:
Instruction: You are an experienced Linux kernel developer tasked with determining if the given kernel bug
report is actionable or not. Actionable means that it contains enough info to root cause
the underlying bug, and that the report is self-consistent and makes sense, rather than
e.g. a one-off nonsensical crash induced by a previous memory corruption.
The bug report is about a use-after-free bug generated by KASAN tool.
It should contain 3 stack traces: the bad memory access stack, the heap block allocation stack,
and the heap block free stack. If the report does not contain 3 stacks, it's not actionable.
All 3 stack traces should be related to the same object type,
and usually be in the same kernel subsystem (at least leaf stack frames).
An example of an actionable and consistent report would be: first access stack relates
to an access to a field of struct Foo, allocation/free stacks relate to allocation/free
of the struct Foo.
In inconsistent/nonsensical reports an access may be to a struct Foo, but allocation
stack allocates a different structure in a different subsystem.
Look for other suspicious signals/inconsistencies that can make this report hard to
debug/understand.
In the final reply explain why you think the report is self-consistent and actionable,
or why it's inconsistent and/or not actionable.
Use the provided tools to confirm any assumptions, variables/fields being accessed, etc.
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 bug report is:
==================================================================
BUG: KASAN: slab-use-after-free in rb_is_reader_page kernel/trace/ring_buffer.c:1353 [inline]
BUG: KASAN: slab-use-after-free in rb_move_tail+0x1653/0x19e0 kernel/trace/ring_buffer.c:3964
Read of size 8 at addr ffff888033712280 by task syz-executor/6764
CPU: 0 UID: 0 PID: 6764 Comm: syz-executor Tainted: G L syzkaller #0 PREEMPT(full)
Tainted: [L]=SOFTLOCKUP
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 08/26/2026
Call Trace:
<IRQ>
__dump_stack lib/dump_stack.c:94 [inline]
dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
print_address_description mm/kasan/report.c:378 [inline]
print_report+0x13d/0x4b0 mm/kasan/report.c:482
kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
rb_is_reader_page kernel/trace/ring_buffer.c:1353 [inline]
rb_move_tail+0x1653/0x19e0 kernel/trace/ring_buffer.c:3964
__rb_reserve_next.constprop.0+0x8cf/0x1640 kernel/trace/ring_buffer.c:4854
rb_reserve_next_event kernel/trace/ring_buffer.c:5010 [inline]
ring_buffer_lock_reserve+0x49a/0x1220 kernel/trace/ring_buffer.c:5069
__trace_buffer_lock_reserve kernel/trace/trace.h:1677 [inline]
trace_event_buffer_lock_reserve+0x123/0x6f0 kernel/trace/trace.c:1924
trace_event_buffer_reserve+0x1f9/0x350 kernel/trace/trace_events.c:715
do_trace_event_raw_event_lock include/trace/events/lock.h:49 [inline]
trace_event_raw_event_lock+0x124/0x2b0 include/trace/events/lock.h:49
__do_trace_lock_release include/trace/events/lock.h:68 [inline]
trace_lock_release include/trace/events/lock.h:68 [inline]
lock_release+0x218/0x310 kernel/locking/lockdep.c:5954
__raw_spin_unlock_irqrestore include/linux/spinlock_api_smp.h:208 [inline]
_raw_spin_unlock_irqrestore+0x1a/0x80 kernel/locking/spinlock.c:221
debug_object_activate+0x343/0x4b0 lib/debugobjects.c:891
debug_hrtimer_activate kernel/time/hrtimer.c:486 [inline]
debug_activate kernel/time/hrtimer.c:529 [inline]
enqueue_hrtimer+0x75/0x2f0 kernel/time/hrtimer.c:1136
__run_hrtimer kernel/time/hrtimer.c:2090 [inline]
__hrtimer_run_queues+0x6ed/0x9c0 kernel/time/hrtimer.c:2131
hrtimer_interrupt+0x441/0xaa0 kernel/time/hrtimer.c:2250
local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1051 [inline]
__sysvec_apic_timer_interrupt+0x109/0x470 arch/x86/kernel/apic/apic.c:1068
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
sysvec_apic_timer_interrupt+0x51/0xc0 arch/x86/kernel/apic/apic.c:1062
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
RIP: 0010:in_softirq_really kernel/kcov.c:167 [inline]
RIP: 0010:check_kcov_mode kernel/kcov.c:179 [inline]
RIP: 0010:__sanitizer_cov_trace_pc+0x27/0x70 kernel/kcov.c:213
Code: 90 90 90 f3 0f 1e fa 65 48 8b 05 6c 80 80 12 48 8b 34 24 65 48 8b 15 50 80 80 12 48 63 c8 a9 00 01 00 ff 74 1e f6 c4 01 74 44 <a9> 00 00 00 0f 75 3d f7 c1 00 00 00 f0 75 35 8b 82 3c 17 00 00 85
RSP: 0018:ffffc90000007c80 EFLAGS: 00000202
RAX: 0000000000000104 RBX: ffffc90000007d00 RCX: 0000000000000104
RDX: ffff88802e8e4b00 RSI: ffffffff821554d0 RDI: ffffc90000007d00
RBP: ffff88801d29d600 R08: 0000000000000001 R09: 0000000000000000
R10: 0000000000000001 R11: 0000000000000001 R12: ffffffff8edec4a0
R13: 0000000000000026 R14: ffffffff8bf19b80 R15: ffff88801d29d600
trace_event_buffer_reserve+0x20/0x350 kernel/trace/trace_events.c:699
do_trace_event_raw_event_lock include/trace/events/lock.h:49 [inline]
trace_event_raw_event_lock+0x124/0x2b0 include/trace/events/lock.h:49
__do_trace_lock_release include/trace/events/lock.h:68 [inline]
trace_lock_release include/trace/events/lock.h:68 [inline]
lock_release+0x218/0x310 kernel/locking/lockdep.c:5954
rcu_lock_release include/linux/rcupdate.h:319 [inline]
rcu_read_unlock include/linux/rcupdate.h:880 [inline]
taprio_dequeue+0x161/0x5f0 net/sched/sch_taprio.c:868
dequeue_skb net/sched/sch_generic.c:322 [inline]
qdisc_restart net/sched/sch_generic.c:427 [inline]
__qdisc_run+0x1be/0x1b20 net/sched/sch_generic.c:445
qdisc_run include/net/pkt_sched.h:121 [inline]
qdisc_run include/net/pkt_sched.h:118 [inline]
net_tx_action+0x549/0xf50 net/core/dev.c:5915
handle_softirqs+0x1e6/0x9d0 kernel/softirq.c:645
__do_softirq kernel/softirq.c:679 [inline]
invoke_softirq kernel/softirq.c:519 [inline]
__irq_exit_rcu+0x16a/0x210 kernel/softirq.c:758
irq_exit_rcu+0x9/0x30 kernel/softirq.c:775
instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
sysvec_apic_timer_interrupt+0xa3/0xc0 arch/x86/kernel/apic/apic.c:1062
</IRQ>
<TASK>
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
RIP: 0010:__rb_reserve_next.constprop.0+0x394/0x1640 kernel/trace/ring_buffer.c:4859
Code: 89 ff e8 8f 2b fd ff 4d 39 e7 0f 85 c4 07 00 00 e8 a1 31 fd ff 48 89 da 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 80 3c 02 00 <0f> 85 f5 0f 00 00 4c 8b 7c 24 28 be 08 00 00 00 4c 8b 23 4c 89 ff
RSP: 0018:ffffc90005f1f3e8 EFLAGS: 00000246
RAX: dffffc0000000000 RBX: ffffc90005f1f530 RCX: 0000000000000002
RDX: 1ffff92000be3ea6 RSI: ffffffff820eee0f RDI: ffff88802e8e4b00
RBP: ffff88801c095000 R08: 0000000000000006 R09: 0000000000000228
R10: 0000000000000228 R11: 0000000000000000 R12: 0000000000000228
R13: ffff88801c095150 R14: ffff88801c08c680 R15: 0000000000000228
rb_reserve_next_event kernel/trace/ring_buffer.c:5010 [inline]
ring_buffer_lock_reserve+0x49a/0x1220 kernel/trace/ring_buffer.c:5069
__trace_buffer_lock_reserve kernel/trace/trace.h:1677 [inline]
trace_event_buffer_lock_reserve+0x123/0x6f0 kernel/trace/trace.c:1924
trace_event_buffer_reserve+0x1f9/0x350 kernel/trace/trace_events.c:715
do_trace_event_raw_event_lock include/trace/events/lock.h:49 [inline]
trace_event_raw_event_lock+0x124/0x2b0 include/trace/events/lock.h:49
__do_trace_lock_release include/trace/events/lock.h:68 [inline]
trace_lock_release include/trace/events/lock.h:68 [inline]
lock_release+0x218/0x310 kernel/locking/lockdep.c:5954
might_alloc include/linux/sched/mm.h:316 [inline]
slab_pre_alloc_hook mm/slub.c:4636 [inline]
slab_alloc_node mm/slub.c:4974 [inline]
kmem_cache_alloc_noprof+0x63/0x6a0 mm/slub.c:5010
anon_vma_alloc mm/rmap.c:94 [inline]
anon_vma_fork+0x8d/0x6a0 mm/rmap.c:391
dup_mmap+0x10e6/0x2370 mm/mmap.c:1781
dup_mm kernel/fork.c:1543 [inline]
copy_mm kernel/fork.c:1595 [inline]
copy_process+0x4811/0x8370 kernel/fork.c:2310
kernel_clone+0x176/0x9d0 kernel/fork.c:2769
__do_sys_clone+0xd9/0x120 kernel/fork.c:2911
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:0x7f122a9c6bd2
Code: 89 e7 e8 71 8b f7 ff 45 31 c0 31 d2 31 f6 64 48 8b 04 25 10 00 00 00 bf 11 00 20 01 4c 8d 90 d0 02 00 00 b8 38 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 66 89 c5 85 c0 75 3b 64 48 8b 04 25 10 00 00
RSP: 002b:00007fffda742550 EFLAGS: 00000246 ORIG_RAX: 0000000000000038
RAX: ffffffffffffffda RBX: 00007fffda742550 RCX: 00007f122a9c6bd2
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000001200011
RBP: 00007fffda7426dc R08: 0000000000000000 R09: 0000000000000001
R10: 000055557d0397d0 R11: 0000000000000246 R12: 0000000000000001
R13: 000055557d04ca10 R14: 000000000008d88f R15: 00007fffda742730
</TASK>
Allocated by task 6453:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
poison_kmalloc_redzone mm/kasan/common.c:398 [inline]
__kasan_kmalloc+0xaa/0xb0 mm/kasan/common.c:415
kasan_kmalloc include/linux/kasan.h:263 [inline]
__do_kmalloc_node mm/slub.c:5414 [inline]
__kmalloc_node_noprof+0x342/0x880 mm/slub.c:5426
_kmalloc_node_noprof include/linux/slab.h:1200 [inline]
__rb_allocate_pages+0x308/0xfc0 kernel/trace/ring_buffer.c:2483
ring_buffer_resize+0x71c/0x1ed0 kernel/trace/ring_buffer.c:3357
__tracing_resize_ring_buffer.part.0+0x52/0x1f0 kernel/trace/trace.c:4740
__tracing_resize_ring_buffer kernel/trace/trace.c:4734 [inline]
tracing_update_buffers+0xd4/0xf0 kernel/trace/trace.c:4979
ftrace_event_write+0x14a/0x2c0 kernel/trace/trace_events.c:1562
vfs_write+0x2aa/0x1050 fs/read_write.c:685
ksys_write+0x12a/0x250 fs/read_write.c:739
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
Freed by task 10552:
kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
kasan_save_track+0x14/0x30 mm/kasan/common.c:78
kasan_save_free_info+0x3b/0x70 mm/kasan/generic.c:584
poison_slab_object mm/kasan/common.c:253 [inline]
__kasan_slab_free+0x5f/0x80 mm/kasan/common.c:285
kasan_slab_free include/linux/kasan.h:235 [inline]
slab_free_hook mm/slub.c:2748 [inline]
slab_free mm/slub.c:6508 [inline]
kfree+0x22b/0x6d0 mm/slub.c:6801
free_buffer_page kernel/trace/ring_buffer.c:418 [inline]
rb_remove_pages kernel/trace/ring_buffer.c:3169 [inline]
rb_update_pages+0x675/0xd60 kernel/trace/ring_buffer.c:3268
update_pages_handler kernel/trace/ring_buffer.c:3279 [inline]
ring_buffer_resize+0x14af/0x1ed0 kernel/trace/ring_buffer.c:3389
__tracing_resize_ring_buffer.part.0+0x52/0x1f0 kernel/trace/trace.c:4740
__tracing_resize_ring_buffer kernel/trace/trace.c:4734 [inline]
tracing_resize_ring_buffer+0x10b/0x160 kernel/trace/trace.c:4795
tracing_entries_write+0x15d/0x220 kernel/trace/trace.c:5741
do_loop_readv_writev fs/read_write.c:851 [inline]
do_loop_readv_writev fs/read_write.c:836 [inline]
vfs_writev+0x5ed/0xdd0 fs/read_write.c:1060
do_writev+0x13e/0x340 fs/read_write.c:1104
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
The buggy address belongs to the object at ffff888033712280
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 0 bytes inside of
freed 64-byte region [ffff888033712280, ffff8880337122c0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x33712
flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 00fff00000000000 ffff88801c0348c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0xd2cc0(GFP_KERNEL|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 12447819587
set_page_owner include/linux/page_owner.h:33 [inline]
post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1871
prep_new_page mm/page_alloc.c:1879 [inline]
get_page_from_freelist+0x110d/0x35d0 mm/page_alloc.c:3943
__alloc_frozen_pages_noprof+0x2eb/0x3300 mm/page_alloc.c:5436
alloc_slab_page mm/slub.c:3347 [inline]
allocate_slab mm/slub.c:3462 [inline]
new_slab+0xa9/0x6e0 mm/slub.c:3513
refill_objects+0xe3/0x410 mm/slub.c:7417
refill_sheaf mm/slub.c:2885 [inline]
__pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4774
alloc_from_pcs mm/slub.c:4850 [inline]
slab_alloc_node mm/slub.c:4984 [inline]
__do_kmalloc_node mm/slub.c:5413 [inline]
__kmalloc_noprof+0x67c/0x840 mm/slub.c:5439
_kmalloc_noprof include/linux/slab.h:995 [inline]
_kzalloc_noprof include/linux/slab.h:1312 [inline]
handler_new_ref+0x1ab/0xc60 drivers/media/v4l2-core/v4l2-ctrls-core.c:1959
v4l2_ctrl_add_handler drivers/media/v4l2-core/v4l2-ctrls-core.c:2520 [inline]
v4l2_ctrl_add_handler+0x223/0x300 drivers/media/v4l2-core/v4l2-ctrls-core.c:2494
vivid_create_controls+0x33bd/0x3e80 drivers/media/test-drivers/vivid/vivid-ctrls.c:2071
vivid_create_instance drivers/media/test-drivers/vivid/vivid-core.c:1933 [inline]
vivid_probe.cold+0x4f1e/0x921e drivers/media/test-drivers/vivid/vivid-core.c:2095
platform_probe+0x106/0x1d0 drivers/base/platform.c:1507
call_driver_probe drivers/base/dd.c:628 [inline]
really_probe+0x241/0xa60 drivers/base/dd.c:706
__driver_probe_device+0x210/0x460 drivers/base/dd.c:868
driver_probe_device+0x4a/0x140 drivers/base/dd.c:898
__driver_attach+0x21f/0x5b0 drivers/base/dd.c:1292
page_owner free stack trace missing
Memory state around the buggy address:
ffff888033712180: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888033712200: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff888033712280: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff888033712300: 00 00 00 00 00 00 fc fc fc fc fc fc fc fc fc fc
ffff888033712380: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================
----------------
Code disassembly (best guess):
0: 90 nop
1: 90 nop
2: 90 nop
3: f3 0f 1e fa endbr64
7: 65 48 8b 05 6c 80 80 mov %gs:0x1280806c(%rip),%rax # 0x1280807b
e: 12
f: 48 8b 34 24 mov (%rsp),%rsi
13: 65 48 8b 15 50 80 80 mov %gs:0x12808050(%rip),%rdx # 0x1280806b
1a: 12
1b: 48 63 c8 movslq %eax,%rcx
1e: a9 00 01 00 ff test $0xff000100,%eax
23: 74 1e je 0x43
25: f6 c4 01 test $0x1,%ah
28: 74 44 je 0x6e
* 2a: a9 00 00 00 0f test $0xf000000,%eax <-- trapping instruction
2f: 75 3d jne 0x6e
31: f7 c1 00 00 00 f0 test $0xf0000000,%ecx
37: 75 35 jne 0x6e
39: 8b 82 3c 17 00 00 mov 0x173c(%rdx),%eax
3f: 85 .byte 0x85
Reply: The bug report is **actionable** and **self-consistent**.
### Detailed Analysis:
1. **Presence of All Three Required Stack Traces**:
- **Bad Memory Access Stack**: Task 6764 encounters a slab-use-after-free in `rb_is_reader_page` (inlined in `rb_move_tail` at `kernel/trace/ring_buffer.c:3964`) while reserving space for an event in the ring buffer (`__rb_reserve_next` via `trace_lock_release`).
- **Allocation Stack**: Task 6453 allocated the object in `__rb_allocate_pages` (`kernel/trace/ring_buffer.c:2483`) via `alloc_cpu_page()` during ring buffer expansion (`ring_buffer_resize`).
- **Free Stack**: Task 10552 freed the object in `free_buffer_page` (`kernel/trace/ring_buffer.c:418`) called by `rb_remove_pages` (`kernel/trace/ring_buffer.c:3169`) during ring buffer downsizing (`ring_buffer_resize`).
2. **Subsystem and Object Type Consistency**:
- All three stacks belong to the exact same kernel subsystem: the tracing ring buffer (`kernel/trace/ring_buffer.c`).
- All three stacks manipulate the exact same struct: `struct buffer_page`.
- `struct buffer_page` has a size of 64 bytes and is allocated from the `kmalloc-64` slab cache.
- The reported access is a read of 8 bytes at offset 0 (`ffff888033712280`, located 0 bytes inside the freed 64-byte region `[ffff888033712280, ffff8880337122c0)`). This precisely matches `list.next` (the first field in `struct buffer_page` / `struct list_head`) being dereferenced by `rb_is_reader_page()`:
```c
struct list_head *list = page->list.prev;
return rb_list_head(list->next) != &page->list;
```
3. **Plausible Bug Mechanism**:
- Resizing the ring buffer down via `tracing_entries_write` / `ring_buffer_resize` removes pages via `rb_remove_pages()` and frees them (`free_buffer_page()`).
- Concurrently, an active writer interrupted or preempted during reserve/commit operations (`__rb_reserve_next` / `rb_move_tail`) traverses or references page pointers (such as `cpu_buffer->commit_page`), accessing a `struct buffer_page` that has already been unlinked and freed.
Because the report contains all three coherent stack traces with matching data structures, offsets, and a clear race condition mechanism, it provides sufficient information to root-cause and fix the bug.
|
| 5/2 |
2026/09/26 00:33 |
llm |
expert |
0m
Model:
Tokens:
input: 11587
output: 38
thoughts: 1982
Thoughts: **Analysis of Kernel Bug Report**
Alright, let's break this down. My task is to determine if this kernel bug report is actionable. I need to figure out if it's self-consistent and contains enough information to root cause the use-after-free. The report must contain three stack traces: the bad memory access, the allocation, and the free. Furthermore, the traces must be related to the same object type and ideally within the same kernel subsystem.
Looking at the report, it's a KASAN slab-use-after-free in `ring_buffer.c`, specifically at `rb_move_tail`. That's a good start.
I can see the "Read of size 8" at a specific address, so the memory access is clear. Now, let's examine the stack traces to see if the requirements are satisfied:
The crash stack shows the call trace: `rb_move_tail`, which calls `rb_is_reader_page` which caused the use-after-free, both functions are in `kernel/trace/ring_buffer.c`. That looks consistent, so far so good.
Next, I need to check the allocation stack. This one includes `__rb_allocate_pages`, also within `kernel/trace/ring_buffer.c`, which implies that the allocation is also related to the ring buffer.
Finally, the free stack is reported with `free_buffer_page`, `rb_remove_pages`, and `rb_update_pages`, again all within `kernel/trace/ring_buffer.c`. All three stack traces are clearly within the same kernel subsystem and point to the same ring buffer.
I need to confirm the object type, which is `kmalloc-64` of size 64. The bug is a read of size 8 at address ffff888033712280, 0 bytes inside a freed 64-byte region. This is exactly what I'd expect for a use-after-free in a kmalloc slab. I can use the tool to make sure that the object type, and related variables/fields being accessed are correct.
This report seems self-consistent. The allocation, free, and access all occur within the same subsystem, and the stacks all appear to be related to the ring buffer and its underlying kmalloc allocation. There are three stack traces, and the information is sufficient to root cause the bug, at least initially.
I am confident that this is an actionable bug report. Now I can use the `set-results` tool and move on.
|
| 6/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:1345 LineCount:30]
Results: map[Contents:1345: * The unique thing about the reader page, is that, if the
1346: * writer is ever on it, the previous pointer never points
1347: * back to the reader page.
1348: */
1349: static bool rb_is_reader_page(struct buffer_page *page)
1350: {
1351: struct list_head *list = page->list.prev;
1352:
1353: return rb_list_head(list->next) != &page->list;
1354: }
1355:
1356: /*
1357: * rb_set_list_to_head - set a list_head to be pointing to head.
1358: */
1359: static void rb_set_list_to_head(struct list_head *list)
1360: {
1361: unsigned long *ptr;
1362:
1363: ptr = (unsigned long *)&list->next;
1364: *ptr |= RB_PAGE_HEAD;
1365: *ptr &= ~RB_PAGE_UPDATE;
1366: }
1367:
1368: /*
1369: * rb_head_page_activate - sets up head page
1370: */
1371: static void rb_head_page_activate(struct ring_buffer_per_cpu *cpu_buffer)
1372: {
1373: struct buffer_page *head;
1374:
]
|
| 7/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 14589
output: 37
thoughts: 104
Thoughts: **Decoding a Kernel Ring Buffer Condition**
Okay, here's what's running through my head. I'm looking at this line, 1353, within `rb_is_reader_page()` in the ring buffer code: `return rb_list_head(list->next) != &page->list;`. Hmm, something seems off here. The code seems to be referencing the `next` pointer of `list` variable. But *hang on*, wasn't `list` defined as `page->list.prev`? That is a `list_head` not `list_head *`, so the arrow operator is concerning. This raises a red flag. I need to understand what `struct buffer_page` *actually* contains. I need to be sure that the code is accessing the correct fields, and that the logic is sound. Time to go back and check the definition of `struct buffer_page`. I'll head over to `kernel/trace/ring_buffer.c` and dig into it.
|
| 8/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:380 LineCount:50]
Results: map[Contents: 380: }
381:
382: static __always_inline long rb_data_page_commit(struct buffer_data_page *dpage)
383: {
384: return local_read(&dpage->commit);
385: }
386:
387: static __always_inline long rb_data_page_size(struct buffer_data_page *dpage)
388: {
389: return rb_data_page_commit(dpage) & ~RB_MISSED_MASK;
390: }
391:
392: static __always_inline unsigned int rb_page_commit(struct buffer_page *bpage)
393: {
394: return rb_data_page_commit(bpage->page);
395: }
396:
397: static __always_inline unsigned int rb_page_size(struct buffer_page *bpage)
398: {
399: return rb_data_page_size(bpage->page);
400: }
401:
402: /**
403: * rb_page_capacity - Get the capacity of a buffer page
404: * @bpage: The buffer page
405: *
406: * Return: The maximum size available for events in the given buffer page.
407: */
408: static __always_inline unsigned int rb_page_capacity(struct buffer_page *bpage)
409: {
410: return (PAGE_SIZE << bpage->order) - BUF_PAGE_HDR_SIZE;
411: }
412:
413: static void free_buffer_page(struct buffer_page *bpage)
414: {
415: /* Range pages are not to be freed */
416: if (!bpage->range)
417: free_pages((unsigned long)bpage->page, bpage->order);
418: kfree(bpage);
419: }
420:
421: /*
422: * For best performance, allocate cpu buffer data cache line sized
423: * and per CPU.
424: */
425: #define alloc_cpu_buffer(cpu) (struct ring_buffer_per_cpu *) \
426: kzalloc_node(ALIGN(sizeof(struct ring_buffer_per_cpu), \
427: cache_line_size()), GFP_KERNEL, cpu_to_node(cpu))
428:
429: #define alloc_cpu_page(cpu) (struct buffer_page *) \
]
|
| 9/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 15710
output: 37
thoughts: 116
Thoughts: Here's my analysis of the provided code snippet:
**Analyzing `free_buffer_page` and `alloc_cpu_page`**
Okay, let's dive into this. The first thing I'm examining is this `free_buffer_page` function. It seems pretty straightforward: it's designed to release a buffer page. The crucial check here is this `if (!bpage->range)`. I can infer that `bpage->range` likely indicates whether the buffer page is associated with a range, and if so, it *isn't* freed in the typical manner using `free_pages`. This suggests some sort of special memory management for range pages, possibly related to persistent allocation or a different freeing mechanism altogether. Otherwise, the standard `free_pages` function is called, which handles the actual physical page deallocation, based on the page's order. Finally, the `kfree(bpage)` frees the metadata structure itself. Makes sense.
Now, I need to understand how these pages are allocated in the first place, so I'll need to check out what happens at line 429 and onwards. The function of interest here is `alloc_cpu_page(cpu)`. This is likely where the pages are initially pulled from for use. Now, let's see how these pages are managed within the CPU context. This might expose how these ranges are assigned in the first place, and possibly explain the design choices in `free_buffer_page`. Understanding the allocation process will provide a complete picture of the memory lifecycle. Let's see...
|
| 10/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:425 LineCount:35]
Results: map[Contents: 425: #define alloc_cpu_buffer(cpu) (struct ring_buffer_per_cpu *) \
426: kzalloc_node(ALIGN(sizeof(struct ring_buffer_per_cpu), \
427: cache_line_size()), GFP_KERNEL, cpu_to_node(cpu))
428:
429: #define alloc_cpu_page(cpu) (struct buffer_page *) \
430: kzalloc_node(ALIGN(sizeof(struct buffer_page), \
431: cache_line_size()), GFP_KERNEL, cpu_to_node(cpu))
432:
433: static struct buffer_data_page *alloc_cpu_data(int cpu, int order)
434: {
435: struct buffer_data_page *dpage;
436: struct page *page;
437: gfp_t mflags;
438:
439: /*
440: * __GFP_RETRY_MAYFAIL flag makes sure that the allocation fails
441: * gracefully without invoking oom-killer and the system is not
442: * destabilized.
443: */
444: mflags = GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_COMP | __GFP_ZERO;
445:
446: page = alloc_pages_node(cpu_to_node(cpu), mflags, order);
447: if (!page)
448: return NULL;
449:
450: dpage = page_address(page);
451: rb_init_data_page(dpage);
452:
453: return dpage;
454: }
455:
456: struct rb_irq_work {
457: struct irq_work work;
458: wait_queue_head_t waiters;
459: wait_queue_head_t full_waiters;
]
|
| 11/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 16767
output: 36
thoughts: 78
Thoughts: Okay, here's my take on those thoughts, framed as my own:
**Analyzing `alloc_cpu_page` in the Linux Kernel**
Alright, let's break this down. My initial observation is that `alloc_cpu_page(cpu)` is, under the hood, a call to `kzalloc_node()`. The allocation size looks like it's the size of `struct buffer_page`, aligned to a cache line using `ALIGN()`, and allocated with `GFP_KERNEL` on a specific NUMA node corresponding to the given `cpu`. This is standard kernel memory allocation logic.
The crucial question now becomes: What exactly *is* the size of `struct buffer_page`? I need that information to understand the memory footprint of this operation. Time to utilize the `codesearch-struct-layout` tool to examine the structure definition and understand how it's laid out. That should quickly tell me the alignment and size. From there I can determine if any optimizations are possible, or understand why it's structured this way.
|
| 12/2 |
2026/09/26 00:34 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:kernel/trace/ring_buffer.c Name:buffer_page]
Results: map[Fields:[map[Name:list OffsetBits:0 SizeBits:128] map[Name:write OffsetBits:128 SizeBits:64] map[Name:read OffsetBits:192 SizeBits:32] map[Name:entries OffsetBits:256 SizeBits:64] map[Name:real_end OffsetBits:320 SizeBits:64] map[Name:order OffsetBits:384 SizeBits:32] map[Name:id OffsetBits:416 SizeBits:30] map[Name:range OffsetBits:446 SizeBits:1] map[Name:page OffsetBits:448 SizeBits:64]]]
|
| 13/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 17287
output: 38
thoughts: 439
Thoughts: **Analyzing a Buffer Page Bug**
Okay, let's break this down. First, I'm examining the `struct buffer_page` layout. Looking at the offsets, it seems like `list` starts at offset 0, taking up 16 bytes. Then we have `write` at offset 128, which is 8 bytes. `read` follows at 192, using 4 bytes. Finally, the `page` member is located at offset 448 using 8 bytes. Wait, hold on. The total calculated size is 64 bytes and the alignment is also 64 bytes. That aligns with the 64-byte `kmalloc` region!
Now, the error report... the buggy address, `ffff888033712280`, belongs to a 64-byte object in the `kmalloc-64` cache. The crash occurred at an offset of 0 bytes within this freed region, specifically accessing a 8-byte read! That address, `ffff888033712280`, is precisely the start of the `list` member, which is `list.next`. This is where things are getting interesting.
Digging into `rb_is_reader_page`, we see the line `list = page->list.prev;` and then `return rb_list_head(list->next) != &page->list;`. This attempts to access `list->next`, where `list` is at offset 0 of *another* `struct buffer_page`. The error indicates this page has been freed or is itself the list.
The access to `list->next` after it has been freed indicates a use-after-free vulnerability!
Let's look at `kernel/trace/ring_buffer.c:2483`. Maybe we can learn what is being allocated.
|
| 14/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:2470 LineCount:40]
Results: map[Contents:2470: set_current_oom_origin();
2471:
2472: if (buffer->range_addr_start)
2473: meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2474:
2475: if (buffer->remote) {
2476: desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2477: if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2478: return -EINVAL;
2479: }
2480:
2481: for (i = 0; i < nr_pages; i++) {
2482:
2483: bpage = alloc_cpu_page(cpu_buffer->cpu);
2484: if (!bpage)
2485: goto free_pages;
2486:
2487: rb_check_bpage(cpu_buffer, bpage);
2488:
2489: /*
2490: * Append the pages as for mapped buffers we want to keep
2491: * the order
2492: */
2493: list_add_tail(&bpage->list, pages);
2494:
2495: if (meta) {
2496: /* A range was given. Use that for the buffer page */
2497: bpage->page = rb_range_buffer(cpu_buffer, i + 1);
2498: if (!bpage->page)
2499: goto free_pages;
2500: /* If this is valid from a previous boot */
2501: if (meta->head_buffer)
2502: rb_meta_buffer_update(cpu_buffer, bpage);
2503: bpage->range = 1;
2504: bpage->id = i + 1;
2505: } else if (desc) {
2506: void *p = ring_buffer_desc_page(desc, i + 1);
2507:
2508: if (WARN_ON(!p))
2509: goto free_pages;
]
|
| 15/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 18790
output: 38
thoughts: 111
Thoughts: **Analyzing Buffer Allocation and Freeing**
Okay, let's dive in. Line 2483 is where things get interesting. I see that `bpage` – that crucial `struct buffer_page` – is allocated using `alloc_cpu_page(cpu_buffer->cpu)` within `__rb_allocate_pages`. The specific task responsible for this allocation is task 6453. I need to understand this allocation.
Now, the next logical step is to see what happens when these pages are freed. Let's shift our focus and investigate the free stack. Task 10552's behavior is particularly relevant here, I'm thinking. The key is going to be in `kernel/trace/ring_buffer.c`. I'll cross-reference lines 3169 and 3268. I want to trace the freeing path to fully grasp the lifecycle of these buffer pages.
|
| 16/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:3160 LineCount:40]
Results: map[Contents:3160: local_add(page_entries, &cpu_buffer->overrun);
3161: local_sub(rb_page_commit(to_remove_page), &cpu_buffer->entries_bytes);
3162: local_inc(&cpu_buffer->pages_lost);
3163: }
3164:
3165: /*
3166: * We have already removed references to this list item, just
3167: * free up the buffer_page and its page
3168: */
3169: free_buffer_page(to_remove_page);
3170: nr_removed--;
3171:
3172: } while (to_remove_page != last_page);
3173:
3174: RB_WARN_ON(cpu_buffer, nr_removed);
3175:
3176: return nr_removed == 0;
3177: }
3178:
3179: static bool
3180: rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer)
3181: {
3182: struct list_head *pages = &cpu_buffer->new_pages;
3183: unsigned long flags;
3184: bool success;
3185: int retries;
3186:
3187: /* Can be called at early boot up, where interrupts must not been enabled */
3188: raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
3189: /*
3190: * We are holding the reader lock, so the reader page won't be swapped
3191: * in the ring buffer. Now we are racing with the writer trying to
3192: * move head page and the tail page.
3193: * We are going to adapt the reader page update process where:
3194: * 1. We first splice the start and end of list of new pages between
3195: * the head page and its previous page.
3196: * 2. We cmpxchg the prev_page->next to point from head page to the
3197: * start of new pages list.
3198: * 3. Finally, we update the head->prev to the end of new list.
3199: *
]
|
| 17/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 19777
output: 38
thoughts: 63
Thoughts: Here's my summary, as though I were thinking through the code:
**Freeing and Tracing Ring Buffer Pages**
Okay, so I'm looking at memory management within this system. I see on line 3169, `free_buffer_page(to_remove_page);`. That's the crucial point - we're definitely freeing a `struct buffer_page` here. That makes sense, we need to ensure that the memory is properly returned to the pool after use. It's important to keep track of this freed memory.
And now, moving on, let's zoom in on `kernel/trace/ring_buffer.c`, specifically around line 3268. I'll need to see how the code uses these buffer pages, probably in the context of writing and reading trace data. I'm guessing that part of the trace implementation handles these pages as a linked list or some data structure. I want to see if this `free_buffer_page` call is coordinated and is free from race conditions with the trace reading process.
|
| 18/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:3250 LineCount:40]
Results: map[Contents:3250: if (!success) {
3251: struct buffer_page *bpage, *tmp;
3252: list_for_each_entry_safe(bpage, tmp, &cpu_buffer->new_pages,
3253: list) {
3254: list_del_init(&bpage->list);
3255: free_buffer_page(bpage);
3256: }
3257: }
3258: return success;
3259: }
3260:
3261: static void rb_update_pages(struct ring_buffer_per_cpu *cpu_buffer)
3262: {
3263: bool success;
3264:
3265: if (cpu_buffer->nr_pages_to_update > 0)
3266: success = rb_insert_pages(cpu_buffer);
3267: else
3268: success = rb_remove_pages(cpu_buffer,
3269: -cpu_buffer->nr_pages_to_update);
3270:
3271: if (success)
3272: cpu_buffer->nr_pages += cpu_buffer->nr_pages_to_update;
3273: }
3274:
3275: static void update_pages_handler(struct work_struct *work)
3276: {
3277: struct ring_buffer_per_cpu *cpu_buffer = container_of(work,
3278: struct ring_buffer_per_cpu, update_pages_work);
3279: rb_update_pages(cpu_buffer);
3280: complete(&cpu_buffer->update_done);
3281: }
3282:
3283: /**
3284: * ring_buffer_resize - resize the ring buffer
3285: * @buffer: the buffer to resize.
3286: * @size: the new size.
3287: * @cpu_id: the cpu buffer to resize
3288: *
3289: * Minimum size is 2 * rb_subbuf_capacity(buffer).
]
|
| 19/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 20700
output: 38
thoughts: 179
Thoughts: Here's my analysis of what's going on, based on the provided information, and keeping in mind the context of ring buffers and kernel tracing:
**Crash Analysis: `rb_move_tail` and `struct buffer_page`**
Okay, so I'm looking at this crash and trying to piece together the sequence. The allocation stack clearly shows that `struct buffer_page` objects, of size 64 bytes, are allocated using `kmalloc-64` within the `__rb_allocate_pages` function, and this happens when the ring buffer is resized (`ring_buffer_resize()`). I’m already thinking about potential fragmentation issues with that small allocation size, but let’s stay focused.
The free stack confirms that these same `struct buffer_page` objects are *freed* when the ring buffer is resized again, in the `rb_remove_pages` section. It seems like the usual lifecycle of these pages involves allocation, use in the ring buffer, and then deallocation when a resize occurs. Makes sense so far.
Now, the crash stack is where things get interesting. We're hitting a problem in `rb_move_tail` when we're accessing a list element within this structure. Specifically, it looks like `rb_move_tail` is trying to traverse a list by accessing `page->list.prev; list->next`, where `page` is a `struct buffer_page`. The problem is, this points to a `list_head` that’s been deallocated, which means we’re dealing with a use-after-free situation. My instinct is that this is the classic "double free" or "use-after-free" bug.
Given the context, I'd immediately focus on the interplay between the resizing logic and how the tail pointer (`rb_move_tail`) is being updated. I need to dig into that function in `kernel/trace/ring_buffer.c` around line 3964, as indicated. My initial thoughts are that we're either:
* Not correctly synchronizing access to `page->list` between readers and the resizing thread.
* Failing to properly invalidate pointers after freeing the page.
* Potentially, there’s a race condition where the freeing happens concurrently with the tail update.
I'll need to look at how `rb_move_tail` interacts with the `struct buffer_page` list and, specifically, how the `list_head` is managed during ring buffer resizing to see how we got here.
|
| 20/2 |
2026/09/26 00:34 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:3950 LineCount:40]
Results: map[Contents:3950: *
3951: * We are also fighting against interrupts coming in and
3952: * moving the head or tail on us as well.
3953: *
3954: * If the next page is the head page then we have filled
3955: * the buffer, unless the commit page is still on the
3956: * reader page.
3957: */
3958: if (rb_is_head_page(next_page, &tail_page->list)) {
3959:
3960: /*
3961: * If the commit is not on the reader page, then
3962: * move the header page.
3963: */
3964: if (!rb_is_reader_page(cpu_buffer->commit_page)) {
3965: /*
3966: * If we are not in overwrite mode,
3967: * this is easy, just stop here.
3968: */
3969: if (!(buffer->flags & RB_FL_OVERWRITE)) {
3970: local_inc(&cpu_buffer->dropped_events);
3971: goto out_reset;
3972: }
3973:
3974: ret = rb_handle_head_page(cpu_buffer,
3975: tail_page,
3976: next_page);
3977: if (ret < 0)
3978: goto out_reset;
3979: if (ret)
3980: goto out_again;
3981: } else {
3982: /*
3983: * We need to be careful here too. The
3984: * commit page could still be on the reader
3985: * page. We could have a small buffer, and
3986: * have filled up the buffer with events
3987: * from interrupts and such, and wrapped.
3988: *
3989: * Note, if the tail page is also on the
]
|
| 21/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 22028
output: 37
thoughts: 351
Thoughts: **Investigating a Potential Race Condition in the Ring Buffer**
Okay, let's break this down. My initial observation focuses on lines 3963-3964 of the kernel code, specifically this check: `if (!rb_is_reader_page(cpu_buffer->commit_page))`. I see that `rb_is_reader_page` is being inlined here, and it calls into list manipulation with `page->list.prev`. This is where things are starting to smell fishy.
`rb_is_reader_page` checks if the page is currently part of the read cycle. Then the `rb_move_tail` function calls it. This leads me to believe there's a problem involving the ring buffer's management of pages.
My primary concern now is centered around the potential for a race condition. It seems as though `ring_buffer_resize` could be removing and freeing pages via `rb_remove_pages -> free_buffer_page` from the buffer while tracing is still active. This would mean that `cpu_buffer->commit_page` could be referencing a freed page, or potentially, `page->list.prev` could be pointing to a freed/removed page. The read cycle relies on a page's `list.prev` to check if a page is on the reader's page.
The critical question then becomes: how does `ring_buffer_resize` properly synchronize with writers and the commit process? I need to understand the synchronization mechanisms in place to determine if this race condition is a real vulnerability. My next step will be to thoroughly investigate the implementation of `ring_buffer_resize` itself, looking for relevant git commits or diving into the code to understand its locking and synchronization strategies. I need to be sure that the `commit_page` is valid throughout the ring buffer operations.
|
| 22/2 |
2026/09/26 00:34 |
tool |
git-log |
0m
Args: map[Count:10 PathPrefix:kernel/trace/ring_buffer.c Since:2 years]
Results: map[Output:d860c67c0516 ring-buffer: Check resize_disabled before publishing the new subbuf order
815e07c8fe88 ring-buffer: Acquire the lock with irqsave in rb_wake_up_waiters()
7e645147dfba tracing: Fix ring_buffer_read_page_size() kernel-doc
3a2c4d55e32a treewide: refresh kmalloc_obj() conversions
d80e12156f1f ring-buffer: Use a macro for static buffer bits
c843fd3c73c9 ring-buffer: Prevent truncation of nr_pages / nr_subbufs
f2b2b645595c ring-buffer: Cap static ring buffer nr_pages
dae8dda341d2 tracing: Fix subbuf resize races with trace_pipe_raw readers
6c001a62c34f ring-buffer: Add checking nr_subbufs to persistent ring buffer validation
6365c44a824f ring-buffer: Allow splice reads on static buffers
]
|
| 23/2 |
2026/09/26 00:34 |
llm |
expert |
0m
Model:
Tokens:
input: 23083
output: 26
thoughts: 30
Thoughts: Here's a summary of my thought process, tailored for an expert like yourself:
**Investigating Potential Memory Management Issues in Ring Buffer Implementation**
Okay, so I'm thinking, let's dive into potential issues within the `ring_buffer.c` implementation. Given the context, I want to specifically hunt for clues around memory management. My initial instinct is to use the commit history as a starting point. Let's see if there's any record of work related to issue `3169`. That issue number probably has some specific context related to the current system, that might be useful. I'll also be searching for more general areas that might highlight memory leaks or buffer overflows. I'll search for the functions `rb_remove_pages` or `ring_buffer_resize`, especially when they're used in the context of the `ring_buffer.c` file, because they are key indicators of activity around resizing and removing parts of the buffer. These functions would be key areas to look for any logic errors, or incorrect memory deallocation. This approach should get me close to the source of any problems.
|
| 24/2 |
2026/09/26 00:34 |
tool |
git-log |
10m
Error:
Args: map[CodeRegexp:rb_remove_pages Count:5]
Results:
|
| 25/2 |
2026/09/26 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 23411
output: 41
thoughts: 17
Thoughts: Here's a summary of my thinking, expressed in the first person:
**Adding Path Prefix to Ring Buffer Trace Point**
Okay, so I'm looking at this code, specifically in the kernel's tracing subsystem. Right now, I need to make some additions. It's time to add a `PathPrefix` attribute. I will add the path prefix to "kernel/trace/ring_buffer.c". This will help in more efficiently debugging the ring buffer functionality. This will allow for more streamlined analysis of trace data related to it.
|
| 26/2 |
2026/09/26 00:44 |
tool |
git-log |
0m
Args: map[CodeRegexp:rb_remove_pages Count:5 PathPrefix:kernel/trace/ring_buffer.c]
Results: map[Output:9b94a8fba501 ring-buffer: Use long for nr_pages to avoid overflow failures
5040b4b7bcc2 ring-buffer: Make addition of pages in ring buffer atomic
83f40318dab0 ring-buffer: Make removal of ring buffer pages atomic
438ced1720b5 ring-buffer: Add per_cpu ring buffer control files
7a8e76a3829f tracing: unified trace buffer
]
|
| 27/2 |
2026/09/26 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 23709
output: 25
thoughts: 46
Thoughts: Here's my take on those thoughts:
**Analyzing Atomic Ring Buffer Page Removal**
Okay, so I see a commit hash here: `83f40318dab0`. Let's dive in and take a look at what this one is about. The title seems pretty straightforward: "ring-buffer: Make removal of ring buffer pages atomic". This signals a performance and/or data consistency concern within a ring buffer implementation, which is often a critical component in kernel-level tracing or logging systems. Making page removal atomic is likely addressing a race condition or a data corruption vulnerability. I'm expecting to see modifications to locking mechanisms, possibly using atomic operations on counters or flags related to page usage. We'll need to scrutinize how the buffer is being managed concurrently, focusing on the specific data structures and any locks used before and after this change. I anticipate we're looking at a solution that either reduces lock contention, ensures the removal happens in a single operation without interruption from another thread or process, or eliminates the need for any lock, or at least reduces the lock's scope. This is the place to start drilling into the code, starting from the commit itself.
|
| 28/2 |
2026/09/26 00:44 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 83f40318dab00e3298a1f6d0b12ac025e84e478d
Author: Vaibhav Nagarnaik <vnagarnaik@google.com>
Date: Thu May 3 18:59:50 2012 -0700
ring-buffer: Make removal of ring buffer pages atomic
This patch adds the capability to remove pages from a ring buffer
without destroying any existing data in it.
This is done by removing the pages after the tail page. This makes sure
that first all the empty pages in the ring buffer are removed. If the
head page is one in the list of pages to be removed, then the page after
the removed ones is made the head page. This removes the oldest data
from the ring buffer and keeps the latest data around to be read.
To do this in a non-racey manner, tracing is stopped for a very short
time while the pages to be removed are identified and unlinked from the
ring buffer. The pages are freed after the tracing is restarted to
minimize the time needed to stop tracing.
The context in which the pages from the per-cpu ring buffer are removed
runs on the respective CPU. This minimizes the events not traced to only
NMI trace contexts.
Link: http://lkml.kernel.org/r/1336096792-25373-1-git-send-email-vnagarnaik@google.com
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Laurent Chavey <chavey@google.com>
Cc: Justin Teravest <teravest@google.com>
Cc: David Sharp <dhsharp@google.com>
Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 2d5eb3320827..27ac37efb2b0 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -23,6 +23,8 @@
#include <asm/local.h>
#include "trace.h"
+static void update_pages_handler(struct work_struct *work);
+
/*
* The ring buffer header is special. We must manually up keep it.
*/
@@ -470,12 +472,15 @@ struct ring_buffer_per_cpu {
/* ring buffer pages to update, > 0 to add, < 0 to remove */
int nr_pages_to_update;
struct list_head new_pages; /* new pages to add */
+ struct work_struct update_pages_work;
+ struct completion update_completion;
};
struct ring_buffer {
unsigned flags;
int cpus;
atomic_t record_disabled;
+ atomic_t resize_disabled;
cpumask_var_t cpumask;
struct lock_class_key *reader_lock_key;
@@ -1048,6 +1053,8 @@ rb_allocate_cpu_buffer(struct ring_buffer *buffer, int nr_pages, int cpu)
raw_spin_lock_init(&cpu_buffer->reader_lock);
lockdep_set_class(&cpu_buffer->reader_lock, buffer->reader_lock_key);
cpu_buffer->lock = (arch_spinlock_t)__ARCH_SPIN_LOCK_UNLOCKED;
+ INIT_WORK(&cpu_buffer->update_pages_work, update_pages_handler);
+ init_completion(&cpu_buffer->update_completion);
bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()),
GFP_KERNEL, cpu_to_node(cpu));
@@ -1235,32 +1242,123 @@ void ring_buffer_set_clock(struct ring_buffer *buffer,
static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
+static inline unsigned long rb_page_entries(struct buffer_page *bpage)
+{
+ return local_read(&bpage->entries) & RB_WRITE_MASK;
+}
+
+static inline unsigned long rb_page_write(struct buffer_page *bpage)
+{
+ return local_read(&bpage->write) & RB_WRITE_MASK;
+}
+
static void
-rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned nr_pages)
+rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
{
- struct buffer_page *bpage;
- struct list_head *p;
- unsigned i;
+ struct list_head *tail_page, *to_remove, *next_page;
+ struct buffer_page *to_remove_page, *tmp_iter_page;
+ struct buffer_page *last_page, *first_page;
+ unsigned int nr_removed;
+ unsigned long head_bit;
+ int page_entries;
+
+ head_bit = 0;
raw_spin_lock_irq(&cpu_buffer->reader_lock);
- rb_head_page_deactivate(cpu_buffer);
+ atomic_inc(&cpu_buffer->record_disabled);
+ /*
+ * We don't race with the readers since we have acquired the reader
+ * lock. We also don't race with writers after disabling recording.
+ * This makes it easy to figure out the first and the last page to be
+ * removed from the list. We unlink all the pages in between including
+ * the first and last pages. This is done in a busy loop so that we
+ * lose the least number of traces.
+ * The pages are freed after we restart recording and unlock readers.
+ */
+ tail_page = &cpu_buffer->tail_page->list;
- for (i = 0; i < nr_pages; i++) {
- if (RB_WARN_ON(cpu_buffer, list_empty(cpu_buffer->pages)))
- goto out;
- p = cpu_buffer->pages->next;
- bpage = list_entry(p, struct buffer_page, list);
- list_del_init(&bpage->list);
- free_buffer_page(bpage);
+ /*
+ * tail page might be on reader page, we remove the next page
+ * from the ring buffer
+ */
+ if (cpu_buffer->tail_page == cpu_buffer->reader_page)
+ tail_page = rb_list_head(tail_page->next);
+ to_remove = tail_page;
+
+ /* start of pages to remove */
+ first_page = list_entry(rb_list_head(to_remove->next),
+ struct buffer_page, list);
+
+ for (nr_removed = 0; nr_removed < nr_pages; nr_removed++) {
+ to_remove = rb_list_head(to_remove)->next;
+ head_bit |= (unsigned long)to_remove & RB_PAGE_HEAD;
}
- if (RB_WARN_ON(cpu_buffer, list_empty(cpu_buffer->pages)))
- goto out;
- rb_reset_cpu(cpu_buffer);
- rb_check_pages(cpu_buffer);
+ next_page = rb_list_head(to_remove)->next;
-out:
+ /*
+ * Now we remove all pages between tail_page and next_page.
+ * Make sure that we have head_bit value preserved for the
+ * next page
+ */
+ tail_page->next = (struct list_head *)((unsigned long)next_page |
+ head_bit);
+ next_page = rb_list_head(next_page);
+ next_page->prev = tail_page;
+
+ /* make sure pages points to a valid page in the ring buffer */
+ cpu_buffer->pages = next_page;
+
+ /* update head page */
+ if (head_bit)
+ cpu_buffer->head_page = list_entry(next_page,
+ struct buffer_page, list);
+
+ /*
+ * change read pointer to make sure any read iterators reset
+ * themselves
+ */
+ cpu_buffer->read = 0;
+
+ /* pages are removed, resume tracing and then free the pages */
+ atomic_dec(&cpu_buffer->record_disabled);
raw_spin_unlock_irq(&cpu_buffer->reader_lock);
+
+ RB_WARN_ON(cpu_buffer, list_empty(cpu_buffer->pages));
+
+ /* last buffer page to remove */
+ last_page = list_entry(rb_list_head(to_remove), struct buffer_page,
+ list);
+ tmp_iter_page = first_page;
+
+ do {
+ to_remove_page = tmp_iter_page;
+ rb_inc_page(cpu_buffer, &tmp_iter_page);
+
+ /* update the counters */
+ page_entries = rb_page_entries(to_remove_page);
+ if (page_entries) {
+ /*
+ * If something was added to this page, it was full
+ * since it is not the tail page. So we deduct the
+ * bytes consumed in ring buffer from here.
+ * No need to update overruns, since this page is
+ * deleted from ring buffer and its entries are
+ * already accounted for.
+ */
+ local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
+ }
+
+ /*
+ * We have already removed references to this list item, just
+ * free up the buffer_page and its page
+ */
+ free_buffer_page(to_remove_page);
+ nr_removed--;
+
+ } while (to_remove_page != last_page);
+
+ RB_WARN_ON(cpu_buffer, nr_removed);
}
static void
@@ -1272,6 +1370,8 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer,
unsigned i;
raw_spin_lock_irq(&cpu_buffer->reader_lock);
+ /* stop the writers while inserting pages */
+ atomic_inc(&cpu_buffer->record_disabled);
rb_head_page_deactivate(cpu_buffer);
for (i = 0; i < nr_pages; i++) {
@@ -1286,19 +1386,27 @@ rb_insert_pages(struct ring_buffer_per_cpu *cpu_buffer,
rb_check_pages(cpu_buffer);
out:
+ atomic_dec(&cpu_buffer->record_disabled);
raw_spin_unlock_irq(&cpu_buffer->reader_lock);
}
-static void update_pages_handler(struct ring_buffer_per_cpu *cpu_buffer)
+static void rb_update_pages(struct ring_buffer_per_cpu *cpu_buffer)
{
if (cpu_buffer->nr_pages_to_update > 0)
rb_insert_pages(cpu_buffer, &cpu_buffer->new_pages,
cpu_buffer->nr_pages_to_update);
else
rb_remove_pages(cpu_buffer, -cpu_buffer->nr_pages_to_update);
+
cpu_buffer->nr_pages += cpu_buffer->nr_pages_to_update;
- /* reset this value */
- cpu_buffer->nr_pages_to_update = 0;
+}
+
+static void update_pages_handler(struct work_struct *work)
+{
+ struct ring_buffer_per_cpu *cpu_buffer = container_of(work,
+ struct ring_buffer_per_cpu, update_pages_work);
+ rb_update_pages(cpu_buffer);
+ complete(&cpu_buffer->update_completion);
}
/**
@@ -1308,14 +1416,14 @@ static void update_pages_handler(struct ring_buffer_per_cpu *cpu_buffer)
*
* Minimum size is 2 * BUF_PAGE_SIZE.
*
- * Returns -1 on failure.
+ * Returns 0 on success and < 0 on failure.
*/
int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
int cpu_id)
{
struct ring_buffer_per_cpu *cpu_buffer;
unsigned nr_pages;
- int cpu;
+ int cpu, err = 0;
/*
* Always succeed at resizing a non-existent buffer:
@@ -1330,15 +1438,18 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
if (size < BUF_PAGE_SIZE * 2)
size = BUF_PAGE_SIZE * 2;
- atomic_inc(&buffer->record_disabled);
+ nr_pages = DIV_ROUND_UP(size, BUF_PAGE_SIZE);
- /* Make sure all writers are done with this buffer. */
- synchronize_sched();
+ /*
+ * Don't succeed if resizing is disabled, as a reader might be
+ * manipulating the ring buffer and is expecting a sane state while
+ * this is true.
+ */
+ if (atomic_read(&buffer->resize_disabled))
+ return -EBUSY;
+ /* prevent another thread from changing buffer sizes */
mutex_lock(&buffer->mutex);
- get_online_cpus();
-
- nr_pages = DIV_ROUND_UP(size, BUF_PAGE_SIZE);
if (cpu_id == RING_BUFFER_ALL_CPUS) {
/* calculate the pages to update */
@@ -1347,33 +1458,67 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
cpu_buffer->nr_pages_to_update = nr_pages -
cpu_buffer->nr_pages;
-
/*
* nothing more to do for removing pages or no update
*/
if (cpu_buffer->nr_pages_to_update <= 0)
continue;
-
/*
* to add pages, make sure all new pages can be
* allocated without receiving ENOMEM
*/
INIT_LIST_HEAD(&cpu_buffer->new_pages);
if (__rb_allocate_pages(cpu_buffer->nr_pages_to_update,
- &cpu_buffer->new_pages, cpu))
+ &cpu_buffer->new_pages, cpu)) {
/* not enough memory for new pages */
- goto no_mem;
+ err = -ENOMEM;
+ goto out_err;
+ }
+ }
+
+ get_online_cpus();
+ /*
+ * Fire off all the required work handlers
+ * Look out for offline CPUs
+ */
+ for_each_buffer_cpu(buffer, cpu) {
+ cpu_buffer = buffer->buffers[cpu];
+ if (!cpu_buffer->nr_pages_to_update ||
+ !cpu_online(cpu))
+ continue;
+
+ schedule_work_on(cpu, &cpu_buffer->update_pages_work);
+ }
+ /*
+ * This loop is for the CPUs that are not online.
+ * We can't schedule anything on them, but it's not necessary
+ * since we can change their buffer sizes without any race.
+ */
+ for_each_buffer_cpu(buffer, cpu) {
+ cpu_buffer = buffer->buffers[cpu];
+ if (!cpu_buffer->nr_pages_to_update ||
+ cpu_online(cpu))
+ continue;
+
+ rb_update_pages(cpu_buffer);
}
/* wait for all the updates to complete */
for_each_buffer_cpu(buffer, cpu) {
cpu_buffer = buffer->buffers[cpu];
- if (cpu_buffer->nr_pages_to_update) {
- update_pages_handler(cpu_buffer);
- }
+ if (!cpu_buffer->nr_pages_to_update ||
+ !cpu_online(cpu))
+ continue;
+
+ wait_for_completion(&cpu_buffer->update_completion);
+ /* reset this value */
+ cpu_buffer->nr_pages_to_update = 0;
}
+
+ put_online_cpus();
} else {
cpu_buffer = buffer->buffers[cpu_id];
+
if (nr_pages == cpu_buffer->nr_pages)
goto out;
@@ -1383,38 +1528,47 @@ int ring_buffer_resize(struct ring_buffer *buffer, unsigned long size,
INIT_LIST_HEAD(&cpu_buffer->new_pages);
if (cpu_buffer->nr_pages_to_update > 0 &&
__rb_allocate_pages(cpu_buffer->nr_pages_to_update,
- &cpu_buffer->new_pages, cpu_id))
- goto no_mem;
+ &cpu_buffer->new_pages, cpu_id)) {
+ err = -ENOMEM;
+ goto out_err;
+ }
- update_pages_handler(cpu_buffer);
+ get_online_cpus();
+
+ if (cpu_online(cpu_id)) {
+ schedule_work_on(cpu_id,
+ &cpu_buffer->update_pages_work);
+ wait_for_completion(&cpu_buffer->update_completion);
+ } else
+ rb_update_pages(cpu_buffer);
+
+ put_online_cpus();
+ /* reset this value */
+ cpu_buffer->nr_pages_to_update = 0;
}
out:
- put_online_cpus();
mutex_unlock(&buffer->mutex);
-
- atomic_dec(&buffer->record_disabled);
-
return size;
- no_mem:
+ out_err:
for_each_buffer_cpu(buffer, cpu) {
struct buffer_page *bpage, *tmp;
+
cpu_buffer = buffer->buffers[cpu];
- /* reset this number regardless */
cpu_buffer->nr_pages_to_update = 0;
+
if (list_empty(&cpu_buffer->new_pages))
continue;
+
list_for_each_entry_safe(bpage, tmp, &cpu_buffer->new_pages,
list) {
list_del_init(&bpage->list);
free_buffer_page(bpage);
}
}
- put_online_cpus();
mutex_unlock(&buffer->mutex);
- atomic_dec(&buffer->record_disabled);
- return -ENOMEM;
+ return err;
}
EXPORT_SYMBOL_GPL(ring_buffer_resize);
@@ -1453,21 +1607,11 @@ rb_iter_head_event(struct ring_buffer_iter *iter)
return __rb_page_index(iter->head_page, iter->head);
}
-static inline unsigned long rb_page_write(struct buffer_page *bpage)
-{
- return local_read(&bpage->write) & RB_WRITE_MASK;
-}
-
static inline unsigned rb_page_commit(struct buffer_page *bpage)
{
return local_read(&bpage->page->commit);
}
-static inline unsigned long rb_page_entries(struct buffer_page *bpage)
-{
- return local_read(&bpage->entries) & RB_WRITE_MASK;
-}
-
/* Size is determined by what has been committed */
static inline unsigned rb_page_size(struct buffer_page *bpage)
{
@@ -3492,6 +3636,7 @@ ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu)
iter->cpu_buffer = cpu_buffer;
+ atomic_inc(&buffer->resize_disabled);
atomic_inc(&cpu_buffer->record_disabled);
return iter;
@@ -3555,6 +3700,7 @@ ring_buffer_read_finish(struct ring_buffer_iter *iter)
struct ring_buffer_per_cpu *cpu_buffer = iter->cpu_buffer;
atomic_dec(&cpu_buffer->record_disabled);
+ atomic_dec(&cpu_buffer->buffer->resize_disabled);
kfree(iter);
}
EXPORT_SYMBOL_GPL(ring_buffer_read_finish);
@@ -3662,8 +3808,12 @@ void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu)
if (!cpumask_test_cpu(cpu, buffer->cpumask))
return;
+ atomic_inc(&buffer->resize_disabled);
atomic_inc(&cpu_buffer->record_disabled);
+ /* Make sure all commits have finished */
+ synchronize_sched();
+
raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
if (RB_WARN_ON(cpu_buffer, local_read(&cpu_buffer->committing)))
@@ -3679,6 +3829,7 @@ void ring_buffer_reset_cpu(struct ring_buffer *buffer, int cpu)
raw_spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
atomic_dec(&cpu_buffer->record_disabled);
+ atomic_dec(&buffer->resize_disabled);
}
EXPORT_SYMBOL_GPL(ring_buffer_reset_cpu);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index d1b3469b62e3..dfbd86cc4876 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3076,20 +3076,10 @@ static int __tracing_resize_ring_buffer(unsigned long size, int cpu)
static ssize_t tracing_resize_ring_buffer(unsigned long size, int cpu_id)
{
- int cpu, ret = size;
+ int ret = size;
mutex_lock(&trace_types_lock);
- tracing_stop();
-
- /* disable all cpu buffers */
- for_each_tracing_cpu(cpu) {
- if (global_trace.data[cpu])
- atomic_inc(&global_trace.data[cpu]->disabled);
- if (max_tr.data[cpu])
- atomic_inc(&max_tr.data[cpu]->disabled);
- }
-
if (cpu_id != RING_BUFFER_ALL_CPUS) {
/* make sure, this cpu is enabled in the mask */
if (!cpumask_test_cpu(cpu_id, tracing_buffer_mask)) {
@@ -3103,14 +3093,6 @@ static ssize_t tracing_resize_ring_buffer(unsigned long size, int cpu_id)
ret = -ENOMEM;
out:
- for_each_tracing_cpu(cpu) {
- if (global_trace.data[cpu])
- atomic_dec(&global_trace.data[cpu]->disabled);
- if (max_tr.data[cpu])
- atomic_dec(&max_tr.data[cpu]->disabled);
- }
-
- tracing_start();
mutex_unlock(&trace_types_lock);
return ret;
]
|
| 29/2 |
2026/09/26 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 30183
output: 38
thoughts: 41
Thoughts: Here's my summary, as if I were thinking it:
**Analyzing `rb_remove_pages` in the Ring Buffer**
Alright, let's dive into this. I need to understand how `rb_remove_pages` functions within the ring buffer, so first thing's first, I should pull up the code for that function. Specifically, I'll go directly to `kernel/trace/ring_buffer.c` and take a good look at `rb_remove_pages`. Let's see how it's implemented. Got to understand how it's removing pages.
|
| 30/2 |
2026/09/26 00:44 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:3080 LineCount:90]
Results: map[Contents:3080:
3081: raw_spin_lock_irq(&cpu_buffer->reader_lock);
3082: atomic_inc(&cpu_buffer->record_disabled);
3083: /*
3084: * We don't race with the readers since we have acquired the reader
3085: * lock. We also don't race with writers after disabling recording.
3086: * This makes it easy to figure out the first and the last page to be
3087: * removed from the list. We unlink all the pages in between including
3088: * the first and last pages. This is done in a busy loop so that we
3089: * lose the least number of traces.
3090: * The pages are freed after we restart recording and unlock readers.
3091: */
3092: tail_page = &cpu_buffer->tail_page->list;
3093:
3094: /*
3095: * tail page might be on reader page, we remove the next page
3096: * from the ring buffer
3097: */
3098: if (cpu_buffer->tail_page == cpu_buffer->reader_page)
3099: tail_page = rb_list_head(tail_page->next);
3100: to_remove = tail_page;
3101:
3102: /* start of pages to remove */
3103: first_page = list_entry(rb_list_head(to_remove->next),
3104: struct buffer_page, list);
3105:
3106: for (nr_removed = 0; nr_removed < nr_pages; nr_removed++) {
3107: to_remove = rb_list_head(to_remove)->next;
3108: head_bit |= (unsigned long)to_remove & RB_PAGE_HEAD;
3109: }
3110: /* Read iterators need to reset themselves when some pages removed */
3111: cpu_buffer->pages_removed += nr_removed;
3112:
3113: next_page = rb_list_head(to_remove)->next;
3114:
3115: /*
3116: * Now we remove all pages between tail_page and next_page.
3117: * Make sure that we have head_bit value preserved for the
3118: * next page
3119: */
3120: tail_page->next = (struct list_head *)((unsigned long)next_page |
3121: head_bit);
3122: next_page = rb_list_head(next_page);
3123: next_page->prev = tail_page;
3124:
3125: /* make sure pages points to a valid page in the ring buffer */
3126: cpu_buffer->pages = next_page;
3127: cpu_buffer->cnt++;
3128:
3129: /* update head page */
3130: if (head_bit)
3131: cpu_buffer->head_page = list_entry(next_page,
3132: struct buffer_page, list);
3133:
3134: /* pages are removed, resume tracing and then free the pages */
3135: atomic_dec(&cpu_buffer->record_disabled);
3136: raw_spin_unlock_irq(&cpu_buffer->reader_lock);
3137:
3138: RB_WARN_ON(cpu_buffer, list_empty(cpu_buffer->pages));
3139:
3140: /* last buffer page to remove */
3141: last_page = list_entry(rb_list_head(to_remove), struct buffer_page,
3142: list);
3143: tmp_iter_page = first_page;
3144:
3145: do {
3146: cond_resched();
3147:
3148: to_remove_page = tmp_iter_page;
3149: rb_inc_page(&tmp_iter_page);
3150:
3151: /* update the counters */
3152: page_entries = rb_page_entries(to_remove_page);
3153: if (page_entries) {
3154: /*
3155: * If something was added to this page, it was full
3156: * since it is not the tail page. So we deduct the
3157: * bytes consumed in ring buffer from here.
3158: * Increment overrun to account for the lost events.
3159: */
3160: local_add(page_entries, &cpu_buffer->overrun);
3161: local_sub(rb_page_commit(to_remove_page), &cpu_buffer->entries_bytes);
3162: local_inc(&cpu_buffer->pages_lost);
3163: }
3164:
3165: /*
3166: * We have already removed references to this list item, just
3167: * free up the buffer_page and its page
3168: */
3169: free_buffer_page(to_remove_page);
]
|
| 31/2 |
2026/09/26 00:44 |
llm |
expert |
0m
Model:
Tokens:
input: 31814
output: 32
thoughts: 209
Thoughts: **Analyzing Ring Buffer Page Removal**
Okay, so I'm diving into this `rb_remove_pages` function, and I'm immediately zeroing in on this section. Let's see, we have `tail_page`, which I understand is a critical pointer to the end of the buffer. The comment points out a nuance, the `tail_page` might be on the reader page, so we use `rb_list_head` to find the proper next page. Then we set `to_remove`. And then we set `first_page`. I get the general flow, we're finding the pages we want to remove from the ring buffer.
But wait a second... `commit_page`... I need to understand that. What exactly *is* `cpu_buffer->commit_page`? I understand the read, but now the commit is what I need to focus on. Where does it fit into the picture? Where is this `commit_page` field being updated? Is it related to the data pages, the metadata or something else? I need to track this down. Okay, let's fire up the search and go directly to `kernel/trace/ring_buffer.c`. I need to see how `commit_page` is manipulated within the context of the ring buffer operations. Let's see what we can find.
|
| 32/2 |
2026/09/26 00:45 |
tool |
grepper |
0m
Args: map[Expression:commit_page PathPrefix:kernel/trace/ring_buffer.c]
Results: map[Output:kernel/trace/ring_buffer.c=521=struct ring_buffer_per_cpu {
--
kernel/trace/ring_buffer.c-536- struct buffer_page *tail_page; /* write to tail */
kernel/trace/ring_buffer.c:537: struct buffer_page *commit_page; /* committed pages */
kernel/trace/ring_buffer.c-538- struct buffer_page *reader_page;
--
kernel/trace/ring_buffer.c=735=static void verify_event(struct ring_buffer_per_cpu *cpu_buffer,
--
kernel/trace/ring_buffer.c-737-{
kernel/trace/ring_buffer.c:738: struct buffer_page *page = cpu_buffer->commit_page;
kernel/trace/ring_buffer.c-739- struct buffer_page *tail_page = READ_ONCE(cpu_buffer->tail_page);
--
kernel/trace/ring_buffer.c=959=static bool rb_watermark_hit(struct trace_buffer *buffer, int cpu, int full)
--
kernel/trace/ring_buffer.c-977- raw_spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
kernel/trace/ring_buffer.c:978: pagebusy = cpu_buffer->reader_page == cpu_buffer->commit_page;
kernel/trace/ring_buffer.c-979- ret = !pagebusy && full_hit(buffer, cpu, full);
--
kernel/trace/ring_buffer.c=2111=static void rb_meta_validate_events(struct ring_buffer_per_cpu *cpu_buffer)
--
kernel/trace/ring_buffer.c-2187- if (meta->commit_buffer == (unsigned long)cpu_buffer->reader_page->page) {
kernel/trace/ring_buffer.c:2188: cpu_buffer->commit_page = cpu_buffer->reader_page;
kernel/trace/ring_buffer.c-2189- /* Nothing more to do, the only page is the reader page */
--
kernel/trace/ring_buffer.c-2202-
kernel/trace/ring_buffer.c:2203: if (head_page == cpu_buffer->commit_page)
kernel/trace/ring_buffer.c-2204- break;
--
kernel/trace/ring_buffer.c-2206-
kernel/trace/ring_buffer.c:2207: if (head_page != cpu_buffer->commit_page) {
kernel/trace/ring_buffer.c-2208- pr_info("Ring buffer meta [%d] commit page not found\n",
--
kernel/trace/ring_buffer.c=2394=static void rb_meta_buffer_update(struct ring_buffer_per_cpu *cpu_buffer,
--
kernel/trace/ring_buffer.c-2402- if (meta->commit_buffer == (unsigned long)bpage->page) {
kernel/trace/ring_buffer.c:2403: cpu_buffer->commit_page = bpage;
kernel/trace/ring_buffer.c-2404- cpu_buffer->tail_page = bpage;
--
kernel/trace/ring_buffer.c=2568=rb_allocate_cpu_buffer(struct trace_buffer *buffer, unsigned long nr_pages, int cpu)
--
kernel/trace/ring_buffer.c-2655- if (!meta || !meta->head_buffer ||
kernel/trace/ring_buffer.c:2656: !cpu_buffer->head_page || !cpu_buffer->commit_page || !cpu_buffer->tail_page) {
kernel/trace/ring_buffer.c-2657- if (meta && meta->head_buffer &&
kernel/trace/ring_buffer.c:2658: (cpu_buffer->head_page || cpu_buffer->commit_page || cpu_buffer->tail_page)) {
kernel/trace/ring_buffer.c-2659- pr_warn("Ring buffer meta buffers not all mapped\n");
--
kernel/trace/ring_buffer.c-2661- pr_warn(" Missing head_page\n");
kernel/trace/ring_buffer.c:2662: if (!cpu_buffer->commit_page)
kernel/trace/ring_buffer.c:2663: pr_warn(" Missing commit_page\n");
kernel/trace/ring_buffer.c-2664- if (!cpu_buffer->tail_page)
--
kernel/trace/ring_buffer.c-2669- = list_entry(cpu_buffer->pages, struct buffer_page, list);
kernel/trace/ring_buffer.c:2670: cpu_buffer->tail_page = cpu_buffer->commit_page = cpu_buffer->head_page;
kernel/trace/ring_buffer.c-2671-
--
kernel/trace/ring_buffer.c=3589=rb_commit_index(struct ring_buffer_per_cpu *cpu_buffer)
kernel/trace/ring_buffer.c-3590-{
kernel/trace/ring_buffer.c:3591: return rb_page_commit(cpu_buffer->commit_page);
kernel/trace/ring_buffer.c-3592-}
--
kernel/trace/ring_buffer.c=3921=rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
--
kernel/trace/ring_buffer.c-3924- struct buffer_page *tail_page = info->tail_page;
kernel/trace/ring_buffer.c:3925: struct buffer_page *commit_page = cpu_buffer->commit_page;
kernel/trace/ring_buffer.c-3926- struct trace_buffer *buffer = cpu_buffer->buffer;
--
kernel/trace/ring_buffer.c-3938- */
kernel/trace/ring_buffer.c:3939: if (unlikely(next_page == commit_page)) {
kernel/trace/ring_buffer.c-3940- local_inc(&cpu_buffer->commit_overrun);
--
kernel/trace/ring_buffer.c-3963- */
kernel/trace/ring_buffer.c:3964: if (!rb_is_reader_page(cpu_buffer->commit_page)) {
kernel/trace/ring_buffer.c-3965- /*
--
kernel/trace/ring_buffer.c-3991- */
kernel/trace/ring_buffer.c:3992: if (unlikely((cpu_buffer->commit_page !=
kernel/trace/ring_buffer.c-3993- cpu_buffer->tail_page) &&
kernel/trace/ring_buffer.c:3994: (cpu_buffer->commit_page ==
kernel/trace/ring_buffer.c-3995- cpu_buffer->reader_page))) {
--
kernel/trace/ring_buffer.c=4249=rb_set_commit_to_write(struct ring_buffer_per_cpu *cpu_buffer)
--
kernel/trace/ring_buffer.c-4263-
kernel/trace/ring_buffer.c:4264: while (cpu_buffer->commit_page != READ_ONCE(cpu_buffer->tail_page)) {
kernel/trace/ring_buffer.c-4265- if (RB_WARN_ON(cpu_buffer, !(--max_count)))
--
kernel/trace/ring_buffer.c-4273- */
kernel/trace/ring_buffer.c:4274: local_set(&cpu_buffer->commit_page->page->commit,
kernel/trace/ring_buffer.c:4275: rb_page_write(cpu_buffer->commit_page));
kernel/trace/ring_buffer.c:4276: rb_inc_page(&cpu_buffer->commit_page);
kernel/trace/ring_buffer.c-4277- if (cpu_buffer->ring_meta) {
kernel/trace/ring_buffer.c-4278- struct ring_buffer_cpu_meta *meta = cpu_buffer->ring_meta;
kernel/trace/ring_buffer.c:4279: meta->commit_buffer = (unsigned long)cpu_buffer->commit_page->page;
kernel/trace/ring_buffer.c-4280- }
--
kernel/trace/ring_buffer.c-4284- while (rb_commit_index(cpu_buffer) !=
kernel/trace/ring_buffer.c:4285: rb_page_write(cpu_buffer->commit_page)) {
kernel/trace/ring_buffer.c-4286-
--
kernel/trace/ring_buffer.c-4288- smp_wmb();
kernel/trace/ring_buffer.c:4289: local_set(&cpu_buffer->commit_page->page->commit,
kernel/trace/ring_buffer.c:4290: rb_page_write(cpu_buffer->commit_page));
kernel/trace/ring_buffer.c-4291- RB_WARN_ON(cpu_buffer,
kernel/trace/ring_buffer.c:4292: rb_page_commit(cpu_buffer->commit_page) & ~RB_WRITE_MASK);
kernel/trace/ring_buffer.c-4293- barrier();
--
kernel/trace/ring_buffer.c-4303- */
kernel/trace/ring_buffer.c:4304: if (unlikely(cpu_buffer->commit_page != READ_ONCE(cpu_buffer->tail_page)))
kernel/trace/ring_buffer.c-4305- goto again;
--
kernel/trace/ring_buffer.c=4377=rb_wakeups(struct trace_buffer *buffer, struct ring_buffer_per_cpu *cpu_buffer)
--
kernel/trace/ring_buffer.c-4393-
kernel/trace/ring_buffer.c:4394: if (cpu_buffer->reader_page == cpu_buffer->commit_page)
kernel/trace/ring_buffer.c-4395- return;
--
kernel/trace/ring_buffer.c=5090=rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
--
kernel/trace/ring_buffer.c-5093- unsigned long addr = (unsigned long)event;
kernel/trace/ring_buffer.c:5094: struct buffer_page *bpage = cpu_buffer->commit_page;
kernel/trace/ring_buffer.c-5095- struct buffer_page *start;
--
kernel/trace/ring_buffer.c=5626=static void rb_update_remote_head(struct ring_buffer_per_cpu *cpu_buffer)
--
kernel/trace/ring_buffer.c-5647-
kernel/trace/ring_buffer.c:5648: orig = cpu_buffer->commit_page = cpu_buffer->head_page;
kernel/trace/ring_buffer.c-5649- retry = 3;
kernel/trace/ring_buffer.c-5650-
kernel/trace/ring_buffer.c:5651: while (cpu_buffer->commit_page->page->time_stamp < next->page->time_stamp) {
kernel/trace/ring_buffer.c-5652- rb_inc_page(&next);
kernel/trace/ring_buffer.c:5653: rb_inc_page(&cpu_buffer->commit_page);
kernel/trace/ring_buffer.c-5654-
kernel/trace/ring_buffer.c:5655: if (cpu_buffer->commit_page == orig) {
kernel/trace/ring_buffer.c-5656- if (WARN_ON_ONCE(!(--retry)))
--
kernel/trace/ring_buffer.c=5717=int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
--
kernel/trace/ring_buffer.c-5721- struct buffer_page *head_page;
kernel/trace/ring_buffer.c:5722: struct buffer_page *commit_page;
kernel/trace/ring_buffer.c:5723: struct buffer_page *curr_commit_page;
kernel/trace/ring_buffer.c-5724- unsigned commit;
--
kernel/trace/ring_buffer.c-5730- head_page = cpu_buffer->head_page;
kernel/trace/ring_buffer.c:5731: commit_page = READ_ONCE(cpu_buffer->commit_page);
kernel/trace/ring_buffer.c:5732: commit_ts = commit_page->page->time_stamp;
kernel/trace/ring_buffer.c-5733-
--
kernel/trace/ring_buffer.c-5739- smp_rmb();
kernel/trace/ring_buffer.c:5740: commit = rb_page_size(commit_page);
kernel/trace/ring_buffer.c-5741- /* We want to make sure that the commit page doesn't change */
--
kernel/trace/ring_buffer.c-5744- /* Make sure commit page didn't change */
kernel/trace/ring_buffer.c:5745: curr_commit_page = READ_ONCE(cpu_buffer->commit_page);
kernel/trace/ring_buffer.c:5746: curr_commit_ts = READ_ONCE(curr_commit_page->page->time_stamp);
kernel/trace/ring_buffer.c-5747-
kernel/trace/ring_buffer.c-5748- /* If the commit page changed, then there's more data */
kernel/trace/ring_buffer.c:5749: if (curr_commit_page != commit_page ||
kernel/trace/ring_buffer.c-5750- curr_commit_ts != commit_ts)
--
kernel/trace/ring_buffer.c-5753- /* Still racy, as it may return a false positive, but that's OK */
kernel/trace/ring_buffer.c:5754: return ((iter->head_page == commit_page && iter->head >= commit) ||
kernel/trace/ring_buffer.c:5755: (iter->head_page == reader && commit_page == head_page &&
kernel/trace/ring_buffer.c-5756- head_page->read == commit &&
--
kernel/trace/ring_buffer.c=5884=__rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
--
kernel/trace/ring_buffer.c-5924- reader = NULL;
kernel/trace/ring_buffer.c:5925: if (cpu_buffer->commit_page == cpu_buffer->reader_page)
kernel/trace/ring_buffer.c-5926- goto out;
--
kernel/trace/ring_buffer.c=6095=static void rb_advance_iter(struct ring_buffer_iter *iter)
--
kernel/trace/ring_buffer.c-6114- /* discarded commits can make the page empty */
kernel/trace/ring_buffer.c:6115: if (iter->head_page == cpu_buffer->commit_page)
kernel/trace/ring_buffer.c-6116- return;
--
kernel/trace/ring_buffer.c=6643=rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
--
kernel/trace/ring_buffer.c-6673- cpu_buffer->tail_page = cpu_buffer->head_page;
kernel/trace/ring_buffer.c:6674: cpu_buffer->commit_page = cpu_buffer->head_page;
kernel/trace/ring_buffer.c-6675-
--
kernel/trace/ring_buffer.c=7190=int ring_buffer_read_page(struct trace_buffer *buffer,
--
kernel/trace/ring_buffer.c-7248- if (read || (len < (size - read)) ||
kernel/trace/ring_buffer.c:7249: cpu_buffer->reader_page == cpu_buffer->commit_page ||
kernel/trace/ring_buffer.c-7250- rb_is_static(cpu_buffer) ||
--
kernel/trace/ring_buffer.c-7258- /* If a full page is requested, it cannot be the commit page */
kernel/trace/ring_buffer.c:7259: if (full && cpu_buffer->reader_page == cpu_buffer->commit_page)
kernel/trace/ring_buffer.c-7260- return -1;
--
kernel/trace/ring_buffer.c=7445=int ring_buffer_subbuf_order_set(struct trace_buffer *buffer, int order)
--
kernel/trace/ring_buffer.c-7563- = list_entry(cpu_buffer->pages, struct buffer_page, list);
kernel/trace/ring_buffer.c:7564: cpu_buffer->tail_page = cpu_buffer->commit_page = cpu_buffer->head_page;
kernel/trace/ring_buffer.c-7565-
--
kernel/trace/ring_buffer.c=7969=int ring_buffer_map_get_reader(struct trace_buffer *buffer, int cpu)
--
kernel/trace/ring_buffer.c-8000- /* Did the reader catch up with the writer? */
kernel/trace/ring_buffer.c:8001: if (cpu_buffer->reader_page == cpu_buffer->commit_page)
kernel/trace/ring_buffer.c-8002- goto out;
--
kernel/trace/ring_buffer.c-8011- if (missed_events) {
kernel/trace/ring_buffer.c:8012: if (cpu_buffer->reader_page != cpu_buffer->commit_page) {
kernel/trace/ring_buffer.c-8013- struct buffer_data_page *dpage = reader->page;
--
kernel/trace/ring_buffer.c-8038- * is on the reader page. But if the tail page is not on the
kernel/trace/ring_buffer.c:8039: * reader page and the commit_page is, that would mean that
kernel/trace/ring_buffer.c-8040- * there's a commit_overrun (an interrupt preempted an
]
|
| 33/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 37074
output: 38
thoughts: 2143
Thoughts: **Analyzing a Ring Buffer Race Condition in Kernel Tracing**
Okay, let's break this down. I'm looking at the `rb_remove_pages()` function, and my first thought is, "Wait, what happens with `cpu_buffer->commit_page`?". This is a crucial area for race conditions in ring buffers, especially within the tracing subsystem. The code never explicitly checks or updates `commit_page` during page removal, which is a red flag. `commit_page` tracks what's considered "committed" – the events that are ready for reading. It seems likely that if `commit_page` is not being synchronized with page removal, we can have a problem where committed pages are removed.
Now, let's dig deeper: when `rb_remove_pages` removes pages, it operates from the `tail_page` (where writing happens) up to a specified number of pages (`nr_pages`). `commit_page` can *lag* behind `tail_page` during nested events or interrupts. So if these pages between `tail_page` and `next_page` are removed, and `commit_page` is within that removed range, boom. This is a circular doubly-linked list, so we're talking about pages immediately *following* the `tail_page`.
I'm starting to see a scenario: the interrupt occurred during a tracing event write, in the middle of a `__rb_reserve_next` call. The timer interrupt can then trigger a resize operation via `ring_buffer_resize` (called by task 10552!), and that calls `rb_remove_pages` to trim the buffer. Crucially, the pages are freed *after* the `record_disabled` flag is decremented, and the reader lock is released.
The trace suggests exactly that: while task 10552 resizes, an interrupt occurs: the interrupt calls `__rb_reserve_next` from `hrtimer_interrupt` while the other task is in `__rb_reserve_next`! This interrupt is accessing a *freed* buffer page and crashes in `rb_is_reader_page` in the `<IRQ>` context.
It's clear that the resize operation (which involves `rb_remove_pages` and ultimately `free_buffer_page`) isn't properly synchronized with writers that may be in-flight. The critical part is that pages are freed *after* recording is re-enabled, meaning a writer can get into a race condition to try to commit to the page just freed.
|
| 34/2 |
2026/09/26 00:45 |
tool |
read-file |
0m
Args: map[File:kernel/trace/ring_buffer.c FirstLine:4840 LineCount:40]
Results: map[Contents:4840: }
4841:
4842: /*B*/ rb_time_set(&cpu_buffer->before_stamp, info->ts);
4843:
4844: /*C*/ write = local_add_return(info->length, &tail_page->write);
4845:
4846: /* set write to only the index of the write */
4847: write &= RB_WRITE_MASK;
4848:
4849: tail = write - info->length;
4850:
4851: /* See if we shot pass the end of this buffer page */
4852: if (unlikely(write > rb_page_capacity(tail_page))) {
4853: check_buffer(cpu_buffer, info, CHECK_FULL_PAGE);
4854: return rb_move_tail(cpu_buffer, tail, info);
4855: }
4856:
4857: if (likely(tail == w)) {
4858: /* Nothing interrupted us between A and C */
4859: /*D*/ rb_time_set(&cpu_buffer->write_stamp, info->ts);
4860: /*
4861: * If something came in between C and D, the write stamp
4862: * may now not be in sync. But that's fine as the before_stamp
4863: * will be different and then next event will just be forced
4864: * to use an absolute timestamp.
4865: */
4866: if (likely(!(info->add_timestamp &
4867: (RB_ADD_STAMP_FORCE | RB_ADD_STAMP_ABSOLUTE))))
4868: /* This did not interrupt any time update */
4869: info->delta = info->ts - info->after;
4870: else
4871: /* Just use full timestamp for interrupting event */
4872: info->delta = info->ts;
4873: check_buffer(cpu_buffer, info, tail);
4874: } else {
4875: u64 ts;
4876: /* SLOW PATH - Interrupted between A and C */
4877:
4878: /* Save the old before_stamp */
4879: rb_time_read(&cpu_buffer->before_stamp, &info->before);
]
|
| 35/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 40456
output: 44
thoughts: 4742
Thoughts: **Analyzing a Ring Buffer Use-After-Free in the Trace Subsystem**
Alright, let's break this down. It seems a use-after-free has occurred within the kernel's trace ring buffer, triggered by a race condition during a resize operation. The KASAN report and the stack traces are all consistent with this. I'm seeing that the problem lies in `rb_move_tail` and, specifically, in how it calls `rb_is_reader_page`.
Looking at the code, the task context was interrupted at line 4859 `rb_time_set(&cpu_buffer->write_stamp, info->ts);` (between C and D, or right at D), inside `__rb_reserve_next.constprop.0`. The IRQ context, however, then runs `rb_move_tail`, which calls `rb_is_reader_page`. This function, in turn, attempts to access a freed `buffer_page`. The crash address reveals the exact offset within the freed memory region, and it all points to the `list.next` member, precisely what `rb_is_reader_page` is reading.
The crux of the problem seems to be that while the task context was writing or preempted, `ring_buffer_resize` removed pages, specifically using `rb_remove_pages`. Crucially, `rb_remove_pages` does *not* synchronize with or wait for writers or check the `cpu_buffer->committing` flag, allowing it to free pages that `rb_move_tail` might still be referencing, thus creating the use-after-free.
The traces confirm that this is a valid report. The first is a memory access stack `rb_is_reader_page` accessing a list pointer of a freed `buffer_page`. Second, the allocation stack shows that the `buffer_page` was allocated via `__rb_allocate_pages`. Third, the `free_buffer_page` called from `rb_remove_pages`, then freeing it. All three point to the same object type (64-byte `struct buffer_page` inside `kmalloc-64`) and subsystem. The object is in a freed state, as confirmed by the shadow memory 0xfa/0xfb KASAN markers.
Furthermore, there is a nested interrupt. The initial task context (before the interrupt) was reserving space in the buffer. Then an APIC timer interrupt arrived. Inside the interrupt handler, softirq processing (specifically net_tx_action) ran, which involved network queueing operations and eventually triggered another interrupt, which ultimately led to the use-after-free, highlighting the race's timing-sensitive nature.
Now, my next step is to examine recent commits related to `ring_buffer_resize`, `rb_remove_pages`, and `rb_is_reader_page` to find a similar fix or to understand how this race was introduced.
|
| 36/2 |
2026/09/26 00:45 |
tool |
git-log |
0m
Args: map[CodeRegexp:rb_is_reader_page Count:10 PathPrefix:kernel/trace/ring_buffer.c]
Results: map[Output:06ca320952dc ring-buffer: rb_is_reader_page() can return boolean
d90fd77402d3 ring-buffer: Reorganize function locations
77ae365eca89 ring-buffer: make lockless
]
|
| 37/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 45947
output: 38
thoughts: 42
Thoughts: Okay, here's my take on those thoughts, framed as an expert's internal monologue:
**Investigating Potential `ring_buffer.c` Memory Corruption**
Alright, time to get to the bottom of this. I need to dive into the recent history of `ring_buffer.c`. My gut tells me we're dealing with a nasty potential use-after-free issue, or maybe a subtle resize problem that's leading to some corrupted memory. I'm going to kick off a search for commit messages. I need to be precise, though. "Use-after-free" itself is a good start, along with the acronym "UAF" that's often used. Let's not limit it to just those terms, though. Any mention of "resize" in the context of this specific file would also be worth a look. And, of course, any recent modifications around `rb_remove_pages` is a must. That function always gives me a little shiver - it's a common area for memory management headaches. Hopefully, the commit messages are descriptive enough to give me a good head start. Let's see what the audit reveals.
|
| 38/2 |
2026/09/26 00:45 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[resize] PathPrefix:kernel/trace/ring_buffer.c]
Results: map[Output:d860c67c0516 ring-buffer: Check resize_disabled before publishing the new subbuf order
7e645147dfba tracing: Fix ring_buffer_read_page_size() kernel-doc
dae8dda341d2 tracing: Fix subbuf resize races with trace_pipe_raw readers
8b502bf6eb3d ring-buffer: Remove ring_buffer_per_cpu::mapped
e743527c5bfd ring-buffer: Fix subbuf resize race with ring_buffer_alloc_read_page()
8a5f63637890 ring-buffer: Fix subbuf resize race with ring buffer readers
7a1fb95de540 ring-buffer: Make cpu_buffer::free_page a buffer_data_read_page
bf98d7b0d5a9 ring-buffer: Prevent subbuf order change when resizing is disabled
6435ffd6c7fc ring-buffer: Avoid softlockup in ring_buffer_resize() during memory free
c98cc9797b70 ring-buffer: Move cpus_read_lock() outside of buffer->mutex
]
|
| 39/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 46560
output: 24
thoughts: 17
Thoughts: Okay, here's my interpretation of that:
**Diving into Commit 6435ffd6c7fc**
Alright, time to get my hands dirty. My immediate thought is, "Let's crack open commit `6435ffd6c7fc` and see what we're dealing with." No fluff, no preamble – it's straight to the point. I'm mentally parsing that commit hash, prepping my mind for the details it holds. I'm expecting to either refresh my memory of what I already know about it, or, more likely, to engage with it directly, examining the diffs and code changes. Let's see what interesting tidbits are hiding in there!
|
| 40/2 |
2026/09/26 00:45 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 6435ffd6c7fcba330dfa91c58dc30aed2df3d0bf
Author: Wupeng Ma <mawupeng1@huawei.com>
Date: Sun Dec 28 14:50:07 2025 +0800
ring-buffer: Avoid softlockup in ring_buffer_resize() during memory free
When user resize all trace ring buffer through file 'buffer_size_kb',
then in ring_buffer_resize(), kernel allocates buffer pages for each
cpu in a loop.
If the kernel preemption model is PREEMPT_NONE and there are many cpus
and there are many buffer pages to be freed, it may not give up cpu
for a long time and finally cause a softlockup.
To avoid it, call cond_resched() after each cpu buffer free as Commit
f6bd2c92488c ("ring-buffer: Avoid softlockup in ring_buffer_resize()")
does.
Detailed call trace as follow:
rcu: INFO: rcu_sched self-detected stall on CPU
rcu: 24-....: (14837 ticks this GP) idle=521c/1/0x4000000000000000 softirq=230597/230597 fqs=5329
rcu: (t=15004 jiffies g=26003221 q=211022 ncpus=96)
CPU: 24 UID: 0 PID: 11253 Comm: bash Kdump: loaded Tainted: G EL 6.18.2+ #278 NONE
pc : arch_local_irq_restore+0x8/0x20
arch_local_irq_restore+0x8/0x20 (P)
free_frozen_page_commit+0x28c/0x3b0
__free_frozen_pages+0x1c0/0x678
___free_pages+0xc0/0xe0
free_pages+0x3c/0x50
ring_buffer_resize.part.0+0x6a8/0x880
ring_buffer_resize+0x3c/0x58
__tracing_resize_ring_buffer.part.0+0x34/0xd8
tracing_resize_ring_buffer+0x8c/0xd0
tracing_entries_write+0x74/0xd8
vfs_write+0xcc/0x288
ksys_write+0x74/0x118
__arm64_sys_write+0x24/0x38
Cc: <mathieu.desnoyers@efficios.com>
Link: https://patch.msgid.link/20251228065008.2396573-1-mawupeng1@huawei.com
Signed-off-by: Wupeng Ma <mawupeng1@huawei.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 41c9f5d079be..630221b00838 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3137,6 +3137,8 @@ int ring_buffer_resize(struct trace_buffer *buffer, unsigned long size,
list) {
list_del_init(&bpage->list);
free_buffer_page(bpage);
+
+ cond_resched();
}
}
out_err_unlock:
]
|
| 41/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 47780
output: 40
thoughts: 19
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience, presented in the first person:
**Digging into `ring_buffer.c` Commit History**
Alright, I need to understand the evolution of this particular code, and the context around how "commit_page" is being used, especially in relation to that `ring_buffer.c` file. My first instinct is to zero in on the commit history. I want to see how this function or variable or whatever the heck "commit_page" represents got introduced, modified, and potentially removed. A simple search for "commit_page" within the commit messages, specifically filtering for changes related to `ring_buffer.c`, should provide a very quick, high-level view of the relevant events and discussions. That's the best place to start before diving into diffs, code reviews, and possibly even related Jira tickets, if there are any. This should give me a good timeline and potentially reveal the motivations behind those changes. Let's see what we can find.
|
| 42/2 |
2026/09/26 00:45 |
tool |
git-log |
0m
Args: map[Count:10 MessageRegexps:[commit_page] PathPrefix:kernel/trace/ring_buffer.c]
Results: map[Output:f1e30cb63692 ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment
6455b6163d8c ring-buffer: Fix race while reader and writer are on the same page
67f0d6d9883c tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop.
5a50e33cc916 ring-buffer: Move access to commit_page up into function used
b85fa01ed958 ring_buffer: fix typing mistake
551b4048b3d4 ring_buffer: reset write when reserve buffer fail
6f3b34402e72 ring_buffer: reset write when reserve buffer fail
]
|
| 43/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 48255
output: 26
thoughts: 38
Thoughts: Okay, let's dive into this. Here's my summary, taking the perspective of someone deeply familiar with version control:
**Investigating a Specific Commit**
Right, so I've been given this intriguing hash: `f1e30cb63692`. My immediate thought? "Right, let's take a look. What does this commit actually *do*?" My instinct, practically automatic at this point, is to go straight to `git show f1e30cb63692`. That should give me the meat of the matter – the changes introduced, the commit message, the author, all the critical details I need to understand the impact of that particular snapshot in the project's history. No need to overthink it; the tools are there, the information is readily available. Time to start digging!
|
| 44/2 |
2026/09/26 00:45 |
tool |
git-show |
0m
Args:
Results: map[Output:commit f1e30cb6369251c03f63c564006f96a54197dcc4
Author: linke li <lilinke99@qq.com>
Date: Sat Mar 2 12:42:21 2024 +0800
ring-buffer: use READ_ONCE() to read cpu_buffer->commit_page in concurrent environment
In function ring_buffer_iter_empty(), cpu_buffer->commit_page is read
while other threads may change it. It may cause the time_stamp that read
in the next line come from a different page. Use READ_ONCE() to avoid
having to reason about compiler optimizations now and in future.
Link: https://lore.kernel.org/linux-trace-kernel/tencent_DFF7D3561A0686B5E8FC079150A02505180A@qq.com
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: linke li <lilinke99@qq.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 67d32af48640..788d321036bd 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -4382,7 +4382,7 @@ int ring_buffer_iter_empty(struct ring_buffer_iter *iter)
cpu_buffer = iter->cpu_buffer;
reader = cpu_buffer->reader_page;
head_page = cpu_buffer->head_page;
- commit_page = cpu_buffer->commit_page;
+ commit_page = READ_ONCE(cpu_buffer->commit_page);
commit_ts = commit_page->page->time_stamp;
/*
]
|
| 45/2 |
2026/09/26 00:45 |
llm |
expert |
0m
Model:
Tokens:
input: 49054
output: 56
thoughts: 24
Thoughts: Okay, let's dive into this. Here's how I'd approach this task, as if these were my internal thoughts:
**Investigating `rb_remove_pages` Modifications in `ring_buffer.c`**
Alright, I need to figure out the history of `rb_remove_pages` within the `ring_buffer.c` file. This means I'm going to leverage my version control knowledge to pinpoint the relevant commits. My goal is to quickly identify the changes made to that specific function. I'll probably be using my preferred version control tool; let's see, depending on the project, it might be git or something else, but either way, I will be searching for the modifications. So, my mental checklist now involves: finding the right tool and then using that tool to precisely focus on the function `rb_remove_pages`. I'll filter by that function name to avoid extraneous results and zoom in on the specific history I'm after. I'll want to review the associated commit messages and diffs to understand *why* those changes were made. I'm looking for patterns in the modifications – were they bug fixes, performance improvements, or functional enhancements? This level of detail will paint a clearer picture of the function's evolution.
|
| 46/2 |
2026/09/26 00:46 |
tool |
git-log |
0m
Error:
Args: map[Count:10 PathPrefix:kernel/trace/ring_buffer.c SourcePath:kernel/trace/ring_buffer.c SymbolName:rb_remove_pages]
Results:
|
| 47/2 |
2026/09/26 00:46 |
llm |
expert |
0m
Model:
Tokens:
input: 49424
output: 41
thoughts: 14
Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience:
**Analyzing Git History with Symbol and Source Context**
Right, so I'm thinking about how to effectively analyze the commit history related to a specific symbol in the codebase. My immediate inclination is to leverage `git-log`, but I need to be precise. The core idea is to invoke `git-log` with, at a minimum, the `SymbolName` and the `SourcePath`. This pairing is crucial. `SymbolName` gets me to the actual object, variable, function, etc., that I'm interested in, and `SourcePath` provides the contextual boundaries, guiding the search within the relevant files or directories. That's the baseline, the most direct approach to pinpointing the commits that touch that specific piece of code.
|
| 48/2 |
2026/09/26 00:46 |
tool |
git-log |
0m
Args: map[Count:10 SourcePath:kernel/trace/ring_buffer.c SymbolName:rb_remove_pages]
Results: map[Output:b237e1f7d227 ring-buffer: Limit time with disabled interrupts in rb_check_pages()
45d99ea451d0 ring-buffer: Fix bytes info in per_cpu buffer stats
2d093282b0d4 ring-buffer: Fix wrong stat of cpu_buffer->read
31029a8b2c7e ring-buffer: Include dropped pages in counting dirty patches
6689bed36c52 ring-buffer: Remove cpu_buffer argument from the rb_inc_page()
83f365554e47 ring-buffer: Allow for rescheduling when removing pages
9b94a8fba501 ring-buffer: Use long for nr_pages to avoid overflow failures
48fdc72f23ad ring-buffer: Fix accounting of entries when removing pages
5040b4b7bcc2 ring-buffer: Make addition of pages in ring buffer atomic
83f40318dab0 ring-buffer: Make removal of ring buffer pages atomic
]
|
| 49/2 |
2026/09/26 00:46 |
llm |
expert |
0m
Model:
Tokens:
input: 49912
output: 27
thoughts: 37
Thoughts: Here's my analysis of the commit, rendered in the first person:
**Analyzing the Ring Buffer Rescheduling Commit**
Okay, let's dive into this commit: `83f365554e47 ring-buffer: Allow for rescheduling when removing pages`. The title immediately grabs my attention. The ring buffer, as we know, is a critical data structure, and any change related to its page management, especially rescheduling, warrants a closer look. I'm expecting this to address some specific contention or latency issue. The phrase "Allow for rescheduling" suggests a potential optimization or a fix for a blocking scenario. I'm imagining this relates to freeing pages and minimizing wait times. I'm curious if this commit is dealing with the interrupt handling related to page removal. I need to understand the specifics of how rescheduling is handled to assess any potential side effects. Is the rescheduling done with the interrupt handler disabled? Are locks acquired? I wonder if this change introduces any new critical sections or race conditions, or if it improves the lock granularity. Time to delve into the code.
|
| 50/2 |
2026/09/26 00:46 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 83f365554e47997ec68dc4eca3f5dce525cd15c3
Author: Vaibhav Nagarnaik <vnagarnaik@google.com>
Date: Fri Sep 7 15:31:29 2018 -0700
ring-buffer: Allow for rescheduling when removing pages
When reducing ring buffer size, pages are removed by scheduling a work
item on each CPU for the corresponding CPU ring buffer. After the pages
are removed from ring buffer linked list, the pages are free()d in a
tight loop. The loop does not give up CPU until all pages are removed.
In a worst case behavior, when lot of pages are to be freed, it can
cause system stall.
After the pages are removed from the list, the free() can happen while
the work is rescheduled. Call cond_resched() in the loop to prevent the
system hangup.
Link: http://lkml.kernel.org/r/20180907223129.71994-1-vnagarnaik@google.com
Cc: stable@vger.kernel.org
Fixes: 83f40318dab00 ("ring-buffer: Make removal of ring buffer pages atomic")
Reported-by: Jason Behmer <jbehmer@google.com>
Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 1d92d4a982fd..65bd4616220d 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -1546,6 +1546,8 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned long nr_pages)
tmp_iter_page = first_page;
do {
+ cond_resched();
+
to_remove_page = tmp_iter_page;
rb_inc_page(cpu_buffer, &tmp_iter_page);
]
|
| 51/2 |
2026/09/26 00:46 |
llm |
expert |
0m
Model:
Tokens:
input: 50798
output: 15
thoughts: 3327
Thoughts: **Analysis of a Kernel Ring Buffer Use-After-Free Vulnerability**
Okay, here's what I've pieced together. `rb_remove_pages()` is the culprit. It's supposed to remove pages from the ring buffer. I see the code removes a contiguous range of pages. The critical thing here is how it updates the linked list pointers – it *bypasses* the removed pages, essentially unlinking them from the ring buffer. But, and this is key, the internal `prev` and `next` pointers within those removed pages *aren't* changed. They still point to each other as they did before being removed.
Now, let's consider the `commit_page`. This page represents where a write operation *started*. Crucially, if the ring buffer wraps around, `commit_page` can lag behind the `tail_page` (which represents the *current* write position). Here's the danger: if `commit_page` happens to be within the set of pages that get removed by `rb_remove_pages()`, then `rb_is_reader_page()` function gets called and it will encounter a freed page.
The crash happens in `rb_is_reader_page()` which, uses `page->list.prev` to check if a page is a reader page, and this is where the UAF occurs. The address where the kernel panicked, `ffff888033712280`, is the start of a recently freed 64-byte `struct buffer_page` object. KASAN confirms this. The stack traces nail it down: one for the allocation, one for the free (during `rb_remove_pages()`), and one for the *use* in `rb_is_reader_page()`. The accessed memory offset perfectly matches the `list.next` pointer in the `struct list_head`.
So, it's a classic race: the buffer is being resized (pages being removed and freed), *while* other writers are still active in the ring buffer. The writer tries to call `rb_is_reader_page`, and it access a freed page. `rb_remove_pages()` removes the page, but the writer continues to try to access that page! The fact that the accessed pointer points to offset 0 means it's reading the `next` pointer of the freed `struct buffer_page`. The crash results when this freed `buffer_page` is read later in `rb_is_reader_page`. The root cause is a synchronization issue between buffer downsizing and concurrent ring buffer writes. This is a very clear and actionable use-after-free!
|
| 52/2 |
2026/09/26 00:46 |
tool |
set-results |
0m
Args:
Results:
|
| 53/2 |
2026/09/26 00:46 |
llm |
expert |
0m
Model:
Tokens:
input: 54717
output: 666
thoughts: 41
Thoughts: Here's my take on that, given the prompt:
**Analyzing the `set-results` Tool's Context**
Okay, the `set-results` tool has been invoked. My immediate focus is on crafting a response that directly addresses the bug report's self-consistency and actionability, as per the instructions. I need to be precise, clear, and comprehensive. This means I must:
1. **Verify the Consistency:** First, I'll assess whether the reported issue's details, expected behavior, and observed results are logically aligned. Are there any contradictions or gaps in the information presented? A self-consistent report provides enough information to validate the claimed issue.
2. **Determine Actionability:** Second, I'll evaluate if the bug report provides sufficient actionable steps for someone to reproduce and fix the bug. Does it describe a clear path to replicate the problem? Are there enough specifics about the environment, steps to reproduce, error messages (if any), and expected versus actual results to guide a developer towards a solution? If not, does it contain enough information so further questions can be asked to make it actionable?
3. **Synthesize into a Concise Explanation:** Finally, I'll compile my findings into a concise, well-structured explanation that highlights the aspects supporting the report's validity and the ability to address the issue. I'll make sure to explicitly state *why* it is self-consistent and *how* it's actionable, focusing on the key evidence in the report that supports these conclusions. This is not just a summary of the report itself, but an analysis of its properties relative to the prompt's requirements.
|
| 54/1 |
2026/09/26 00:46 |
action |
format-explanation |
0m
Results: map[Explanation:The bug report is **actionable** and **self-consistent**.
### Detailed Analysis:
1. **Presence of All Three Required Stack Traces**:
- **Bad Memory Access Stack**: Task 6764 encounters a slab-use-after-free in
`rb_is_reader_page` (inlined in `rb_move_tail` at
`kernel/trace/ring_buffer.c:3964`) while reserving space for an event in the
ring buffer (`__rb_reserve_next` via `trace_lock_release`).
- **Allocation Stack**: Task 6453 allocated the object in
`__rb_allocate_pages` (`kernel/trace/ring_buffer.c:2483`) via
`alloc_cpu_page()` during ring buffer expansion (`ring_buffer_resize`).
- **Free Stack**: Task 10552 freed the object in `free_buffer_page`
(`kernel/trace/ring_buffer.c:418`) called by `rb_remove_pages`
(`kernel/trace/ring_buffer.c:3169`) during ring buffer downsizing
(`ring_buffer_resize`).
2. **Subsystem and Object Type Consistency**:
- All three stacks belong to the exact same kernel subsystem: the tracing
ring buffer (`kernel/trace/ring_buffer.c`).
- All three stacks manipulate the exact same struct: `struct buffer_page`.
- `struct buffer_page` has a size of 64 bytes and is allocated from the
`kmalloc-64` slab cache.
- The reported access is a read of 8 bytes at offset 0 (`ffff888033712280`,
located 0 bytes inside the freed 64-byte region `[ffff888033712280,
ffff8880337122c0)`). This precisely matches `list.next` (the first field in
`struct buffer_page` / `struct list_head`) being dereferenced by
`rb_is_reader_page()`:
```c
struct list_head *list = page->list.prev;
return rb_list_head(list->next) != &page->list;
```
3. **Plausible Bug Mechanism**:
- Resizing the ring buffer down via `tracing_entries_write` /
`ring_buffer_resize` removes pages via `rb_remove_pages()` and frees them
(`free_buffer_page()`).
- Concurrently, an active writer interrupted or preempted during
reserve/commit operations (`__rb_reserve_next` / `rb_move_tail`) traverses or
references page pointers (such as `cpu_buffer->commit_page`), accessing a
`struct buffer_page` that has already been unlinked and freed.
Because the report contains all three coherent stack traces with matching data
structures, offsets, and a clear race condition mechanism, it provides
sufficient information to root-cause and fix the bug.]
|