Received: by 10.223.176.5 with SMTP id f5csp1084612wra; Sat, 3 Feb 2018 18:00:49 -0800 (PST) X-Google-Smtp-Source: AH8x225buNQGMldm8/1h43yBpBU9OleiWpEz7hDwhVuV7VEbP0Ako+KhcuEBb0bYM5EB7pUgUnp3 X-Received: by 2002:a17:902:1a4:: with SMTP id b33-v6mr2745204plb.58.1517709649699; Sat, 03 Feb 2018 18:00:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517709649; cv=none; d=google.com; s=arc-20160816; b=Z/CTwljR2m/sXe1GpH5yez6h4Ri41t6tsPkqgMvjBhb9PJ3sHhdpOFmxWMwO+wQhhw zFZyZiWRr1qy77kd/l1aDSg5xvBkOcb08+jTEkbzIe2YO/9/YlKRzw9E7QTxq8qz1q0A 0+jWZch+Xyt1zO3AgBdugVjTP2dhM+paaIWpBy21dW4qPcjT0yrt91a5UomnLpva9Z4E z4M7d3hu/N3JhL+JMfV019ps256lbQy9EBdWNO1Fv2XBTLNDhC4twAbdFkMD/uX366bI 33RGslHUXD+K8WOhl07pjozhngd7YL+3huHXKXFmNCtmHwpSeafTGdVG2gftmKsTFhMk sHcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=3hJpFib2VkWXwKz7ZTyVFCcnMtVIhJRc9eYHnrb7iPw=; b=ovHiHYByKMFjnFBjahaiq6yJjp+oUhzzV+waLJBkEU/3VBJjlgJiydkei3UdMbfDP8 NdG1ayllY/ypNWa9EAr4Kv5eUEmEXRzBX6zXQFgBs+Pyy3/+49fQgRJfzAQ0Y5Z+mDhO Kpf7rXELnbCCGJTdXnr0OZwJehCibCcrfSMZuco+/qJ4Bbq/RRcWC1jBFdPAdzI6VzUo OALiRF71RwfLkW/tg3End7j8dVP5VFtJrDmTYLs8I/5UWyD1wjqDmoyNQCpwGV8Bqdvf uB6Tvj6ZHFLaiB9s7eYJX2CN3y7ytPVjACA8pBA189aih+Z4dm0hA4tcttMbjUmJJ1BE jM4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cVRMlVGW; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f31-v6si4613347plf.601.2018.02.03.18.00.35; Sat, 03 Feb 2018 18:00:49 -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=@gmail.com header.s=20161025 header.b=cVRMlVGW; 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=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752916AbeBDBYl (ORCPT + 99 others); Sat, 3 Feb 2018 20:24:41 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:35847 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752675AbeBDBYd (ORCPT ); Sat, 3 Feb 2018 20:24:33 -0500 Received: by mail-pf0-f196.google.com with SMTP id k5so3354441pff.3; Sat, 03 Feb 2018 17:24:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=3hJpFib2VkWXwKz7ZTyVFCcnMtVIhJRc9eYHnrb7iPw=; b=cVRMlVGW4GZBszLmDmWP3D0uSet3EegpWbjR5S7wabEfRM/tObrbWMdGb/1TAt44+O pGSVRe/40IU1tAVnDCeBYnJdWCv2CO1/bwQs1pWwq+kEMqxfZDrZt3pglyFSr+DIf52i IzLaKzCCg07bRt0Guto5JMnfEeHO4t9iKeRQ8NtNLg2cobM8f74iumynfCn3ogPuyyeA Zwsyo1QXGV+ZpJObPPTWryUrWu+NWu1ttl0it25L0tFgNlVNtndXvhadp85nmRi9uppA f+eBFds7tZvwIGlo6t39EuE9cZ2IDCr2/JnjiqGv0YoFqZuCI2I7wX4z3mWJUCUq9d7h /yFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=3hJpFib2VkWXwKz7ZTyVFCcnMtVIhJRc9eYHnrb7iPw=; b=nSWP6x3QX2B2+BnQDJ2by7O9iu1Kfo+4jUM9HFK80qb7E2EcNa5L5tRFkSgxfQy6L3 6A9dH9hE1LLK7knAsu3lPDGFQ6beCR5Ag1sLR0S1ohLw2WhBZWjVuL8iBxrJatITZroj xy1HkuIeuDCTbEjRxpPI5e5XgkycNm9kZ7tjdG/QTpEUW3rAb0q0VBakdMpAuFAFiJNC RXpKLQhAa3m3jF7J6vWHenq0REn8DkOtqlUNLlDVIf7s3NOwSFJfOMVElHpFLwgCiCML QJxqgfLgZk/Gwtxv/1epAiI5m8SDjjD1p6EiiJiaECU44kpoV+80K6UNByIjn91LdPJH BBbA== X-Gm-Message-State: AKwxytc0kb+6NB7l2QQDicEiTLxQxaO2OdQoUct/+rr4Vao5ZNbPWh+A 2V8o/wvq1U88MR3EL8ff62k= X-Received: by 10.99.108.7 with SMTP id h7mr34599684pgc.292.1517707472844; Sat, 03 Feb 2018 17:24:32 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id i3sm7937916pgs.63.2018.02.03.17.24.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 03 Feb 2018 17:24:32 -0800 (PST) Date: Sat, 3 Feb 2018 17:24:29 -0800 From: Eric Biggers To: Sasha Levin Cc: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , Lan Tianyu , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Dmitry Vyukov , Jim Mattson Subject: Re: [PATCH AUTOSEL for 4.14 006/110] KVM/x86: Check input paging mode when cs.l is set Message-ID: <20180204012429.GA24727@zzz.localdomain> References: <20180203180015.29073-1-alexander.levin@microsoft.com> <20180203180015.29073-6-alexander.levin@microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180203180015.29073-6-alexander.levin@microsoft.com> User-Agent: Mutt/1.9.3 (2018-01-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 03, 2018 at 06:00:29PM +0000, Sasha Levin wrote: > From: Lan Tianyu > > [ Upstream commit f29810335965ac1f7bcb501ee2af5f039f792416 ] > > Reported by syzkaller: > WARNING: CPU: 0 PID: 27962 at arch/x86/kvm/emulate.c:5631 x86_emulate_insn+0x557/0x15f0 [kvm] > Modules linked in: kvm_intel kvm [last unloaded: kvm] > CPU: 0 PID: 27962 Comm: syz-executor Tainted: G B W 4.15.0-rc2-next-20171208+ #32 > Hardware name: Intel Corporation S1200SP/S1200SP, BIOS S1200SP.86B.01.03.0006.040720161253 04/07/2016 > RIP: 0010:x86_emulate_insn+0x557/0x15f0 [kvm] > RSP: 0018:ffff8807234476d0 EFLAGS: 00010282 > RAX: 0000000000000000 RBX: ffff88072d0237a0 RCX: ffffffffa0065c4d > RDX: 1ffff100e5a046f9 RSI: 0000000000000003 RDI: ffff88072d0237c8 > RBP: ffff880723447728 R08: ffff88072d020000 R09: ffffffffa008d240 > R10: 0000000000000002 R11: ffffed00e7d87db3 R12: ffff88072d0237c8 > R13: ffff88072d023870 R14: ffff88072d0238c2 R15: ffffffffa008d080 > FS: 00007f8a68666700(0000) GS:ffff880802200000(0000) knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 000000002009506c CR3: 000000071fec4005 CR4: 00000000003626f0 > Call Trace: > x86_emulate_instruction+0x3bc/0xb70 [kvm] > ? reexecute_instruction.part.162+0x130/0x130 [kvm] > vmx_handle_exit+0x46d/0x14f0 [kvm_intel] > ? trace_event_raw_event_kvm_entry+0xe7/0x150 [kvm] > ? handle_vmfunc+0x2f0/0x2f0 [kvm_intel] > ? wait_lapic_expire+0x25/0x270 [kvm] > vcpu_enter_guest+0x720/0x1ef0 [kvm] > ... > > When CS.L is set, vcpu should run in the 64 bit paging mode. > Current kvm set_sregs function doesn't have such check when > userspace inputs sreg values. This will lead unexpected behavior. > This patch is to add checks for CS.L, EFER.LME, EFER.LMA and > CR4.PAE when get SREG inputs from userspace in order to avoid > unexpected behavior. > > Suggested-by: Paolo Bonzini > Reported-by: Dmitry Vyukov > Cc: Paolo Bonzini > Cc: Radim Krčmář > Cc: Dmitry Vyukov > Cc: Jim Mattson > Signed-off-by: Tianyu Lan > Signed-off-by: Paolo Bonzini > Signed-off-by: Sasha Levin > --- > arch/x86/kvm/x86.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 8c28023a43b1..ad0f18107c74 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -7473,6 +7473,29 @@ int kvm_task_switch(struct kvm_vcpu *vcpu, u16 tss_selector, int idt_index, > } > EXPORT_SYMBOL_GPL(kvm_task_switch); > > +int kvm_valid_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs) > +{ > + if ((sregs->efer & EFER_LME) && (sregs->cr0 & X86_CR0_PG_BIT)) { > + /* > + * When EFER.LME and CR0.PG are set, the processor is in > + * 64-bit mode (though maybe in a 32-bit code segment). > + * CR4.PAE and EFER.LMA must be set. > + */ > + if (!(sregs->cr4 & X86_CR4_PAE_BIT) > + || !(sregs->efer & EFER_LMA)) > + return -EINVAL; > + } else { > + /* > + * Not in 64-bit mode: EFER.LMA is clear and the code > + * segment cannot be 64-bit. > + */ > + if (sregs->efer & EFER_LMA || sregs->cs.l) > + return -EINVAL; > + } > + > + return 0; > +} This commit is broken and there was a fix for it merged: 37b95951c58 ("KVM/x86: Fix wrong macro references of X86_CR0_PG_BIT and X86_CR4_PAE_BIT in kvm_valid_sregs()"). Shouldn't your script have picked that up too? - Eric