[moderation] [perf?] KCSAN: data-race in event_sched_in / perf_event_release_kernel

0 views
Skip to first unread message

syzbot

unread,
7:05 PM (1 hour ago) 7:05 PM
to syzkaller-upst...@googlegroups.com
Hello,

syzbot found the following issue on:

HEAD commit: 8dac6df92a2e Merge tag 'nfsd-7.4-1' of git://git.kernel.or..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=156dccd5580000
kernel config: https://syzkaller.appspot.com/x/.config?x=886d2ddd2d6b664e
dashboard link: https://syzkaller.appspot.com/bug?extid=ca170c97cd5de8125b23
compiler: Debian clang version 22.1.8 (1~deb13u4), Debian LLD 22.1.8
CC: [ac...@kernel.org adrian...@intel.com alexander...@linux.intel.com iro...@google.com james...@linaro.org jo...@kernel.org linux-...@vger.kernel.org linux-pe...@vger.kernel.org mark.r...@arm.com mi...@redhat.com namh...@kernel.org pet...@infradead.org]

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/dfc787d10469/disk-8dac6df9.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/db7a8e4799da/vmlinux-8dac6df9.xz
kernel image: https://storage.googleapis.com/syzbot-assets/169073a123bc/bzImage-8dac6df9.xz

AI-generated root cause summary:
In `kernel/events/core.c`, `perf_event_release_kernel()` performs an unmarked
read of `event->state` while holding only `ctx->mutex`, racing with
`event_sched_in()` -> `perf_event_set_state()` updating `event->state` via
`WRITE_ONCE()` under `ctx->lock` during context switch. Because `ctx->mutex`
serializes all transitions to `PERF_EVENT_STATE_REVOKED` and
`PERF_EVENT_STATE_DEAD`, any concurrent `ctx->lock` transitions (such as
`PERF_EVENT_STATE_INACTIVE` to `PERF_EVENT_STATE_ACTIVE`) remain strictly
greater than `PERF_EVENT_STATE_REVOKED`. As a result,
`perf_event_release_kernel()` still consistently takes the
`perf_remove_from_context()` branch, making this a benign KCSAN data race caused
by a missing `READ_ONCE()`.

full analysis: https://syzkaller.appspot.com/x/ai_root_cause?x=ca170c97cd5de8125b23

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+ca170c...@syzkaller.appspotmail.com

==================================================================
BUG: KCSAN: data-race in event_sched_in / perf_event_release_kernel

write (marked) to 0xffff88811b7e2028 of 4 bytes by task 6809 on cpu 1:
perf_event_set_state kernel/events/core.c:790 [inline]
event_sched_in+0x360/0xc70 kernel/events/core.c:2849
group_sched_in kernel/events/core.c:2896 [inline]
merge_sched_in+0x252/0xbe0 kernel/events/core.c:4160
visit_groups_merge+0x9cb/0xf70 kernel/events/core.c:4091
pmu_groups_sched_in kernel/events/core.c:4196 [inline]
__pmu_ctx_sched_in kernel/events/core.c:-1 [inline]
ctx_sched_in+0x3ba/0x410 kernel/events/core.c:4275
perf_event_sched_in kernel/events/core.c:-1 [inline]
perf_event_context_sched_in kernel/events/core.c:4322 [inline]
__perf_event_task_sched_in+0x69e/0xb50 kernel/events/core.c:4351
perf_event_task_sched_in include/linux/perf_event.h:1645 [inline]
finish_task_switch+0x2bd/0x340 kernel/sched/core.c:5430
context_switch kernel/sched/core.c:5587 [inline]
__schedule+0x796/0xd30 kernel/sched/core.c:7386
preempt_schedule_irq+0x2c/0x50 kernel/sched/core.c:7666
irqentry_exit_cond_resched kernel/entry/common.c:145 [inline]
irqentry_exit_to_kernel_mode_preempt+0x63/0x80 include/linux/irq-entry-common.h:453
irqentry_exit_to_kernel_mode include/linux/irq-entry-common.h:543 [inline]
irqentry_exit+0x99/0x640 kernel/entry/common.c:154
sysvec_apic_timer_interrupt+0x44/0x80 arch/x86/kernel/apic/apic.c:1062
asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674
syscall_enter_from_user_mode_work include/linux/entry-common.h:142 [inline]
do_syscall_64+0x86/0x3a0 arch/x86/entry/syscall_64.c:86
entry_SYSCALL_64_after_hwframe+0x77/0x7f

read to 0xffff88811b7e2028 of 4 bytes by task 6808 on cpu 0:
perf_event_release_kernel+0x23f/0x550 kernel/events/core.c:5990
perf_release+0x1f/0x30 kernel/events/core.c:6066
__fput+0x292/0x660 fs/file_table.c:512
fput_close_sync+0xd5/0x1d0 fs/file_table.c:618
filp_close_sync+0x27/0x40 fs/open.c:1574
__range_close fs/file.c:919 [inline]
__do_sys_close_range fs/file.c:1003 [inline]
__se_sys_close_range+0x765/0x880 fs/file.c:954
__x64_sys_close_range+0x43/0x50 fs/file.c:954
x64_sys_call+0x2198/0x2550 arch/x86/include/generated/asm/syscalls_64.h:437
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x11e/0x3a0 arch/x86/entry/syscall_64.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f

value changed: 0x00000000 -> 0x00000001

Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 6808 Comm: syz.1.662 Not tainted syzkaller #0 PREEMPT(lazy)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/06/2026
==================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzk...@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup
Reply all
Reply to author
Forward
0 new messages