* [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2)
@ 2024-10-14 6:09 syzbot
2024-10-14 8:30 ` Dmitry Vyukov
0 siblings, 1 reply; 5+ messages in thread
From: syzbot @ 2024-10-14 6:09 UTC (permalink / raw)
To: acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
kan.liang, linux-kernel, linux-perf-users, mark.rutland, mingo,
namhyung, peterz, syzkaller-bugs
Hello,
syzbot found the following issue on:
HEAD commit: 87d6aab2389e Merge tag 'for_linus' of git://git.kernel.org..
git tree: upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=10104f9f980000
kernel config: https://syzkaller.appspot.com/x/.config?x=a2f7ae2f221e9eae
dashboard link: https://syzkaller.appspot.com/bug?extid=e75157f5b04f8ff40e17
compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
Unfortunately, I don't have any reproducer for this issue yet.
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/cce40536bdc3/disk-87d6aab2.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/479edc06c8d8/vmlinux-87d6aab2.xz
kernel image: https://storage.googleapis.com/syzbot-assets/9d377c65ffca/bzImage-87d6aab2.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com
==================================================================
BUG: KCSAN: data-race in _free_event / perf_pending_task
write to 0xffff8881155361e8 of 4 bytes by task 9574 on cpu 1:
perf_pending_task+0xe8/0x220 kernel/events/core.c:6976
task_work_run+0x13a/0x1a0 kernel/task_work.c:228
resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0xbe/0x130 kernel/entry/common.c:218
do_syscall_64+0xd6/0x1c0 arch/x86/entry/common.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
read to 0xffff8881155361e8 of 4 bytes by task 9573 on cpu 0:
perf_pending_task_sync kernel/events/core.c:5302 [inline]
_free_event+0x3d/0xa10 kernel/events/core.c:5326
put_event kernel/events/core.c:5454 [inline]
perf_event_release_kernel+0x61a/0x670 kernel/events/core.c:5579
perf_release+0x1f/0x30 kernel/events/core.c:5589
__fput+0x17a/0x6d0 fs/file_table.c:431
____fput+0x1c/0x30 fs/file_table.c:459
task_work_run+0x13a/0x1a0 kernel/task_work.c:228
resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
__syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
syscall_exit_to_user_mode+0xbe/0x130 kernel/entry/common.c:218
do_syscall_64+0xd6/0x1c0 arch/x86/entry/common.c:89
entry_SYSCALL_64_after_hwframe+0x77/0x7f
value changed: 0x7ad100bf -> 0x00000000
Reported by Kernel Concurrency Sanitizer on:
CPU: 0 UID: 0 PID: 9573 Comm: syz.3.2265 Tainted: G W 6.12.0-rc2-syzkaller-00006-g87d6aab2389e #0
Tainted: [W]=WARN
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
==================================================================
---
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 syzkaller@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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2)
2024-10-14 6:09 [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2) syzbot
@ 2024-10-14 8:30 ` Dmitry Vyukov
2024-10-14 9:40 ` Marco Elver
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Vyukov @ 2024-10-14 8:30 UTC (permalink / raw)
To: syzbot, Marco Elver
Cc: acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
kan.liang, linux-kernel, linux-perf-users, mark.rutland, mingo,
namhyung, peterz, syzkaller-bugs
On Mon, 14 Oct 2024 at 08:09, syzbot
<syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com> wrote:
>
> Hello,
>
> syzbot found the following issue on:
>
> HEAD commit: 87d6aab2389e Merge tag 'for_linus' of git://git.kernel.org..
> git tree: upstream
> console output: https://syzkaller.appspot.com/x/log.txt?x=10104f9f980000
> kernel config: https://syzkaller.appspot.com/x/.config?x=a2f7ae2f221e9eae
> dashboard link: https://syzkaller.appspot.com/bug?extid=e75157f5b04f8ff40e17
> compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
>
> Unfortunately, I don't have any reproducer for this issue yet.
>
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/cce40536bdc3/disk-87d6aab2.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/479edc06c8d8/vmlinux-87d6aab2.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/9d377c65ffca/bzImage-87d6aab2.xz
>
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com
>
> ==================================================================
> BUG: KCSAN: data-race in _free_event / perf_pending_task
>
> write to 0xffff8881155361e8 of 4 bytes by task 9574 on cpu 1:
> perf_pending_task+0xe8/0x220 kernel/events/core.c:6976
> task_work_run+0x13a/0x1a0 kernel/task_work.c:228
> resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
> exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
> exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
> __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
> syscall_exit_to_user_mode+0xbe/0x130 kernel/entry/common.c:218
> do_syscall_64+0xd6/0x1c0 arch/x86/entry/common.c:89
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
> read to 0xffff8881155361e8 of 4 bytes by task 9573 on cpu 0:
> perf_pending_task_sync kernel/events/core.c:5302 [inline]
+Marco, IIRC we assumed event->pending_work should only be accessed by
the owner task.
Here it's concurrently modified/changed. The other task calls
task_work_cancel on current based on the valus of this field, this
looks bad.
> _free_event+0x3d/0xa10 kernel/events/core.c:5326
> put_event kernel/events/core.c:5454 [inline]
> perf_event_release_kernel+0x61a/0x670 kernel/events/core.c:5579
> perf_release+0x1f/0x30 kernel/events/core.c:5589
> __fput+0x17a/0x6d0 fs/file_table.c:431
> ____fput+0x1c/0x30 fs/file_table.c:459
> task_work_run+0x13a/0x1a0 kernel/task_work.c:228
> resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
> exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
> exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
> __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
> syscall_exit_to_user_mode+0xbe/0x130 kernel/entry/common.c:218
> do_syscall_64+0xd6/0x1c0 arch/x86/entry/common.c:89
> entry_SYSCALL_64_after_hwframe+0x77/0x7f
>
> value changed: 0x7ad100bf -> 0x00000000
>
> Reported by Kernel Concurrency Sanitizer on:
> CPU: 0 UID: 0 PID: 9573 Comm: syz.3.2265 Tainted: G W 6.12.0-rc2-syzkaller-00006-g87d6aab2389e #0
> Tainted: [W]=WARN
> Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024
> ==================================================================
>
>
> ---
> 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 syzkaller@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
>
> --
> You received this message because you are subscribed to the Google Groups "syzkaller-bugs" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to syzkaller-bugs+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/syzkaller-bugs/670cb595.050a0220.4cbc0.0043.GAE%40google.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2)
2024-10-14 8:30 ` Dmitry Vyukov
@ 2024-10-14 9:40 ` Marco Elver
2024-10-14 10:30 ` Dmitry Vyukov
0 siblings, 1 reply; 5+ messages in thread
From: Marco Elver @ 2024-10-14 9:40 UTC (permalink / raw)
To: Dmitry Vyukov
Cc: syzbot, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
kan.liang, linux-kernel, linux-perf-users, mark.rutland, mingo,
namhyung, peterz, syzkaller-bugs
On Mon, 14 Oct 2024 at 10:30, Dmitry Vyukov <dvyukov@google.com> wrote:
>
> On Mon, 14 Oct 2024 at 08:09, syzbot
> <syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com> wrote:
> >
> > Hello,
> >
> > syzbot found the following issue on:
> >
> > HEAD commit: 87d6aab2389e Merge tag 'for_linus' of git://git.kernel.org..
> > git tree: upstream
> > console output: https://syzkaller.appspot.com/x/log.txt?x=10104f9f980000
> > kernel config: https://syzkaller.appspot.com/x/.config?x=a2f7ae2f221e9eae
> > dashboard link: https://syzkaller.appspot.com/bug?extid=e75157f5b04f8ff40e17
> > compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
> >
> > Unfortunately, I don't have any reproducer for this issue yet.
> >
> > Downloadable assets:
> > disk image: https://storage.googleapis.com/syzbot-assets/cce40536bdc3/disk-87d6aab2.raw.xz
> > vmlinux: https://storage.googleapis.com/syzbot-assets/479edc06c8d8/vmlinux-87d6aab2.xz
> > kernel image: https://storage.googleapis.com/syzbot-assets/9d377c65ffca/bzImage-87d6aab2.xz
> >
> > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > Reported-by: syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com
> >
> > ==================================================================
> > BUG: KCSAN: data-race in _free_event / perf_pending_task
> >
> > write to 0xffff8881155361e8 of 4 bytes by task 9574 on cpu 1:
> > perf_pending_task+0xe8/0x220 kernel/events/core.c:6976
> > task_work_run+0x13a/0x1a0 kernel/task_work.c:228
> > resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
> > exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
> > exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
> > __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
> > syscall_exit_to_user_mode+0xbe/0x130 kernel/entry/common.c:218
> > do_syscall_64+0xd6/0x1c0 arch/x86/entry/common.c:89
> > entry_SYSCALL_64_after_hwframe+0x77/0x7f
> >
> > read to 0xffff8881155361e8 of 4 bytes by task 9573 on cpu 0:
> > perf_pending_task_sync kernel/events/core.c:5302 [inline]
>
> +Marco, IIRC we assumed event->pending_work should only be accessed by
> the owner task.
> Here it's concurrently modified/changed. The other task calls
> task_work_cancel on current based on the valus of this field, this
> looks bad.
On freeing an event it can be any other task, AFAIK. There's this comment:
> * All accesses related to the event are within the same RCU section in
> * perf_pending_task(). The RCU grace period before the event is freed
> * will make sure all those accesses are complete by then.
So there is no risk of UAF.
All that may happen is that on concurrent free of an event with a
pending SIGTRAP, it's possible the SIGTRAP may or may not be
delivered. But I think that's perfectly reasonable if the event is in
the process of being closed.
Did I miss something?
Thanks,
-- Marco
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2)
2024-10-14 9:40 ` Marco Elver
@ 2024-10-14 10:30 ` Dmitry Vyukov
2024-10-14 12:42 ` Marco Elver
0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Vyukov @ 2024-10-14 10:30 UTC (permalink / raw)
To: Marco Elver
Cc: syzbot, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
kan.liang, linux-kernel, linux-perf-users, mark.rutland, mingo,
namhyung, peterz, syzkaller-bugs
On Mon, 14 Oct 2024 at 11:41, Marco Elver <elver@google.com> wrote:
>
> On Mon, 14 Oct 2024 at 10:30, Dmitry Vyukov <dvyukov@google.com> wrote:
> >
> > On Mon, 14 Oct 2024 at 08:09, syzbot
> > <syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com> wrote:
> > >
> > > Hello,
> > >
> > > syzbot found the following issue on:
> > >
> > > HEAD commit: 87d6aab2389e Merge tag 'for_linus' of git://git.kernel.org..
> > > git tree: upstream
> > > console output: https://syzkaller.appspot.com/x/log.txt?x=10104f9f980000
> > > kernel config: https://syzkaller.appspot.com/x/.config?x=a2f7ae2f221e9eae
> > > dashboard link: https://syzkaller.appspot.com/bug?extid=e75157f5b04f8ff40e17
> > > compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40
> > >
> > > Unfortunately, I don't have any reproducer for this issue yet.
> > >
> > > Downloadable assets:
> > > disk image: https://storage.googleapis.com/syzbot-assets/cce40536bdc3/disk-87d6aab2.raw.xz
> > > vmlinux: https://storage.googleapis.com/syzbot-assets/479edc06c8d8/vmlinux-87d6aab2.xz
> > > kernel image: https://storage.googleapis.com/syzbot-assets/9d377c65ffca/bzImage-87d6aab2.xz
> > >
> > > IMPORTANT: if you fix the issue, please add the following tag to the commit:
> > > Reported-by: syzbot+e75157f5b04f8ff40e17@syzkaller.appspotmail.com
> > >
> > > ==================================================================
> > > BUG: KCSAN: data-race in _free_event / perf_pending_task
> > >
> > > write to 0xffff8881155361e8 of 4 bytes by task 9574 on cpu 1:
> > > perf_pending_task+0xe8/0x220 kernel/events/core.c:6976
> > > task_work_run+0x13a/0x1a0 kernel/task_work.c:228
> > > resume_user_mode_work include/linux/resume_user_mode.h:50 [inline]
> > > exit_to_user_mode_loop kernel/entry/common.c:114 [inline]
> > > exit_to_user_mode_prepare include/linux/entry-common.h:328 [inline]
> > > __syscall_exit_to_user_mode_work kernel/entry/common.c:207 [inline]
> > > syscall_exit_to_user_mode+0xbe/0x130 kernel/entry/common.c:218
> > > do_syscall_64+0xd6/0x1c0 arch/x86/entry/common.c:89
> > > entry_SYSCALL_64_after_hwframe+0x77/0x7f
> > >
> > > read to 0xffff8881155361e8 of 4 bytes by task 9573 on cpu 0:
> > > perf_pending_task_sync kernel/events/core.c:5302 [inline]
> >
> > +Marco, IIRC we assumed event->pending_work should only be accessed by
> > the owner task.
> > Here it's concurrently modified/changed. The other task calls
> > task_work_cancel on current based on the valus of this field, this
> > looks bad.
>
> On freeing an event it can be any other task, AFAIK. There's this comment:
>
> > * All accesses related to the event are within the same RCU section in
> > * perf_pending_task(). The RCU grace period before the event is freed
> > * will make sure all those accesses are complete by then.
>
> So there is no risk of UAF.
>
> All that may happen is that on concurrent free of an event with a
> pending SIGTRAP, it's possible the SIGTRAP may or may not be
> delivered. But I think that's perfectly reasonable if the event is in
> the process of being closed.
>
> Did I miss something?
I have not recap all logic, but what looked suspicious on the first glance:
The task doing _free_event->perf_pending_task_sync is not the owner of
the event (the other task is the owner?).
But that task is later using 'current' to do something with regard to
this event:
/*
* If the task is queued to the current task's queue, we
* obviously can't wait for it to complete. Simply cancel it.
*/
if (task_work_cancel(current, head)) {
Is this current wrong here? So it may both not cancel it for the real
owner, and cancel something else for itself (?).
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2)
2024-10-14 10:30 ` Dmitry Vyukov
@ 2024-10-14 12:42 ` Marco Elver
0 siblings, 0 replies; 5+ messages in thread
From: Marco Elver @ 2024-10-14 12:42 UTC (permalink / raw)
To: Dmitry Vyukov
Cc: syzbot, acme, adrian.hunter, alexander.shishkin, irogers, jolsa,
kan.liang, linux-kernel, linux-perf-users, mark.rutland, mingo,
namhyung, peterz, syzkaller-bugs
On Mon, 14 Oct 2024 at 12:30, Dmitry Vyukov <dvyukov@google.com> wrote:
[...]
> But that task is later using 'current' to do something with regard to
> this event:
>
> /*
> * If the task is queued to the current task's queue, we
> * obviously can't wait for it to complete. Simply cancel it.
> */
> if (task_work_cancel(current, head)) {
>
> Is this current wrong here? So it may both not cancel it for the real
> owner, and cancel something else for itself (?).
That's fine - task_work_cancel() looks for the event in the passed
task_struct, and does nothing if not found. If the task_work is owned
by another task, task_work_cancel() will never find a match, and this
is a no-op. The later rcuwait_wait_event() will wait for the task_work
to complete in the other task.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-10-14 12:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-14 6:09 [syzbot] [perf?] KCSAN: data-race in _free_event / perf_pending_task (2) syzbot
2024-10-14 8:30 ` Dmitry Vyukov
2024-10-14 9:40 ` Marco Elver
2024-10-14 10:30 ` Dmitry Vyukov
2024-10-14 12:42 ` Marco Elver
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox