From patchwork Mon Jan 21 12:20:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 10773783 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF0FE746 for ; Mon, 21 Jan 2019 12:21:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FCC029C10 for ; Mon, 21 Jan 2019 12:21:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9355B29C1D; Mon, 21 Jan 2019 12:21:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id C590A29C10 for ; Mon, 21 Jan 2019 12:21:13 +0000 (UTC) Received: (qmail 30058 invoked by uid 550); 21 Jan 2019 12:21:11 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Received: (qmail 30034 invoked from network); 21 Jan 2019 12:21:11 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=MnVtObA1fJy4gD+z1gL9LPKcmKRhWMJ7sii8yrEXzQM=; b=FLFVYR/ahaWCAE55FUa1NtgQZuryUXHAdfQ++fo9u2HBVxMlrfgGpo90HR0g+z+xTd Q9rpjJhTjkb9w7e/tNUolg9q1/LCfDWTZXgqpPONx/DzdY6Lsjv0Uhuc+xqB82XZkwjZ XmbEWpM2faJXrIEFYl9tKOoVRZ4jhCbCLr6Zd6/ZznOZXQ0tH122KDWQIlOMHRsfUzvU zJJzUdyvp1Nmry0mnaA2tUPyX65+qCYhmoQe6yGIf6OMLL0w3H0FyhDR+eVyMJnptL1E cvJIPKlCd77cBqZ/9NYYcpGSwbr74x921qCET1rRAhC/Pf6hgwNB6ZCY5mqe7SceUHMr g/tg== X-Gm-Message-State: AJcUukciAffjiBAlNGb30xX4cCBAHRO7I2DWhr28RHhH2PkPUqRtEfdd e1qm4i17R9KVt8N5nnWy75U= X-Google-Smtp-Source: ALg8bN7DaRXNO4htnXb7bQ9aYJzD0ErtwNDHpFyoNT+R5TOQPCqXKF/fIoRjSqDcmVrUMylc+LF6xg== X-Received: by 2002:a19:cd50:: with SMTP id d77mr17894241lfg.125.1548073259875; Mon, 21 Jan 2019 04:20:59 -0800 (PST) From: Alexander Popov To: Paolo Bonzini , Radim Krcmar , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Nadav Amit , Andy Lutomirski , Stefan Hajnoczi , H Peter Anvin , x86@kernel.org, kvm@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-kernel@vger.kernel.org, Alexander Popov Subject: [PATCH] KVM: x86: Fix single-step debugging Date: Mon, 21 Jan 2019 15:20:24 +0300 Message-Id: <1548073224-5363-1-git-send-email-alex.popov@linux.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP The single-step debugging of KVM guests on x86 is broken: if we run gdb 'stepi' command at the breakpoint when the guest interrupts are enabled, RIP always jumps to native_apic_mem_write(). Then other nasty effects follow. Long investigation showed that the commit c8401dda2f0a00cd25c0 (Jun 7 2017) introduced the kvm_run.debug corruption: kvm_vcpu_do_singlestep() can be called without X86_EFLAGS_TF set. Let's fix it. Please consider that for -stable. --- arch/x86/kvm/x86.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index f049ecf..9686068 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6407,8 +6407,7 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, toggle_interruptibility(vcpu, ctxt->interruptibility); vcpu->arch.emulate_regs_need_sync_to_vcpu = false; kvm_rip_write(vcpu, ctxt->eip); - if (r == EMULATE_DONE && - (ctxt->tf || (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP))) + if (r == EMULATE_DONE && ctxt->tf) kvm_vcpu_do_singlestep(vcpu, &r); if (!ctxt->have_exception || exception_type(ctxt->exception.vector) == EXCPT_TRAP)