* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-24 6:15 ` syzbot
@ 2025-10-24 19:14 ` Sean Christopherson
2025-10-24 20:10 ` syzbot
2025-10-24 23:24 ` Hillf Danton
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Sean Christopherson @ 2025-10-24 19:14 UTC (permalink / raw)
To: syzbot
Cc: david, kvm, linux-kernel, pbonzini, syzkaller-bugs, tabba,
xiaoyao.li
On Thu, Oct 23, 2025, syzbot wrote:
> syzbot has bisected this issue to:
>
> commit d1e54dd08f163a9021433020d16a8f8f70ddc41c
> Author: Fuad Tabba <tabba@google.com>
> 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
>
> Reported-by: syzbot+2479e53d0db9b32ae2aa@syzkaller.appspotmail.com
> 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
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 427c0acee9d7..3741ea23e330 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -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);
}
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-24 6:15 ` syzbot
2025-10-24 19:14 ` Sean Christopherson
@ 2025-10-24 23:24 ` Hillf Danton
2025-10-24 23:27 ` syzbot
2025-10-24 23:43 ` Hillf Danton
2025-10-25 1:58 ` Hillf Danton
3 siblings, 1 reply; 11+ messages in thread
From: Hillf Danton @ 2025-10-24 23:24 UTC (permalink / raw)
To: syzbot
Cc: Sean Christopherson, kvm, linux-kernel, syzkaller-bugs, tabba,
xiaoyao.li
On Thu, Oct 23, 2025, syzbot wrote:
> syzbot has bisected this issue to:
>
> commit d1e54dd08f163a9021433020d16a8f8f70ddc41c
> Author: Fuad Tabba <tabba@google.com>
> 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
Test Sean's fix.
#syz test
--- x/virt/kvm/guest_memfd.c
+++ y/virt/kvm/guest_memfd.c
@@ -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. */
--
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-24 6:15 ` syzbot
2025-10-24 19:14 ` Sean Christopherson
2025-10-24 23:24 ` Hillf Danton
@ 2025-10-24 23:43 ` Hillf Danton
2025-10-25 0:12 ` syzbot
2025-10-25 1:58 ` Hillf Danton
3 siblings, 1 reply; 11+ messages in thread
From: Hillf Danton @ 2025-10-24 23:43 UTC (permalink / raw)
To: syzbot
Cc: Sean Christopherson, kvm, linux-kernel, syzkaller-bugs, tabba,
xiaoyao.li
On Thu, Oct 23, 2025, syzbot wrote:
> syzbot has bisected this issue to:
>
> commit d1e54dd08f163a9021433020d16a8f8f70ddc41c
> Author: Fuad Tabba <tabba@google.com>
> 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
Test Sean's fix.
#syz test linux-next master
--- x/virt/kvm/guest_memfd.c
+++ y/virt/kvm/guest_memfd.c
@@ -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. */
--
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-24 23:43 ` Hillf Danton
@ 2025-10-25 0:12 ` syzbot
0 siblings, 0 replies; 11+ messages in thread
From: syzbot @ 2025-10-25 0:12 UTC (permalink / raw)
To: hdanton, kvm, linux-kernel, seanjc, syzkaller-bugs, tabba,
xiaoyao.li
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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-24 6:15 ` syzbot
` (2 preceding siblings ...)
2025-10-24 23:43 ` Hillf Danton
@ 2025-10-25 1:58 ` Hillf Danton
2025-10-25 3:42 ` syzbot
2025-10-27 14:41 ` Sean Christopherson
3 siblings, 2 replies; 11+ messages in thread
From: Hillf Danton @ 2025-10-25 1:58 UTC (permalink / raw)
To: syzbot
Cc: Sean Christopherson, kvm, linux-kernel, syzkaller-bugs, tabba,
xiaoyao.li
On Thu, Oct 23, 2025, syzbot wrote:
> syzbot has bisected this issue to:
>
> commit d1e54dd08f163a9021433020d16a8f8f70ddc41c
> Author: Fuad Tabba <tabba@google.com>
> 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
Test Sean's fix.
#syz test linux-next master
--- x/virt/kvm/guest_memfd.c
+++ y/virt/kvm/guest_memfd.c
@@ -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. */
--- x/kernel/printk/printk_ringbuffer.c
+++ y/kernel/printk/printk_ringbuffer.c
@@ -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. */
--
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-25 1:58 ` Hillf Danton
@ 2025-10-25 3:42 ` syzbot
2025-10-27 14:41 ` Sean Christopherson
1 sibling, 0 replies; 11+ messages in thread
From: syzbot @ 2025-10-25 3:42 UTC (permalink / raw)
To: hdanton, kvm, linux-kernel, seanjc, syzkaller-bugs, tabba,
xiaoyao.li
Hello,
syzbot has tested the proposed patch and the reproducer did not trigger any issue:
Reported-by: syzbot+2479e53d0db9b32ae2aa@syzkaller.appspotmail.com
Tested-by: syzbot+2479e53d0db9b32ae2aa@syzkaller.appspotmail.com
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.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [syzbot] [kvm?] KASAN: slab-use-after-free Write in kvm_gmem_release
2025-10-25 1:58 ` Hillf Danton
2025-10-25 3:42 ` syzbot
@ 2025-10-27 14:41 ` Sean Christopherson
1 sibling, 0 replies; 11+ messages in thread
From: Sean Christopherson @ 2025-10-27 14:41 UTC (permalink / raw)
To: Hillf Danton; +Cc: syzbot, kvm, linux-kernel, syzkaller-bugs, tabba, xiaoyao.li
On Sat, Oct 25, 2025, Hillf Danton wrote:
> On Thu, Oct 23, 2025, syzbot wrote:
> > syzbot has bisected this issue to:
> >
> > commit d1e54dd08f163a9021433020d16a8f8f70ddc41c
> > Author: Fuad Tabba <tabba@google.com>
> > 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
>
> Test Sean's fix.
>
> #syz test linux-next master
Oh, nice. Thanks Hillf!
^ permalink raw reply [flat|nested] 11+ messages in thread