{"id":"CVE-2026-99336","state":"PUBLISHED","title":"KVM: guest_memfd: take the invalidate lock when unbinding a dying file","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nKVM: guest_memfd: take the invalidate lock when unbinding a dying file\n\nkvm_gmem_unbind() takes mapping->invalidate_lock only if the\nget_file_active() succeeds. When the guest_memfd file is dying, its\nreference count is already zero so get_file_active fails and the binding\nis removed without holding the invalidate lock.\n\nkvm_gmem_invalidate_{start,end}() checks f->bindings independently to\ndecide whether to begin or end KVM MMU invalidation. So, the bindings\nmust therefore remain stable between the two calls. Otherwise, unbind\ncan remove a binding after start increments mmu_invalidate_in_progress,\nbut before end finds the binding and decrements it.\nExample, unbind race with memory failure:\n\n  CPU 0: memory failure               CPU 1: memslot delete\n  ----------------------------------  ---------------------------\n                                      (guest_memfd file is dying)\n  kvm_gmem_error_folio()\n    kvm_gmem_invalidate_start()\n      finds binding\n      mmu_invalidate_in_progress++\n                                      kvm_gmem_unbind()\n                                        get_file_active() fails\n                                        removes binding\n    kvm_gmem_invalidate_end()\n      no binding found\n      counter stays elevated\n\nmmu_invalidate_retry() then returns 1 forever, so guest page faults\nretry without ever installing a mapping and the guest hangs.\n\nRemove the distinction between live and dying files in the unbind path.\nAlways use slot->gmem.file and take the invalidate lock when it's non-NULL.\nNormal unbind callers hold slots_lock, which prevents release from clearing\nthe pointer or freeing the file state until unbind completes. Final VM\nteardown can only see a NULL pointer because guest_memfd pins the KVM until\nrelease has cleared all bindings.","publishedAt":"2026-11-19T14:21:42.304Z","updatedAt":"2026-11-22T11:07:43.269Z","severity":{"score":7,"label":"High","version":"3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"Linux"},"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"a8ac2bd0f98e1a230f1eb3260fa552bf2ef1753b","status":"affected","lessThan":"4ae4316682cdc78d8f5a856ab0712a8281f211ca","versionType":"git"},{"version":"ae431059e75d36170a5ae6b44cc4d06d43613215","status":"affected","lessThan":"3af94f4e3526efdf52d84d7ba8d9fb8e8facb93a","versionType":"git"},{"version":"ae431059e75d36170a5ae6b44cc4d06d43613215","status":"affected","lessThan":"024be82ac4c4df650cc6daca6d7db79daee95470","versionType":"git"},{"version":"ae431059e75d36170a5ae6b44cc4d06d43613215","status":"affected","lessThan":"0ee2c883b62deb74d8c43007e8049dc006d3a2fb","versionType":"git"},{"version":"393893693a523e053f84d69320d090b93503f79f","status":"affected","versionType":"git"},{"version":"6.12.59","status":"affected","lessThan":"6.12.118","versionType":"semver"},{"version":"6.17.9","status":"affected","lessThan":"6.18","versionType":"semver"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["virt/kvm/guest_memfd.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.18","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.18","versionType":"semver"},{"version":"6.12.118","status":"unaffected","lessThanOrEqual":"6.12.*","versionType":"semver"},{"version":"6.18.64","status":"unaffected","lessThanOrEqual":"6.18.*","versionType":"semver"},{"version":"7.3.2","status":"unaffected","lessThanOrEqual":"7.3.*","versionType":"semver"},{"version":"7.4-rc1","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["virt/kvm/guest_memfd.c"]}],"references":["https://git.kernel.org/stable/c/4ae4316682cdc78d8f5a856ab0712a8281f211ca","https://git.kernel.org/stable/c/3af94f4e3526efdf52d84d7ba8d9fb8e8facb93a","https://git.kernel.org/stable/c/024be82ac4c4df650cc6daca6d7db79daee95470","https://git.kernel.org/stable/c/0ee2c883b62deb74d8c43007e8049dc006d3a2fb"],"weaknesses":[],"ingestedAt":"2026-11-22T11:18:06.032Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2026/99xxx/CVE-2026-99336.json","commit":"247cc9beefd85903834df0592e88a44f4d599223","baselineCommit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2026-99336","state":"PUBLISHED","datePublished":"2026-11-19T14:21:42.304Z","dateUpdated":"2026-11-22T11:07:43.269Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2026-09-25T10:25:14.408Z"},"containers":{"cna":{"title":"KVM: guest_memfd: take the invalidate lock when unbinding a dying file","descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nKVM: guest_memfd: take the invalidate lock when unbinding a dying file\n\nkvm_gmem_unbind() takes mapping->invalidate_lock only if the\nget_file_active() succeeds. When the guest_memfd file is dying, its\nreference count is already zero so get_file_active fails and the binding\nis removed without holding the invalidate lock.\n\nkvm_gmem_invalidate_{start,end}() checks f->bindings independently to\ndecide whether to begin or end KVM MMU invalidation. So, the bindings\nmust therefore remain stable between the two calls. Otherwise, unbind\ncan remove a binding after start increments mmu_invalidate_in_progress,\nbut before end finds the binding and decrements it.\nExample, unbind race with memory failure:\n\n  CPU 0: memory failure               CPU 1: memslot delete\n  ----------------------------------  ---------------------------\n                                      (guest_memfd file is dying)\n  kvm_gmem_error_folio()\n    kvm_gmem_invalidate_start()\n      finds binding\n      mmu_invalidate_in_progress++\n                                      kvm_gmem_unbind()\n                                        get_file_active() fails\n                                        removes binding\n    kvm_gmem_invalidate_end()\n      no binding found\n      counter stays elevated\n\nmmu_invalidate_retry() then returns 1 forever, so guest page faults\nretry without ever installing a mapping and the guest hangs.\n\nRemove the distinction between live and dying files in the unbind path.\nAlways use slot->gmem.file and take the invalidate lock when it's non-NULL.\nNormal unbind callers hold slots_lock, which prevents release from clearing\nthe pointer or freeing the file state until unbind completes. Final VM\nteardown can only see a NULL pointer because guest_memfd pins the KVM until\nrelease has cleared all bindings."}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"a8ac2bd0f98e1a230f1eb3260fa552bf2ef1753b","status":"affected","lessThan":"4ae4316682cdc78d8f5a856ab0712a8281f211ca","versionType":"git"},{"version":"ae431059e75d36170a5ae6b44cc4d06d43613215","status":"affected","lessThan":"3af94f4e3526efdf52d84d7ba8d9fb8e8facb93a","versionType":"git"},{"version":"ae431059e75d36170a5ae6b44cc4d06d43613215","status":"affected","lessThan":"024be82ac4c4df650cc6daca6d7db79daee95470","versionType":"git"},{"version":"ae431059e75d36170a5ae6b44cc4d06d43613215","status":"affected","lessThan":"0ee2c883b62deb74d8c43007e8049dc006d3a2fb","versionType":"git"},{"version":"393893693a523e053f84d69320d090b93503f79f","status":"affected","versionType":"git"},{"version":"6.12.59","status":"affected","lessThan":"6.12.118","versionType":"semver"},{"version":"6.17.9","status":"affected","lessThan":"6.18","versionType":"semver"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["virt/kvm/guest_memfd.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.18","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.18","versionType":"semver"},{"version":"6.12.118","status":"unaffected","lessThanOrEqual":"6.12.*","versionType":"semver"},{"version":"6.18.64","status":"unaffected","lessThanOrEqual":"6.18.*","versionType":"semver"},{"version":"7.3.2","status":"unaffected","lessThanOrEqual":"7.3.*","versionType":"semver"},{"version":"7.4-rc1","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["virt/kvm/guest_memfd.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/4ae4316682cdc78d8f5a856ab0712a8281f211ca"},{"url":"https://git.kernel.org/stable/c/3af94f4e3526efdf52d84d7ba8d9fb8e8facb93a"},{"url":"https://git.kernel.org/stable/c/024be82ac4c4df650cc6daca6d7db79daee95470"},{"url":"https://git.kernel.org/stable/c/0ee2c883b62deb74d8c43007e8049dc006d3a2fb"}],"metrics":[{"cvssV3_1":{"version":"3.1","vectorString":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:H/I:H/A:H","baseScore":7,"baseSeverity":"HIGH"},"scenarios":[{"lang":"en","value":"AV:L - kvm_gmem_unbind() runs only from kvm_free_memslot() when KVM_SET_USER_MEMORY_REGION deletes a slot (kvm_vm_ioctl -> kvm_vm_ioctl_set_memory_region -> kvm_set_memslot -> kvm_commit_memory_region). The racer, kvm_gmem_error_folio(), is entered from memory_failure(), not from a remote protocol message.\nAC:H - The invalidate lock is skipped only after get_file_active() fails on a dying guest_memfd, and the bad window is kvm_gmem_invalidate_start() through kvm_gmem_invalidate_end() in kvm_gmem_error_folio(). That callback runs only from memory_failure() on an ECC/MCE the attacker cannot schedule.\nPR:L - kvm_vm_ioctl() accepts KVM_CREATE_GUEST_MEMFD and KVM_SET_USER_MEMORY_REGION after checking only that kvm->mm equals current->mm. A user who can open /dev/kvm can create the guest_memfd, close it, and delete the slot; CAP_SYS_ADMIN is not checked.\nUI:N - The process that owns the VM fd closes the guest_memfd and issues the memslot deletion itself. No other user has to mount, open, or approve anything.\nS:U - The stuck kvm->mmu_invalidate_in_progress counter and the freed kvm_memory_slot belong to the host KVM instance the caller already controls via the VM fd. The guest cannot invoke kvm_gmem_unbind(), so this does not cross a guest/host boundary.\nC:H - kvm_free_memslot() kfree()s the slot as soon as the unlocked kvm_gmem_unbind() returns, while kvm_gmem_invalidate_start() can still be in kvm_unmap_gfn_range() reading slot->as_id and, once shadow roots exist, gfn_to_rmap() on slot->arch.rmap[]. Reclaiming that object exposes those reads.\nI:H - With shadow rmaps allocated, gfn_to_rmap() indexes slot->arch.rmap[] and kvm_zap_rmap() writes through that pointer while kvm_unmap_gfn_range() still holds the slot kvm_free_memslot() has kfree'd. Reclaiming the slab is a kernel write primitive.\nA:H - If kvm_gmem_invalidate_end() no longer finds the binding, mmu_invalidate_in_progress stays non-zero and mmu_invalidate_retry() returns 1 forever, so faults in gmem_abort() re-enter the guest with no mapping and the vCPU livelocks. The slot use-after-free can also oops the host."}]}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-11-22T11:07:43.269Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.12.59","versionEndExcluding":"6.12.118"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.18","versionEndExcluding":"6.18.64"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.18","versionEndExcluding":"7.3.2"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.18","versionEndExcluding":"7.4-rc1"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.17.9"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}