Commit 0c4762e
KVM: arm64: nv: Avoid NV stage-2 code when NV is not supported
The NV stage-2 manipulation functions kvm_nested_s2_unmap(),
kvm_nested_s2_wp(), and others, are being called for any stage-2
manipulation regardless of whether nested virtualization is supported or
enabled for the VM.
For protected KVM (pKVM), `struct kvm_pgtable` uses the
`pkvm_mappings` member of the union. This member aliases `ia_bits`,
which is used by the non-protected NV code paths. Attempting to
read `pgt->ia_bits` in these functions results in treating
protected mapping pointers or state values as bit-shift amounts.
This triggers a UBSAN shift-out-of-bounds error:
UBSAN: shift-out-of-bounds in arch/arm64/kvm/nested.c:1127:34
shift exponent 174565952 is too large for 64-bit type 'unsigned long'
Call trace:
__ubsan_handle_shift_out_of_bounds+0x28c/0x2c0
kvm_nested_s2_unmap+0x228/0x248
kvm_arch_flush_shadow_memslot+0x98/0xc0
kvm_set_memslot+0x248/0xce0
Since pKVM and NV are mutually exclusive, prevent entry into these
NV handling functions if the VM has not allocated any nested MMUs
(i.e., `kvm->arch.nested_mmus_size` is 0).
Fixes: 7270cc9 ("KVM: arm64: nv: Handle VNCR_EL2 invalidation from MMU notifiers")
Suggested-by: Marc Zyngier <maz@kernel.org>
Signed-off-by: Fuad Tabba <tabba@google.com>
Link: https://patch.msgid.link/20260202152310.113467-1-tabba@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>1 parent 82a32ea commit 0c4762e
1 file changed
+12
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1101 | 1101 | | |
1102 | 1102 | | |
1103 | 1103 | | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1104 | 1107 | | |
1105 | 1108 | | |
1106 | 1109 | | |
| |||
1117 | 1120 | | |
1118 | 1121 | | |
1119 | 1122 | | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
1120 | 1126 | | |
1121 | 1127 | | |
1122 | 1128 | | |
| |||
1133 | 1139 | | |
1134 | 1140 | | |
1135 | 1141 | | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
1136 | 1145 | | |
1137 | 1146 | | |
1138 | 1147 | | |
| |||
1145 | 1154 | | |
1146 | 1155 | | |
1147 | 1156 | | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
1148 | 1160 | | |
1149 | 1161 | | |
1150 | 1162 | | |
| |||
0 commit comments