Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6468615imu; Mon, 21 Jan 2019 09:23:35 -0800 (PST) X-Google-Smtp-Source: ALg8bN7A/ZI+XSdR6mIY8YnziiO8Fodc52dxJBf4TJF7M93UoExuL3eG9G+q37XmuncbdbTOuudg X-Received: by 2002:a62:7e13:: with SMTP id z19mr30302828pfc.94.1548091415086; Mon, 21 Jan 2019 09:23:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548091414; cv=none; d=google.com; s=arc-20160816; b=CY+fe3NBrYE22rkGCKh2O0yNAiawLjXc0+/JVpKXK1eqTU0KUQym6FqkBJI86tQj5w hiAnIBKjPM8ibt3dmNzRg13cgB+cFstweh0cOTKSHP9KS6thgmQYGFJ6YyAHdBXuFpMm 0v4ltvULpBh3gEKw4E53h75D4hh0wJdSP+Fh5cFrPCGXIB2omkBz0n3TgHbbMoTX3ga2 HTr/HS3MxMYfui6Alq+0iW7KsmtQQdD8RtpoQt6iqPByjsls8tHCQf2N2bCm/NYEMTAr 8BQENsfLzL8pMPkQ8cTyXK+E8dMW5KRaKu2iXrZh+E8i+z5pMqS13jFw1w8wvoLsc1Qg wKQg== 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=1rik5yWAwK/VZEgE3GAP/26Xz0u6FKuRPpB5cNtjyms=; b=rjB4GmAyxs/gidZa6TTxCMY/LyJpK75E4MGvC26XUIn5HC4uAqgrx8v3RQnbjJIQ33 uSfwkzTRTPamVn9APBC2h8LsWJYoEjz+vcSpJDqmskxphCr3V9+VMG2h8j1ziCmwVu3O d9Z4Zp56TrzOjxbbSC38dpjO3xVy1kudgVW9HlIDHMNv7aLHI1mxx8inZa65ss2Sr1rC Z+F8kNI0SFM5CHdq5LgsdtdVDTFMChYBz+o8rScyPY7sDQCHpix9cZSTWQXQdKc0ra2w w3kVV258uWA2zvw41yrkbk0SGpdfnsQg+JUjKkWkUdj37GqweQm6viKxDHC40iFMyfx3 1f0g== 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 a12si12815883pgk.291.2019.01.21.09.23.18; Mon, 21 Jan 2019 09:23:34 -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 S1728704AbfAUMsx (ORCPT + 99 others); Mon, 21 Jan 2019 07:48:53 -0500 Received: from mail-lf1-f67.google.com ([209.85.167.67]:41274 "EHLO mail-lf1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728163AbfAUMsx (ORCPT ); Mon, 21 Jan 2019 07:48:53 -0500 Received: by mail-lf1-f67.google.com with SMTP id c16so15392154lfj.8; Mon, 21 Jan 2019 04:48:52 -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=1rik5yWAwK/VZEgE3GAP/26Xz0u6FKuRPpB5cNtjyms=; b=DPX5QiPhJznBlN+vd9vjGMrvlZHwpxjKSnx/xYYTu78H+7dtbwb6SDDFt9k8ctKTZJ jCDw1zkqT4M1gRWR+yFi+DjLwcI0sVFEkqf/UM3qd1XoCTkVcxApEH5fOh9HMSoX/4kl 7dp2281IwD0fTEr6I+UU42CsHYVQ5qJr6CZXZB4K7u3nz6k/Fyu0TcL6oe5DjtCnCnI7 s1vXtqpu6Id2g45nnsoRT4CFXERR+ZfSBXZsj4GITk3KMGTTbKYUkM1aumfQ0qfylIQd w/0lJg11ZMhLkugoi5nXESvChIRZRZsVQkoufy6v7IEL8QzF7CcVeBT7ceMEAE5e4Iwi vZHQ== X-Gm-Message-State: AJcUukcEHeptivX6crbwUNmZ/VBBHEmBt8aMFrlHwVzK9HvW/nmXoelB ulj5V2TUk5e1bOYpOVVIkRc= X-Received: by 2002:a19:c70a:: with SMTP id x10mr17898358lff.88.1548074931300; Mon, 21 Jan 2019 04:48:51 -0800 (PST) Received: from localhost.localdomain ([213.87.132.221]) by smtp.gmail.com with ESMTPSA id k68-v6sm2288537ljb.35.2019.01.21.04.48.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Jan 2019 04:48:50 -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 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 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) -- 2.7.4