Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3964994b authored by Eric Sesterhenn / Snakebyte's avatar Eric Sesterhenn / Snakebyte Committed by Avi Kivity
Browse files

KVM: Fix overflow bug in overflow detection code



The expression

   sp - 6 < sp

where sp is a u16 is undefined in C since 'sp - 6' is promoted to int,
and signed overflow is undefined in C.  gcc 4.2 actually warns about it.
Replace with a simpler test.

Signed-off-by: default avatarEric Sesterhenn <snakebyte@gmx.de>
Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent 5008fdf5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -1182,7 +1182,7 @@ static void inject_rmode_irq(struct kvm_vcpu *vcpu, int irq)
	u16 sp =  vmcs_readl(GUEST_RSP);
	u16 sp =  vmcs_readl(GUEST_RSP);
	u32 ss_limit = vmcs_read32(GUEST_SS_LIMIT);
	u32 ss_limit = vmcs_read32(GUEST_SS_LIMIT);


	if (sp > ss_limit || sp - 6 > sp) {
	if (sp > ss_limit || sp < 6 ) {
		vcpu_printf(vcpu, "%s: #SS, rsp 0x%lx ss 0x%lx limit 0x%x\n",
		vcpu_printf(vcpu, "%s: #SS, rsp 0x%lx ss 0x%lx limit 0x%x\n",
			    __FUNCTION__,
			    __FUNCTION__,
			    vmcs_readl(GUEST_RSP),
			    vmcs_readl(GUEST_RSP),