Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6165296imu; Mon, 21 Jan 2019 04:22:51 -0800 (PST) X-Google-Smtp-Source: ALg8bN7xBpU290pTkco125Fi9eyOOSgGnhCoMDCnPGWdyz+h8KpW83B3tMgE3ojjDCHLSBy/i1IC X-Received: by 2002:a17:902:aa4c:: with SMTP id c12mr29992576plr.48.1548073371558; Mon, 21 Jan 2019 04:22:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548073371; cv=none; d=google.com; s=arc-20160816; b=zp/1fMJUfnvQJqjp2nBtydcbUf4gMR2Og4iYbCcsBddPtqdrzPkISQd4MEqAD2+geH F49EQy8vU9Zl0DdddFVZkYh8fUmIU/HI61rc/Rlf+99hlGkFuBWmz7bTpRe0ivS096VM 9o9cuK50Bgy0pAzTTOPmzpCujfD5/KxpUdLVTsv0375xHoHL5+YHhScfmGJiHYg5/IY3 17gcAj0mYdnKLh1N6MVQm5dDG+qo6SnHEz1AMwech+cARBBKlgQIbQPUFG3iofjn7Asx 5NJwp9zRfDlhRBKNRo9WMYBdgsOPQCSKZTvVnw8xlEixFhX7Mj1r2cLHjmiUsozu9Nzf OWsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:to:from; bh=MnVtObA1fJy4gD+z1gL9LPKcmKRhWMJ7sii8yrEXzQM=; b=CfkiHRaYuyN7+B9PMC/b0+/pGdTQAc8lz/MJRc/zcvjfg7V04hjnO6GX1of0BY32qD Ic0sW+vbEIthe/pC0VlXMsFZYMN0LQV1+I08FiouOEDiz9ziBC0yWA0azA1lsmagYZ70 RqCrM0szCq10wprdA/wn3Ho0EoCpL13WUydpCRomA3wwHcJ+Dgv0tLzXFIq4cGaZOKtp S3whw8DqeQlKTlxh5/WhwojZ3q3yUUUU15SKAZ6ips82pdlKIui25gV2DmXRg7vje9Bk 12GVYLlKlSIA404qm36++GG+mQszMPtlaMQIE3W1tte390r6u1C25UBCWbtR0we/WWnb poEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e9si12464447plt.181.2019.01.21.04.22.24; Mon, 21 Jan 2019 04:22:51 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728439AbfAUMVC (ORCPT + 99 others); Mon, 21 Jan 2019 07:21:02 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:43928 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727926AbfAUMVB (ORCPT ); Mon, 21 Jan 2019 07:21:01 -0500 Received: by mail-lf1-f68.google.com with SMTP id u18so15320404lff.10; Mon, 21 Jan 2019 04:21:00 -0800 (PST) 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=dGOwpX5RMI2P2azKteXJzfXlLDMvLDfEiY1mnYVgqik7vmhNCy4yEitcVf4IR45k+m 5Cred5MV/U2jjPgNi2TdO929b5iqzEEBu/DLzor3qoeCs92AqOkcdfishzjcJAip70tu M4FXkMPaM9Nhp01hlKlv79JCSm32caf0u5dQrYKJ5ENQ5EHVIMbQ/Je9ubP7HO7W1Nz7 IqCXRfPqdup1vyVyOLiC6aIbZTeX+BgTvdjuAjcmYWudAKo++eEiPwKCU4oaqq++b7sV hXV2lagGprHb+D9OLArz0zLl2H6Hw2lHaKv1W6jTuft/ftYxR1JVSio1CcA/olErVpzn rJxw== X-Gm-Message-State: AJcUukflIFUP36VOdhkm02zRCf6iTo2zbT6zgwBMpp/pKXrq+HJfv39V ElN7XJlU4398KEIB9HJ60/Q= X-Received: by 2002:a19:cd50:: with SMTP id d77mr17894241lfg.125.1548073259875; Mon, 21 Jan 2019 04:20:59 -0800 (PST) Received: from localhost.localdomain ([213.87.132.221]) by smtp.gmail.com with ESMTPSA id 10sm2256354lff.62.2019.01.21.04.20.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.7.4