From patchwork Mon Jan 21 12:48:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Popov X-Patchwork-Id: 10773841 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 7B0CF14E5 for ; Mon, 21 Jan 2019 12:49:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C1E229CD9 for ; Mon, 21 Jan 2019 12:49:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FE4C29CE1; Mon, 21 Jan 2019 12:49:05 +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 9C7C029CD9 for ; Mon, 21 Jan 2019 12:49:04 +0000 (UTC) Received: (qmail 30036 invoked by uid 550); 21 Jan 2019 12:49:03 -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 30014 invoked from network); 21 Jan 2019 12:49:02 -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=1rik5yWAwK/VZEgE3GAP/26Xz0u6FKuRPpB5cNtjyms=; b=gdq0lShxdhj9K/R6e4b2AL1reN4FWHBzAFTa6+f+rmpEfsyz7vQyzE/PUDLqkZ5AFD Oa7JSVzJLGMHB3TzZi0h8Cnm340mH+xd42bohfIAJ6D3l3Q4Qfh0W7pBT246fCFDNPc9 ii/+NNsyGZUmSJ6cvZh0vqAyq/dwwrzOmgR2m0gbfOK7H7HATmSYF1CR02SVLNKSsvku zqJCCZLSb1LOKpNMaxpfWYRevBmvKf0gOog00cCJgu/TE+OsvCxbH0VnHzaGgZFFz+Lu Orf4UUs4NggRG1XBEbqQBNp9weziI7OyS0sPoKv7wviKI/YYmwBTOYa6sCI6aO53fLbb ySyQ== X-Gm-Message-State: AJcUukc35cbIFdqMAiR3drczdElbGdmC6H755WSSOmzJ+bLyEg1g6T5D YyMrK35UJTjBUjP6kz7nQr9bqnjK X-Google-Smtp-Source: ALg8bN6Ko9Iwu5fWvCaS60yLSJRKSDsyvVKlRT85yCEdok16q+tqefY4oIBm6IlKhLSI8+XxIIXszw== X-Received: by 2002:a19:c70a:: with SMTP id x10mr17898358lff.88.1548074931300; Mon, 21 Jan 2019 04:48:51 -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 v2] KVM: x86: Fix single-step debugging Date: Mon, 21 Jan 2019 15:48:40 +0300 Message-Id: <1548074920-10651-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 on Jun 7, 2017 the commit c8401dda2f0a00cd25c0 ("KVM: x86: fix singlestepping over syscall") 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. Signed-off-by: Alexander Popov --- 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)