Skip to content

Commit 696db30

Browse files
Maxim Levitskybonzini
authored andcommitted
KVM: x86: smm: number of GPRs in the SMRAM image depends on the image format
On 64 bit host, if the guest doesn't have X86_FEATURE_LM, KVM will access 16 gprs to 32-bit smram image, causing out-ouf-bound ram access. On 32 bit host, the rsm_load_state_64/enter_smm_save_state_64 is compiled out, thus access overflow can't happen. Fixes: b443183 ("KVM: x86: Reduce the number of emulator GPRs to '8' for 32-bit KVM") Signed-off-by: Maxim Levitsky <[email protected]> Reviewed-by: Sean Christopherson <[email protected]> Message-Id: <[email protected]> Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent ad8f9e6 commit 696db30

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/x86/kvm/emulate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,7 +2461,7 @@ static int rsm_load_state_32(struct x86_emulate_ctxt *ctxt,
24612461
ctxt->eflags = GET_SMSTATE(u32, smstate, 0x7ff4) | X86_EFLAGS_FIXED;
24622462
ctxt->_eip = GET_SMSTATE(u32, smstate, 0x7ff0);
24632463

2464-
for (i = 0; i < NR_EMULATOR_GPRS; i++)
2464+
for (i = 0; i < 8; i++)
24652465
*reg_write(ctxt, i) = GET_SMSTATE(u32, smstate, 0x7fd0 + i * 4);
24662466

24672467
val = GET_SMSTATE(u32, smstate, 0x7fcc);
@@ -2518,7 +2518,7 @@ static int rsm_load_state_64(struct x86_emulate_ctxt *ctxt,
25182518
u16 selector;
25192519
int i, r;
25202520

2521-
for (i = 0; i < NR_EMULATOR_GPRS; i++)
2521+
for (i = 0; i < 16; i++)
25222522
*reg_write(ctxt, i) = GET_SMSTATE(u64, smstate, 0x7ff8 - i * 8);
25232523

25242524
ctxt->_eip = GET_SMSTATE(u64, smstate, 0x7f78);

0 commit comments

Comments
 (0)