Commit 51e2c75
committed
KVM: x86: Fix shadow paging use-after-free due to unexpected GFN
jira VULN-186742
cve CVE-2026-46113
commit-author Sean Christopherson <seanjc@google.com>
commit -
commit-source-sha 0cb2af2ea66ad95873455d8a1d0f6f4e13fef645
commit-source https://lore.kernel.org/all/20260626112634.1778506-1-pbonzini@redhat.com/
upstream-diff |
This is a HAND-PORT, not a cherry-pick. Upstream commit
0cb2af2 fixes kvm_mmu_get_child_sp() by adding a
spte_to_child_sp(*sptep)->gfn == gfn check to its -EEXIST reuse
guard. That function (and spte_to_child_sp/kvm_mmu_child_role,
the whole get_child_sp/get_shadow_page split) does NOT exist on
this 4.18-based tree, which predates the ~6.2 KVM MMU refactor and
still uses kvm_mmu_get_page() + link_shadow_page().
On this tree the interior-SPTE reuse happens in the fault-path
walkers __direct_map() and FNAME(fetch): after drop_large_spte(),
a present non-large SPTE is reused as-is (skipping the
kvm_mmu_get_page() alloc path that would validate gfn), with no
re-check that the referenced child shadow page still maps the
expected gfn. The equivalent guard is therefore applied at each of
the three reuse sites via a shared helper kvm_mmu_child_sp_matches();
on mismatch the stale child SPTE is zapped (mmu_page_zap_pte + remote
flush) so the correct child is (re)allocated. kvm_mmu_child_role()
factors out kvm_mmu_get_page()'s role derivation so the guard and the
allocator cannot drift. Functionally equivalent to upstream.
Commit 0cb2af2 ("KVM: x86: Fix shadow paging use-after-free due to
unexpected GFN") fixes a shadow paging mismatch between the stored and
computed GFNs. The bug can be triggered by changing a PDE mapping from
outside the guest and then deleting a memslot: rmap_remove() misses
entries whose leaf SPTE gfn does not match the gfn of the struct
kvm_mmu_page. The freed shadow page's rmap entry survives, and later
walks of that gfn (dirty logging, MMU notifier invalidation, ...)
dereference an sptep in the freed page, causing the use-after-free.
Fixes: 2032a93 ("KVM: MMU: Don't allocate gfns page for direct mmu pages")
Reported-by: Hyunwoo Kim <imv4bel@gmail.com>
Signed-off-by: Shreeya Patel <spatel@ciq.com>1 parent cbbe7c6 commit 51e2c75
2 files changed
Lines changed: 109 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
| |||
2076 | 2078 | | |
2077 | 2079 | | |
2078 | 2080 | | |
2079 | | - | |
2080 | | - | |
2081 | | - | |
2082 | | - | |
2083 | | - | |
2084 | | - | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
2085 | 2090 | | |
2086 | 2091 | | |
2087 | 2092 | | |
2088 | | - | |
2089 | 2093 | | |
2090 | | - | |
2091 | | - | |
2092 | | - | |
2093 | 2094 | | |
2094 | 2095 | | |
2095 | 2096 | | |
| |||
2103 | 2104 | | |
2104 | 2105 | | |
2105 | 2106 | | |
| 2107 | + | |
| 2108 | + | |
| 2109 | + | |
| 2110 | + | |
| 2111 | + | |
| 2112 | + | |
| 2113 | + | |
| 2114 | + | |
| 2115 | + | |
| 2116 | + | |
| 2117 | + | |
| 2118 | + | |
| 2119 | + | |
| 2120 | + | |
| 2121 | + | |
| 2122 | + | |
| 2123 | + | |
| 2124 | + | |
| 2125 | + | |
| 2126 | + | |
| 2127 | + | |
| 2128 | + | |
| 2129 | + | |
| 2130 | + | |
| 2131 | + | |
| 2132 | + | |
| 2133 | + | |
| 2134 | + | |
| 2135 | + | |
| 2136 | + | |
| 2137 | + | |
| 2138 | + | |
| 2139 | + | |
| 2140 | + | |
| 2141 | + | |
| 2142 | + | |
| 2143 | + | |
| 2144 | + | |
| 2145 | + | |
| 2146 | + | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
| 2151 | + | |
| 2152 | + | |
| 2153 | + | |
| 2154 | + | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
| 2159 | + | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
2106 | 2168 | | |
2107 | 2169 | | |
2108 | 2170 | | |
| |||
2998 | 3060 | | |
2999 | 3061 | | |
3000 | 3062 | | |
| 3063 | + | |
| 3064 | + | |
| 3065 | + | |
| 3066 | + | |
| 3067 | + | |
| 3068 | + | |
| 3069 | + | |
| 3070 | + | |
| 3071 | + | |
| 3072 | + | |
| 3073 | + | |
| 3074 | + | |
3001 | 3075 | | |
3002 | 3076 | | |
3003 | 3077 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
661 | 661 | | |
662 | 662 | | |
663 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
664 | 678 | | |
665 | 679 | | |
666 | | - | |
667 | | - | |
668 | 680 | | |
669 | 681 | | |
670 | 682 | | |
| |||
723 | 735 | | |
724 | 736 | | |
725 | 737 | | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
726 | 749 | | |
727 | 750 | | |
728 | 751 | | |
| |||
0 commit comments