CVE-2026-99336: KVM: guest_memfd: take the invalidate lock when unbinding a dying file
In the Linux kernel, the following vulnerability has been resolved:
KVM: guestmemfd: take the invalidate lock when unbinding a dying file
kvmgmemunbind() takes mapping->invalidatelock only if the getfileactive() succeeds. When the guestmemfd file is dying, its reference count is already zero so getfileactive fails and the binding is removed without holding the invalidate lock.
kvmgmeminvalidate{start,end}() checks f->bindings independently to decide whether to begin or end KVM MMU invalidation. So, the bindings must therefore remain stable between the two calls. Otherwise, unbind can remove a binding after start increments mmuinvalidateinprogress, but before end finds the binding and decrements it. Example, unbind race with memory failure:
CPU 0: memory failure CPU 1: memslot delete ---------------------------------- --------------------------- (guestmemfd file is dying) kvmgmemerrorfolio() kvmgmeminvalidatestart() finds binding mmuinvalidateinprogress++ kvmgmemunbind() getfileactive() fails removes binding kvmgmeminvalidateend() no binding found counter stays elevated
mmuinvalidateretry() then returns 1 forever, so guest page faults retry without ever installing a mapping and the guest hangs.
Remove the distinction between live and dying files in the unbind path. Always use slot->gmem.file and take the invalidate lock when it's non-NULL. Normal unbind callers hold slotslock, which prevents release from clearing the pointer or freeing the file state until unbind completes. Final VM teardown can only see a NULL pointer because guestmemfd pins the KVM until release has cleared all bindings.