Received: by 10.223.176.5 with SMTP id f5csp293038wra; Tue, 6 Feb 2018 22:43:17 -0800 (PST) X-Google-Smtp-Source: AH8x227N16D09uDBpKltEGAEWB4VxUYsAPxr5yMbA1L0YI1CVFJG6+tzpVbGxIkhyv3jA/cdeXbH X-Received: by 10.98.150.14 with SMTP id c14mr3056054pfe.210.1517985797223; Tue, 06 Feb 2018 22:43:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517985797; cv=none; d=google.com; s=arc-20160816; b=EoY0heELJWkXvro6F58bjkrXj9LF+K/aBPxTkshIJgv79/ICFTRbOQB18S24grA4xW apZ4QzkfjuTRgqGKEFyMt4xNCKDI/xoluZJvsb2u6zSgLvT1OgViulgE52VFvUw8wgJX 2CuZsqxRg9t04HlDaIvRdU2ZOE21BWUmQx40jy7De84PdELFA5Y1MQzS773i2dRYDZkb /fye4F63MWScOH3oWV9oL34zf4zczAqtOqdajuE/I0LIx5CD2Y9kgSD7r157T+Vo7+Rk UWCJlVT58LTaWj45ThcSFi07XSpBWDvaLcqHKujd8H39MmAIvPCO54BVboiOJ53LNLkf YUMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=PNQPdoiumiiDYYYGXjL44YGLDbrbN/RQlfqYb8Z2ZQI=; b=DSpLS/Ui9YtjVk37Qfy1ntk3edf2zZJ7OJmzhfuZl8gFv6B0LDByq0ONkFyB+w9spD SgLxH5SwlVnZUEr9KF61S0xij0W+WK22omfwwtSfY/pYKwSxH2ouN3S675VZ6HADcZJ6 PabrdapCW+0Op2FnyGN0CjfEERpJtbibdxSQYzvpWbgJB4YUB58bwEvFD/Zl3Yix1fHo GALp4RhWYqaXD5pp3XeNNT61YblC2QrZ3bNcD4DvQunkDEIEYYeQ4JTLaCglA/NWCr/r Q8GwrciI5wQbdibCp1ZxVibtLAdvyNdoUcS2RAkXDBzzfcQLxsuygfiV8dnngSDm4NJ8 6TOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=cKafGKZP; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r20si653320pfe.245.2018.02.06.22.42.51; Tue, 06 Feb 2018 22:43:17 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=cKafGKZP; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753420AbeBGGl4 (ORCPT + 99 others); Wed, 7 Feb 2018 01:41:56 -0500 Received: from mail-pl0-f66.google.com ([209.85.160.66]:45876 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750768AbeBGGly (ORCPT ); Wed, 7 Feb 2018 01:41:54 -0500 Received: by mail-pl0-f66.google.com with SMTP id p5so2881488plo.12 for ; Tue, 06 Feb 2018 22:41:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=PNQPdoiumiiDYYYGXjL44YGLDbrbN/RQlfqYb8Z2ZQI=; b=cKafGKZPF/DRdhdlvMi96I5QheMPBnYxqGDyYSMemzDZ1C99G16eZH6Lwi33ig8mZn 3APplc3IS0FIyMQOM3V2zxpcDowAa6M4fvfUFKQKGY55vKJvxyi81r7/ea2T+WrDcFFa zqqPRbGQ0QPXkdyJK1rtOoGqSJxHgKm4a2ibVDoikQf7NQDsBuhsRgKl1+pVWTkuhCQM xmR7qN36ABsAOHxCqG9rEtPDEK5wA/PpNfd71f6Zm0eOUgo64noMFnGEXN/mqD/GCWSM w74WBoPnBp2qi5h9QYUrGSOKqrGEthP3SaSKV59W1d78P17y+EBJsvyOubs4gb3RXZHe 7xNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=PNQPdoiumiiDYYYGXjL44YGLDbrbN/RQlfqYb8Z2ZQI=; b=tC3HIcPRIU8daYqZ4YIYfDPOmKjy44p07omA7UQlELYvt98UQKo4VNt+efe+wF1Z5d KedWraL5ttrxHVXH9vH2sDuRU6fzhsOc0e7H9+zBlTKGjJ87eGg/6uiiDjWHEuexb9H1 LBy1xmxepPrGgm8vn31jncacdrcI25M0ZKNqNJ2aLb+fjKFTRRW8amkAbDEABJ6boVY8 8h+Hz2nb4GZvI+x7rbflEcM4gODxVJAxLp4Umw1QGrxasKjRv6OKYYJ9GR6BU1ELUrE2 +41i2tKP/EIRlkX5tnIsbiPJeugD5yn8XqjBX/EBrkGBcCELd86sCfCj6t4zyj1G2YnP 26qg== X-Gm-Message-State: APf1xPBDYgekT9tkoZHu1rp07kORl75dZ3wb1vpA2T70Ngxge+qfRfKy VKuHe2eCrTB9ECSK1zeSma0vMbFekE6mJ5/SMhM1KQ== X-Received: by 2002:a17:902:8f8b:: with SMTP id z11-v6mr5025357plo.43.1517985713752; Tue, 06 Feb 2018 22:41:53 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.140.151 with HTTP; Tue, 6 Feb 2018 22:41:33 -0800 (PST) In-Reply-To: <1517984706-47244-1-git-send-email-wanpengli@tencent.com> References: <1517984706-47244-1-git-send-email-wanpengli@tencent.com> From: Dmitry Vyukov Date: Wed, 7 Feb 2018 07:41:33 +0100 Message-ID: Subject: Re: [PATCH] KVM: X86: Fix SMRAM accessing even if VM is shutdown To: Wanpeng Li Cc: LKML , KVM list , Paolo Bonzini , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 7, 2018 at 7:25 AM, Wanpeng Li wrote: > From: Wanpeng Li > > Reported by syzkaller: > > WARNING: CPU: 6 PID: 2434 at arch/x86/kvm/vmx.c:6660 handle_ept_miscon= fig+0x54/0x1e0 [kvm_intel] > CPU: 6 PID: 2434 Comm: repro_test Not tainted 4.15.0+ #4 > RIP: 0010:handle_ept_misconfig+0x54/0x1e0 [kvm_intel] > Call Trace: > vmx_handle_exit+0xbd/0xe20 [kvm_intel] > kvm_arch_vcpu_ioctl_run+0xdaf/0x1d50 [kvm] > kvm_vcpu_ioctl+0x3e9/0x720 [kvm] > do_vfs_ioctl+0xa4/0x6a0 > SyS_ioctl+0x79/0x90 > entry_SYSCALL_64_fastpath+0x25/0x9c > > The syzkaller creates a former thread to issue KVM_SMI ioctl, and then cr= eates > a latter thread to mmap and operate on the same vCPU, rsm emulation will = not be > executed since there is no something like seabios which implements smi ha= ndler > when running syzkaller directly. This triggers a race condition when runn= ing > the testcase with multiple threads. Sometimes one thread exit w/ SHUTDOWN > reason, another thread mmaps and operates on the same vCPU, it continues = to > use CS=3D0x30000, IP=3D0x8000 to access the address of SMI handler which = results > in the above ept misconfig. This patch fixes it by bailing out immediatel= y if > the vCPU is marked EXIT_SHUTDOWN reason. > > Reported-by: Dmitry Vyukov This was reported by syzbot: https://groups.google.com/d/msg/syzkaller-bugs/6GrlY0UcDEk/aMShRKq3AwAJ IMPORTANT: if you fix the bug, please add the following tag to the commit: Reported-by: syzbot+c1d9517cab094dae65e446c0c5b4de6c40f4dc58@syzkaller.apps= potmail.com It will help syzbot understand when the bug is fixed. > Cc: Dmitry Vyukov > Cc: Paolo Bonzini > Cc: Radim Kr=C4=8Dm=C3=A1=C5=99 > Signed-off-by: Wanpeng Li > --- > arch/x86/kvm/x86.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 786cd00..445e702 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -7458,6 +7458,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu,= struct kvm_run *kvm_run) > goto out; > } > > + if (unlikely(vcpu->run->exit_reason =3D=3D KVM_EXIT_SHUTDOWN)) { > + r =3D -EINVAL; > + goto out; > + } > + > if (vcpu->run->kvm_dirty_regs) { > r =3D sync_regs(vcpu); > if (r !=3D 0) > -- > 2.7.4 >