KASAN: slab-use-after-free Write in kvm_gmem_release
Subsystems (3)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: aaa9c3550b60 Add linux-next specific files for 20251022 git tree: linux-next console output: https://syzkaller.appspot.com/x/log.txt?x=1021c3e2580000 kernel config: https://syzkaller.appspot.com/x/.config?x=ad8f5526e5acd067 dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=10dd0c92580000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=1152c614580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/2fe0a8f92a64/disk-aaa9c355.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/199d2e804802/vmlinux-aaa9c355.xz
kernel image: https://storage.googleapis.com/syzbot-assets/9371d55e359e/bzImage-aaa9c355.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
==================================================================
BUG: KASAN: slab-use-after-free in kvm_gmem_release+0x176/0x440 virt/kvm/guest_memfd.c:353 Write of size 8 at addr ffff88807befa508 by task syz.0.17/6022 CPU: 0 UID: 0 PID: 6022 Comm: syz.0.17 Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025 Call Trace: <TASK> dump_stack_lvl+0x189/0x250 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xca/0x240 mm/kasan/report.c:482 kasan_report+0x118/0x150 mm/kasan/report.c:595 kvm_gmem_release+0x176/0x440 virt/kvm/guest_memfd.c:353 __fput+0x44c/0xa70 fs/file_table.c:468 task_work_run+0x1d4/0x260 kernel/task_work.c:227 resume_user_mode_work include/linux/resume_user_mode.h:50 [inline] exit_to_user_mode_loop+0xe9/0x130 kernel/entry/common.c:43 exit_to_user_mode_prepare include/linux/irq-entry-common.h:225 [inline] syscall_exit_to_user_mode_work include/linux/entry-common.h:175 [inline] syscall_exit_to_user_mode include/linux/entry-common.h:210 [inline] do_syscall_64+0x2bd/0xfa0 arch/x86/entry/syscall_64.c:100 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fbeeff8efc9 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007ffffdf1e2c8 EFLAGS: 00000246 ORIG_RAX: 00000000000001b4 RAX: 0000000000000000 RBX: 00007fbef01e7da0 RCX: 00007fbeeff8efc9 RDX: 0000000000000000 RSI: 000000000000001e RDI: 0000000000000003 RBP: 00007fbef01e7da0 R08: 0000000000000000 R09: 00000004fdf1e5bf R10: 00007fbef01e7cb0 R11: 0000000000000246 R12: 0000000000019ff7 R13: 00007ffffdf1e3c0 R14: ffffffffffffffff R15: 00007ffffdf1e3e0 </TASK> Allocated by task 6023: kasan_save_stack mm/kasan/common.c:56 [inline] kasan_save_track+0x3e/0x80 mm/kasan/common.c:77 poison_kmalloc_redzone mm/kasan/common.c:397 [inline] __kasan_kmalloc+0x93/0xb0 mm/kasan/common.c:414 kasan_kmalloc include/linux/kasan.h:262 [inline] __kmalloc_cache_noprof+0x3e2/0x700 mm/slub.c:5758 kmalloc_noprof include/linux/slab.h:957 [inline] kzalloc_noprof include/linux/slab.h:1094 [inline] kvm_set_memory_region+0x747/0xb90 virt/kvm/kvm_main.c:2104 kvm_vm_ioctl_set_memory_region+0x6f/0xd0 virt/kvm/kvm_main.c:2154 kvm_vm_ioctl+0x957/0xc60 virt/kvm/kvm_main.c:5201 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 6023: kasan_save_stack mm/kasan/common.c:56 [inline] kasan_save_track+0x3e/0x80 mm/kasan/common.c:77 kasan_save_free_info+0x46/0x50 mm/kasan/generic.c:584 poison_slab_object mm/kasan/common.c:252 [inline] __kasan_slab_free+0x5c/0x80 mm/kasan/common.c:284 kasan_slab_free include/linux/kasan.h:234 [inline] slab_free_hook mm/slub.c:2533 [inline] slab_free mm/slub.c:6622 [inline] kfree+0x19a/0x6d0 mm/slub.c:6829 kvm_set_memory_region+0x9c4/0xb90 virt/kvm/kvm_main.c:2130 kvm_vm_ioctl_set_memory_region+0x6f/0xd0 virt/kvm/kvm_main.c:2154 kvm_vm_ioctl+0x957/0xc60 virt/kvm/kvm_main.c:5201 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl+0xfc/0x170 fs/ioctl.c:583 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the object at ffff88807befa400 which belongs to the cache kmalloc-cg-512 of size 512
The buggy address is located 264 bytes inside of
freed 512-byte region [ffff88807befa400, ffff88807befa600)
The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7bef8
head: order:2 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0 memcg:ffff888077513701
anon flags: 0xfff00000000040(head|node=0|zone=1|lastcpupid=0x7ff)page_type: f5(slab)
raw: 00fff00000000040 ffff88813fe30140 0000000000000000 dead000000000001 raw: 0000000000000000 0000000000100010 00000000f5000000 ffff888077513701
head: 00fff00000000040 ffff88813fe30140 0000000000000000 dead000000000001
head: 0000000000000000 0000000000100010 00000000f5000000 ffff888077513701
head: 00fff00000000002 ffffea0001efbe01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000004
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 2, migratetype Unmovable, gfp_mask 0xd20c0(__GFP_IO|__GFP_FS|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 5203, tgid 5203 (udevd), ts 35020479428, free_ts 30283368313
set_page_owner include/linux/page_owner.h:32 [inline]
post_alloc_hook+0x240/0x2a0 mm/page_alloc.c:1851
prep_new_page mm/page_alloc.c:1859 [inline]
get_page_from_freelist+0x2365/0x2440 mm/page_alloc.c:3920
__alloc_frozen_pages_noprof+0x181/0x370 mm/page_alloc.c:5214
alloc_pages_mpol+0x232/0x4a0 mm/mempolicy.c:2418
alloc_slab_page mm/slub.c:3049 [inline]
allocate_slab+0x96/0x3a0 mm/slub.c:3222
new_slab mm/slub.c:3276 [inline]
___slab_alloc+0xe94/0x18a0 mm/slub.c:4646
__slab_alloc+0x65/0x100 mm/slub.c:4765
__slab_alloc_node mm/slub.c:4841 [inline]
slab_alloc_node mm/slub.c:5263 [inline]
__do_kmalloc_node mm/slub.c:5636 [inline]
__kmalloc_node_track_caller_noprof+0x5d0/0x810 mm/slub.c:5746
kmalloc_reserve+0x136/0x290 net/core/skbuff.c:604
__alloc_skb+0x142/0x2d0 net/core/skbuff.c:673
alloc_skb include/linux/skbuff.h:1383 [inline]
alloc_skb_with_frags+0xca/0x890 net/core/skbuff.c:6685
sock_alloc_send_pskb+0x84d/0x980 net/core/sock.c:2987
unix_dgram_sendmsg+0x461/0x1850 net/unix/af_unix.c:2153
sock_sendmsg_nosec net/socket.c:727 [inline]
__sock_sendmsg+0x21c/0x270 net/socket.c:742
sock_write_iter+0x279/0x360 net/socket.c:1195
new_sync_write fs/read_write.c:593 [inline]
vfs_write+0x5c9/0xb30 fs/read_write.c:686
page last free pid 1 tgid 1 stack trace:
reset_page_owner include/linux/page_owner.h:25 [inline]
free_pages_prepare mm/page_alloc.c:1395 [inline]
__free_frozen_pages+0xbc8/0xd30 mm/page_alloc.c:2948
__free_pages mm/page_alloc.c:5333 [inline]
free_contig_range+0x1bd/0x4a0 mm/page_alloc.c:7176
destroy_args+0x69/0x660 mm/debug_vm_pgtable.c:958
debug_vm_pgtable+0x39f/0x3b0 mm/debug_vm_pgtable.c:1345
do_one_initcall+0x236/0x820 init/main.c:1283
do_initcall_level+0x104/0x190 init/main.c:1345
do_initcalls+0x59/0xa0 init/main.c:1361
kernel_init_freeable+0x334/0x4b0 init/main.c:1593
kernel_init+0x1d/0x1d0 init/main.c:1483
ret_from_fork+0x4bc/0x870 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Memory state around the buggy address:
ffff88807befa400: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807befa480: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff88807befa500: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807befa580: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807befa600: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
==================================================================---
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 [email protected].
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 syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
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
syzbot
syzbotsyzbot has bisected this issue to:
syzbot has bisected this issue to:
commit d1e54dd08f163a9021433020d16a8f8f70ddc41c
Author: Fuad Tabba <[email protected]> Date: Tue Jul 29 22:54:40 2025 +0000
KVM: x86: Enable KVM_GUEST_MEMFD for all 64-bit builds
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12a663cd980000 start commit: 43e9ad0c55a3 Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11a663cd980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16a663cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa syz repro: https://syzkaller.appspot.com/x/repro.syz?x=173ecd2f980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14bc2be2580000
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
Sean Christopherson
maintainerQuoted 18 lines · syzbot
syzbot has bisected this issue to:
commit
d1e54dd08f163a9021433020d16a8f8f70ddc41cAuthor: Fuad Tabba <[email protected]> Date: Tue Jul 29 22:54:40 2025 +0000KVM: x86: Enable
KVM_GUEST_MEMFDfor all 64-bit buildsbisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12a663cd980000 start commit: 43e9ad0c55a3 Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11a663cd980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16a663cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa syz repro: https://syzkaller.appspot.com/x/repro.syz?x=173ecd2f980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14bc2be2580000
Quoted 2 lines
Reported-by [email protected]Fixes d1e54dd08f16 ("KVM: x86: Enable KVM_GUEST_MEMFD for all 64-bit builds")
LOL, I was about to say that I suspected that this bug existed since guest_memfd was first added, but that syzbot only now found the issue due to us enabling KVM_GUEST_MEMFD broadly. syzbot beat me to the punch.
#syz test
virt/kvm/guest_memfd.c +30 -13
@@ -708,23 +708,11 @@ int kvm_gmem_bind(struct kvm *kvm, struct kvm_memory_slot *slot,return r; } -void kvm_gmem_unbind (struct kvm_memory_slot *slot) +static void __kvm_gmem_unbind (struct kvm_memory_slot *slot,struct gmem_file *f) {unsigned long start = slot->gmem.pgoff;unsigned long end = start + slot->npages; -struct gmem_file *f; -/* -* Nothing to do if the underlying file was already closed (or is being -* closed right now), kvm_gmem_release() invalidates all bindings. -*/ -CLASS (gmem_get_file, file)(slot); -if (!file) -return ; - - f = file->private_data; - -filemap_invalidate_lock (file->f_mapping);xa_store_range (&f->bindings, start, end -1 ,NULL ,GFP_KERNEL );/*
@@ -732,6 +720,35 @@ void kvm_gmem_unbind(struct kvm_memory_slot *slot)* cannot see this memslot. */ WRITE_ONCE (slot->gmem.file,NULL ); +} + +void kvm_gmem_unbind (struct kvm_memory_slot *slot) +{ +/* +* Nothing to do if the underlying file was _already_ closed, as +* kvm_gmem_release() invalidates and nullifies all bindings. +*/ +if (!slot->gmem.file) +return ; + +CLASS (gmem_get_file, file)(slot); + +/* +* However, if the file is _being_ closed, then the bindings need to be +* removed as kvm_gmem_release() might not run until after the memslot +* is freed. Note, modifying the bindings is safe even though the file +* is dying as kvm_gmem_release() nullifies slot->gmem.file under +* slots_lock, and only puts its reference to KVM after destroying all +* bindings. I.e. reaching this point means kvm_gmem_release() can't +* concurrently destroy the bindings or free the gmem_file. +*/ +if (!file) { +__kvm_gmem_unbind (slot, slot->gmem.file->private_data); +return ; + } + +filemap_invalidate_lock (file->f_mapping); +__kvm_gmem_unbind (slot, file->private_data);filemap_invalidate_unlock (file->f_mapping); }
syzbot
syzbotsyzbot tried to test the proposed patch but the build/boot failed:
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
failed to apply patch:
checking file virt/kvm/guest_memfd.c
Hunk #1 FAILED at 708.
Hunk #2 succeeded at 648 with fuzz 2 (offset -84 lines). 1 out of 2 hunks FAILED
Tested on:
commit: 2e590d67 Merge tag 'devicetree-fixes-for-6.18-2' of gi.. git tree: upstream kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa
compiler:
patch: https://syzkaller.appspot.com/x/patch.diff?x=15343b04580000
Quoted 8 lines · syzbot
syzbot has bisected this issue to:
commit
d1e54dd08f163a9021433020d16a8f8f70ddc41cAuthor: Fuad Tabba <[email protected]> Date: Tue Jul 29 22:54:40 2025 +0000KVM: x86: Enable
KVM_GUEST_MEMFDfor all 64-bit builds
Quoted 9 lines
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12a663cd980000 start commit: 43e9ad0c55a3 Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11a663cd980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16a663cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa syz repro: https://syzkaller.appspot.com/x/repro.syz?x=173ecd2f980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14bc2be2580000
Test Sean's fix.
#syz test
virt/kvm/guest_memfd.c +31 -14
@@ -708,23 +708,11 @@ err:return r; } -void kvm_gmem_unbind (struct kvm_memory_slot *slot) +static void __kvm_gmem_unbind (struct kvm_memory_slot *slot,struct gmem_file *f) {unsigned long start = slot->gmem.pgoff;unsigned long end = start + slot->npages; -struct gmem_file *f; - -/* -* Nothing to do if the underlying file was already closed (or is being -* closed right now), kvm_gmem_release() invalidates all bindings. -*/ -CLASS (gmem_get_file, file)(slot); -if (!file) -return ; - - f = file->private_data; -filemap_invalidate_lock (file->f_mapping);xa_store_range (&f->bindings, start, end -1 ,NULL ,GFP_KERNEL );/*
@@ -732,7 +720,36 @@ void kvm_gmem_unbind(struct kvm_memory_s* cannot see this memslot. */ WRITE_ONCE (slot->gmem.file,NULL ); -filemap_invalidate_unlock (file->f_mapping); +} + +void kvm_gmem_unbind (struct kvm_memory_slot *slot) +{ +/* +* Nothing to do if the underlying file was _already_ closed, as +* kvm_gmem_release() invalidates and nullifies all bindings. +*/ +if (!slot->gmem.file) +return ; + +CLASS (gmem_get_file, file)(slot); + +/* +* However, if the file is _being_ closed, then the bindings need to be +* removed as kvm_gmem_release() might not run until after the memslot +* is freed. Note, modifying the bindings is safe even though the file +* is dying as kvm_gmem_release() nullifies slot->gmem.file under +* slots_lock, and only puts its reference to KVM after destroying all +* bindings. I.e. reaching this point means kvm_gmem_release() can't +* concurrently destroy the bindings or free the gmem_file. +*/ +if (!file) { +__kvm_gmem_unbind (slot, slot->gmem.file->private_data); +return ; + } + +filemap_invalidate_lock (file->f_mapping); +__kvm_gmem_unbind (slot, file->private_data); +filemap_invalidate_unlock (file->f_mapping); }/* Returns a locked folio on success. */
--
syzbot
syzbotsyzbot tried to test the proposed patch but the build/boot failed:
Hello,
syzbot tried to test the proposed patch but the build/boot failed:
failed to apply patch:
checking file virt/kvm/guest_memfd.c
Hunk #1 FAILED at 708.
Hunk #2 FAILED at 732.
2 out of 2 hunks FAILED
Tested on:
commit: d2818517 Merge tag 'block-6.18-20251023' of git://git... git tree: upstream kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa
compiler:
patch: https://syzkaller.appspot.com/x/patch.diff?x=14426e7c580000
Quoted 8 lines · syzbot
syzbot has bisected this issue to:
commit
d1e54dd08f163a9021433020d16a8f8f70ddc41cAuthor: Fuad Tabba <[email protected]> Date: Tue Jul 29 22:54:40 2025 +0000KVM: x86: Enable
KVM_GUEST_MEMFDfor all 64-bit builds
Quoted 9 lines
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12a663cd980000 start commit: 43e9ad0c55a3 Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11a663cd980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16a663cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa syz repro: https://syzkaller.appspot.com/x/repro.syz?x=173ecd2f980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14bc2be2580000
Test Sean's fix.
#syz test linux-next master
virt/kvm/guest_memfd.c +31 -14
@@ -708,23 +708,11 @@ err:return r; } -void kvm_gmem_unbind (struct kvm_memory_slot *slot) +static void __kvm_gmem_unbind (struct kvm_memory_slot *slot,struct gmem_file *f) {unsigned long start = slot->gmem.pgoff;unsigned long end = start + slot->npages; -struct gmem_file *f; - -/* -* Nothing to do if the underlying file was already closed (or is being -* closed right now), kvm_gmem_release() invalidates all bindings. -*/ -CLASS (gmem_get_file, file)(slot); -if (!file) -return ; - - f = file->private_data; -filemap_invalidate_lock (file->f_mapping);xa_store_range (&f->bindings, start, end -1 ,NULL ,GFP_KERNEL );/*
@@ -732,7 +720,36 @@ void kvm_gmem_unbind(struct kvm_memory_s* cannot see this memslot. */ WRITE_ONCE (slot->gmem.file,NULL ); -filemap_invalidate_unlock (file->f_mapping); +} + +void kvm_gmem_unbind (struct kvm_memory_slot *slot) +{ +/* +* Nothing to do if the underlying file was _already_ closed, as +* kvm_gmem_release() invalidates and nullifies all bindings. +*/ +if (!slot->gmem.file) +return ; + +CLASS (gmem_get_file, file)(slot); + +/* +* However, if the file is _being_ closed, then the bindings need to be +* removed as kvm_gmem_release() might not run until after the memslot +* is freed. Note, modifying the bindings is safe even though the file +* is dying as kvm_gmem_release() nullifies slot->gmem.file under +* slots_lock, and only puts its reference to KVM after destroying all +* bindings. I.e. reaching this point means kvm_gmem_release() can't +* concurrently destroy the bindings or free the gmem_file. +*/ +if (!file) { +__kvm_gmem_unbind (slot, slot->gmem.file->private_data); +return ; + } + +filemap_invalidate_lock (file->f_mapping); +__kvm_gmem_unbind (slot, file->private_data); +filemap_invalidate_unlock (file->f_mapping); }/* Returns a locked folio on success. */
--
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue: WARNING in get_data
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
WARNING in get_data
------------[ cut here ]------------ WARNING: kernel/printk/printk_ringbuffer.c:1278 at get_data+0x48a/0x840 kernel/printk/printk_ringbuffer.c:1278, CPU#1: udevd/5199 Modules linked in: CPU: 1 UID: 0 PID: 5199 Comm: udevd Not tainted syzkaller #0 PREEMPT(full) Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/02/2025 RIP: 0010:get_data+0x48a/0x840 kernel/printk/printk_ringbuffer.c:1278 Code: 83 c4 f8 48 b8 00 00 00 00 00 fc ff df 41 0f b6 04 07 84 c0 0f 85 ee 01 00 00 44 89 65 00 49 83 c5 08 eb 13 e8 57 cd 1e 00 90 <0f> 0b 90 eb 05 e8 4c cd 1e 00 45 31 ed 4c 89 e8 48 83 c4 28 5b 41 RSP: 0018:ffffc90000a08560 EFLAGS: 00010006 RAX: ffffffff81a16c59 RBX: 00003fffffffffff RCX: ffff88807e471e40 RDX: 0000000000010000 RSI: 00003fffffffffff RDI: 0000000000000000 RBP: 0000000000000012 R08: 0000000000001005 R09: 0000002047c57766 R10: 0000002047c57766 R11: 0000196a8200002e R12: 0000000000000012 R13: 0000000000000000 R14: ffffc90000a086a8 R15: 1ffffffff1bcaa96 FS: 00007fa682a1a880(0000) GS:ffff888126022000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000001b30c63fff CR3: 000000007e4be000 CR4: 00000000003526f0 Call Trace: <IRQ> copy_data kernel/printk/printk_ringbuffer.c:1857 [inline] prb_read kernel/printk/printk_ringbuffer.c:1966 [inline] _prb_read_valid+0x672/0xa90 kernel/printk/printk_ringbuffer.c:2143 prb_read_valid+0x3c/0x60 kernel/printk/printk_ringbuffer.c:2215 printk_get_next_message+0x15c/0x7b0 kernel/printk/printk.c:2978 console_emit_next_record kernel/printk/printk.c:3065 [inline] console_flush_one_record kernel/printk/printk.c:3197 [inline] console_flush_all+0x4cc/0xb10 kernel/printk/printk.c:3271 __console_flush_and_unlock kernel/printk/printk.c:3301 [inline] console_unlock+0xbb/0x190 kernel/printk/printk.c:3341 wake_up_klogd_work_func+0xa8/0x130 kernel/printk/printk.c:4550 irq_work_single+0xe1/0x240 kernel/irq_work.c:221 irq_work_run_list kernel/irq_work.c:252 [inline] irq_work_tick+0x2c2/0x360 kernel/irq_work.c:277 update_process_times+0x264/0x2f0 kernel/time/timer.c:2476 tick_sched_handle kernel/time/tick-sched.c:276 [inline] tick_nohz_handler+0x39a/0x520 kernel/time/tick-sched.c:297 __run_hrtimer kernel/time/hrtimer.c:1777 [inline] __hrtimer_run_queues+0x4e0/0xc60 kernel/time/hrtimer.c:1841 hrtimer_interrupt+0x45b/0xaa0 kernel/time/hrtimer.c:1903 local_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1041 [inline] __sysvec_apic_timer_interrupt+0x10b/0x410 arch/x86/kernel/apic/apic.c:1058 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1052 [inline] sysvec_apic_timer_interrupt+0xa1/0xc0 arch/x86/kernel/apic/apic.c:1052 </IRQ> <TASK> asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:697 RIP: 0010:__sanitizer_cov_trace_cmp4+0x4/0x90 kernel/kcov.c:288 Code: 89 74 11 18 48 89 44 11 20 e9 48 ca 8b 09 cc 0f 1f 80 00 00 00 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa <48> 8b 04 24 65 48 8b 14 25 08 e0 6f 92 65 8b 0d a8 a4 af 10 81 e1 RSP: 0018:ffffc900030e7d00 EFLAGS: 00000246 RAX: 0000000000000000 RBX: 0000000000000040 RCX: 0000000000000000 RDX: ffff88807e471e40 RSI: 0000000000000040 RDI: 000000000000000c RBP: 000000000000000c R08: 0000000000000003 R09: 0000000000000004 R10: dffffc0000000000 R11: fffff5200061cf90 R12: ffff88807ea4d320 R13: dffffc0000000000 R14: ffff88807ea4d3c0 R15: 0000000000000000 alloc_fd+0x2f3/0x6c0 fs/file.c:595 do_sys_openat2+0xfc/0x1c0 fs/open.c:1435 do_sys_open fs/open.c:1452 [inline] __do_sys_openat fs/open.c:1468 [inline] __se_sys_openat fs/open.c:1463 [inline] __x64_sys_openat+0x138/0x170 fs/open.c:1463 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xfa/0xfa0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7fa6822a7407 Code: 48 89 fa 4c 89 df e8 38 aa 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff RSP: 002b:00007fffd29370d0 EFLAGS: 00000202 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 00007fa682a1a880 RCX: 00007fa6822a7407 RDX: 0000000000080000 RSI: 00007fffd2937250 RDI: ffffffffffffff9c RBP: 0000000000000008 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000202 R12: 00005600f32347f5 R13: 00005600f32347f5 R14: 0000000000000001 R15: 0000000000000000 </TASK> ---------------- Code disassembly (best guess): 0: 89 74 11 18 mov %esi,0x18(%rcx,%rdx,1) 4: 48 89 44 11 20 mov %rax,0x20(%rcx,%rdx,1) 9: e9 48 ca 8b 09 jmp 0x98bca56 e: cc int3 f: 0f 1f 80 00 00 00 00 nopl 0x0(%rax) 16: 90 nop 17: 90 nop 18: 90 nop 19: 90 nop 1a: 90 nop 1b: 90 nop 1c: 90 nop 1d: 90 nop 1e: 90 nop 1f: 90 nop 20: 90 nop 21: 90 nop 22: 90 nop 23: 90 nop 24: 90 nop 25: 90 nop 26: f3 0f 1e fa endbr64 * 2a: 48 8b 04 24 mov (%rsp),%rax <-- trapping instruction 2e: 65 48 8b 14 25 08 e0 mov %gs:0xffffffff926fe008,%rdx 35: 6f 92 37: 65 8b 0d a8 a4 af 10 mov %gs:0x10afa4a8(%rip),%ecx # 0x10afa4e6 3e: 81 .byte 0x81 3f: e1 .byte 0xe1
Tested on:
commit: 72fb0170 Add linux-next specific files for 20251024 git tree: linux-next console output: https://syzkaller.appspot.com/x/log.txt?x=14b2e3cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=bcaf4aad77308158 dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 patch: https://syzkaller.appspot.com/x/patch.diff?x=13d98be2580000
Quoted 8 lines · syzbot
syzbot has bisected this issue to:
commit
d1e54dd08f163a9021433020d16a8f8f70ddc41cAuthor: Fuad Tabba <[email protected]> Date: Tue Jul 29 22:54:40 2025 +0000KVM: x86: Enable
KVM_GUEST_MEMFDfor all 64-bit builds
Quoted 9 lines
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12a663cd980000 start commit: 43e9ad0c55a3 Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11a663cd980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16a663cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa syz repro: https://syzkaller.appspot.com/x/repro.syz?x=173ecd2f980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14bc2be2580000
Test Sean's fix.
#syz test linux-next master
virt/kvm/guest_memfd.c +31 -14
@@ -708,23 +708,11 @@ err:return r; } -void kvm_gmem_unbind (struct kvm_memory_slot *slot) +static void __kvm_gmem_unbind (struct kvm_memory_slot *slot,struct gmem_file *f) {unsigned long start = slot->gmem.pgoff;unsigned long end = start + slot->npages; -struct gmem_file *f; - -/* -* Nothing to do if the underlying file was already closed (or is being -* closed right now), kvm_gmem_release() invalidates all bindings. -*/ -CLASS (gmem_get_file, file)(slot); -if (!file) -return ; - - f = file->private_data; -filemap_invalidate_lock (file->f_mapping);xa_store_range (&f->bindings, start, end -1 ,NULL ,GFP_KERNEL );/*
@@ -732,7 +720,36 @@ void kvm_gmem_unbind(struct kvm_memory_s* cannot see this memslot. */ WRITE_ONCE (slot->gmem.file,NULL ); -filemap_invalidate_unlock (file->f_mapping); +} + +void kvm_gmem_unbind (struct kvm_memory_slot *slot) +{ +/* +* Nothing to do if the underlying file was _already_ closed, as +* kvm_gmem_release() invalidates and nullifies all bindings. +*/ +if (!slot->gmem.file) +return ; + +CLASS (gmem_get_file, file)(slot); + +/* +* However, if the file is _being_ closed, then the bindings need to be +* removed as kvm_gmem_release() might not run until after the memslot +* is freed. Note, modifying the bindings is safe even though the file +* is dying as kvm_gmem_release() nullifies slot->gmem.file under +* slots_lock, and only puts its reference to KVM after destroying all +* bindings. I.e. reaching this point means kvm_gmem_release() can't +* concurrently destroy the bindings or free the gmem_file. +*/ +if (!file) { +__kvm_gmem_unbind (slot, slot->gmem.file->private_data); +return ; + } + +filemap_invalidate_lock (file->f_mapping); +__kvm_gmem_unbind (slot, file->private_data); +filemap_invalidate_unlock (file->f_mapping); }/* Returns a locked folio on success. */
kernel/printk/printk_ringbuffer.c +1 -1
@@ -1286,7 +1286,7 @@ static const char *get_data(struct prb_d }/* A valid data block will always have at least an ID. */ -if (WARN_ON_ONCE (*data_size <sizeof (db->id))) +if (*data_size <sizeof (db->id))return NULL ;/* Subtract block ID space from size to reflect data size. */
--
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Tested on:
commit: 72fb0170 Add linux-next specific files for 20251024 git tree: linux-next console output: https://syzkaller.appspot.com/x/log.txt?x=15da53e2580000 kernel config: https://syzkaller.appspot.com/x/.config?x=bcaf4aad77308158 dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa compiler: Debian clang version 20.1.8 (++20250708063551+0c9f909b7976-1~exp1~20250708183702.136), Debian LLD 20.1.8 patch: https://syzkaller.appspot.com/x/patch.diff?x=161c4258580000
Note: testing is done by a robot and is best-effort only.
Sean Christopherson
maintainerQuoted 19 lines · Hillf Danton
Quoted 8 lines · syzbot
syzbot has bisected this issue to:
commit
d1e54dd08f163a9021433020d16a8f8f70ddc41cAuthor: Fuad Tabba <[email protected]> Date: Tue Jul 29 22:54:40 2025 +0000KVM: x86: Enable
KVM_GUEST_MEMFDfor all 64-bit buildsQuoted 9 lines
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=12a663cd980000 start commit: 43e9ad0c55a3 Merge tag 'scsi-fixes' of git://git.kernel.or.. git tree: upstream final oops: https://syzkaller.appspot.com/x/report.txt?x=11a663cd980000 console output: https://syzkaller.appspot.com/x/log.txt?x=16a663cd980000 kernel config: https://syzkaller.appspot.com/x/.config?x=67b63a24f3c26fca dashboard link: https://syzkaller.appspot.com/bug?extid=2479e53d0db9b32ae2aa syz repro: https://syzkaller.appspot.com/x/repro.syz?x=173ecd2f980000 C reproducer: https://syzkaller.appspot.com/x/repro.c?x=14bc2be2580000
Quoted 3 lines
Test Sean's fix.
#syz test linux-next master
Oh, nice. Thanks Hillf!