Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3721667pxb; Mon, 24 Jan 2022 16:18:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsfWwQV0S+o0+lmaHg1DTEzb/H49QeNKqtRa0pNImk9xeDOSqjLbE+6IRbZQgg//fxDchU X-Received: by 2002:a05:6a00:1a4b:b0:4ca:a64b:434d with SMTP id h11-20020a056a001a4b00b004caa64b434dmr2056268pfv.32.1643069935419; Mon, 24 Jan 2022 16:18:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069935; cv=none; d=google.com; s=arc-20160816; b=B1brtoXunZSm29y51OJihA0+Za2O+ZUQafhlLsk40hGwwxCdcxYVXMi4EtLTl39KgJ 0gvxBlRB+i9jED/eUGLwoodIwXltdkxLpxZ2Qzmb8JQck94/LGhrDWn9XgGE7ZkRAq97 Nk5t+NnUSTYt5ScYDCOVKPwP5iDMbDyc2eP2DCTPDnPkIgqQsjXdLVXQYRwJmV/QPOLD 7ufEGNbb4V50timTVtuulAA9+rO47jtIeMceHBfJlxjhzo9N1p1aFnkjJTEh9Fyj6fz0 g/Ts/QeXDyG1oKANGqD/Ro+EjdyMjvL26CmdMjbVO1HGd9tHihFWd7Ai8AHbbgh6VR/0 iwkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Ryee6ktq1rbiqc6FqEbFzhVOFpQ7RTZ+qbQxmzwPV94=; b=npmreWQdCf4YjZ7SK+RC4kJCP04lIjufCbEfK3IpVyZzaujETgEcoyPrtReNF9rYze GQ6aXGUNaWbxKe20tn8RtHdQ37e8JBAh0I4QdeOViD/beZ9/yjQ1HqowE3zyawIecJ+o 9Kq69+FO537treM8NPI1ncaNEtX0ZhcJ3dMcr+L931runrlcFEeJwv48A3rI4a6//yXa KjU3Ke4mCcXjlg9uk5zIpQVaL2PYfoHTig6ccEaBH71ppZ8/5Yq1yn7FrKSbqkmuntDT bmj2pxVLHyeeahSD11Yy66ily/H5N44PjmOCr5E8uzq6MEsU4GPbqXyiuTHmmPVEhj6o Busg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qMH8R9DY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y4si6870803plg.427.2022.01.24.16.18.43; Mon, 24 Jan 2022 16:18:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=qMH8R9DY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1388516AbiAYAOP (ORCPT + 99 others); Mon, 24 Jan 2022 19:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1458150AbiAXX2Q (ORCPT ); Mon, 24 Jan 2022 18:28:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B51BC01D7FF; Mon, 24 Jan 2022 13:32:43 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2846E61305; Mon, 24 Jan 2022 21:32:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04D5CC340E4; Mon, 24 Jan 2022 21:32:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059962; bh=vV8dMG+wgDd6ixe70t0hx35EAlauBYI8+Djh336oDOQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMH8R9DYc4y8bIFCcdIeYFeHgBwmLMry5PmBmQl97k/VoQPaEOWg6MoDU7GEHIe4H psnYfLp8CXdQ0a7VcMVBbHzNWsqWOoxjvmCHdv2ozj8AJp3LQHWJB3VFK+zuXuZZRB 17gV8rRJVy2y4ZwTJqZ0RHdVFBlT0f/VvYMMvpNk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Christopherson , Paolo Bonzini , Sasha Levin Subject: [PATCH 5.16 0792/1039] KVM: x86: Handle 32-bit wrap of EIP for EMULTYPE_SKIP with flat code seg Date: Mon, 24 Jan 2022 19:43:01 +0100 Message-Id: <20220124184151.922433858@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson [ Upstream commit 5e854864ee4384736f27a986633bae21731a4e4e ] Truncate the new EIP to a 32-bit value when handling EMULTYPE_SKIP as the decode phase does not truncate _eip. Wrapping the 32-bit boundary is legal if and only if CS is a flat code segment, but that check is implicitly handled in the form of limit checks in the decode phase. Opportunstically prepare for a future fix by storing the result of any truncation in "eip" instead of "_eip". Fixes: 1957aa63be53 ("KVM: VMX: Handle single-step #DB for EMULTYPE_SKIP on EPT misconfig") Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini Message-Id: <093eabb1eab2965201c9b018373baf26ff256d85.1635842679.git.houwenlong93@linux.alibaba.com> Signed-off-by: Sasha Levin --- arch/x86/kvm/x86.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index bb87f43cdc78c..5d5a8e75edcb7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8134,7 +8134,12 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, * updating interruptibility state and injecting single-step #DBs. */ if (emulation_type & EMULTYPE_SKIP) { - kvm_rip_write(vcpu, ctxt->_eip); + if (ctxt->mode != X86EMUL_MODE_PROT64) + ctxt->eip = (u32)ctxt->_eip; + else + ctxt->eip = ctxt->_eip; + + kvm_rip_write(vcpu, ctxt->eip); if (ctxt->eflags & X86_EFLAGS_RF) kvm_set_rflags(vcpu, ctxt->eflags & ~X86_EFLAGS_RF); return 1; -- 2.34.1