+PAGEMAP_SCAN folks On Wed, Dec 13, 2023, syzbot wrote: > Hello, > > syzbot found the following issue on: > > HEAD commit: f2e8a57ee903 Merge tag 'scsi-fixes' of git://git.kernel.or.. > git tree: upstream > console output: https://syzkaller.appspot.com/x/log.txt?x=14fdc732e80000 > kernel config: https://syzkaller.appspot.com/x/.config?x=e56083f7dbe162c2 > dashboard link: https://syzkaller.appspot.com/bug?extid=81227d2bd69e9dedb802 > compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=129d09cae80000 > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=10b8afeee80000 > > Downloadable assets: > disk image: https://storage.googleapis.com/syzbot-assets/7b75e59fc59d/disk-f2e8a57e.raw.xz > vmlinux: https://storage.googleapis.com/syzbot-assets/f853580d61be/vmlinux-f2e8a57e.xz > kernel image: https://storage.googleapis.com/syzbot-assets/8c893ce02e2c/bzImage-f2e8a57e.xz > > Bisection is inconclusive: the first bad commit could be any of: > > d61ea1cb0095 userfaultfd: UFFD_FEATURE_WP_ASYNC > 52526ca7fdb9 fs/proc/task_mmu: implement IOCTL to get and optionally clear info about PTEs PAGEMAP_SCAN is indeed to blame, do_pagemap_scan() invokes mmu_notifiers without holding mmap_lock. This allows KVM to attach its mmu_notifier between start() and end(), which causes mn_active_invalidate_count to underflow. Note, the actual WARN from KVM fires after the underflow; I'll send a patch to further harden KVM. Ideally this would be fixed before the final v6.7 release, as it would be trivial for this to cause deadlock in KVM. The only reason the repro doesn't cause deadlock is because it's not creating memslots in KVM, i.e. KVM doesn't truly consume the corrupted mn_active_invalidate_count. Side topic, it would be wonderful if we could figure out a semi-efficient way to add lockdep assertions in the mmu_notifier helpers to assert that at least one of the locks acquired by mm_take_all_locks() is held. Relying on KVM's paranoia to detect these types of bugs is not a good strategy.