From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752606AbdLHIoL (ORCPT ); Fri, 8 Dec 2017 03:44:11 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:42318 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750993AbdLHIoK (ORCPT ); Fri, 8 Dec 2017 03:44:10 -0500 X-Google-Smtp-Source: AGs4zMa3SvtosP4lieV3esCFpzs8Vd4y9JyGJk/2UYLrCivvV1IC0NuddFKzZIC9dVQ+BYL0YKk7Jg== Date: Fri, 8 Dec 2017 09:44:06 +0100 From: Ingo Molnar To: Tianyu Lan Cc: Jim Mattson , Wanpeng Li , Dmitry Vyukov , syzbot , "H. Peter Anvin" , kvm , "linux-kernel@vger.kernel.org" , Ingo Molnar , Paolo Bonzini , Radim Krcmar , syzkaller-bugs@googlegroups.com, Thomas Gleixner , the arch/x86 maintainers , Andrew Jones Subject: Re: WARNING in x86_emulate_insn Message-ID: <20171208084406.hogx5aidikmp4nwl@gmail.com> References: <001a1143d526c5b1aa055f9d604c@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Tianyu Lan wrote: > Hi Jim&Wanpeng: > Thanks for your help. > > 2017-12-08 5:25 GMT+08:00 Jim Mattson : > > Try disabling the module parameter, "unrestricted_guest." Make sure > > that the module parameter, "emulate_invalid_guest_state" is enabled. > > This combination allows userspace to feed invalid guest state into the > > in-kernel emulator. > > Yes, you are right. I need to disable unrestricted_guest to reproduce the issue. > > I find this is pop instruction emulation issue. According "SDM VOL2, > chapter INSTRUCTION > SET REFERENCE. POP—Pop a Value from the Stack" > > Protected Mode Exceptions > #GP(0) If attempt is made to load SS register with NULL segment selector. > > This test case hits it but current code doesn't check such case. > The following patch can fix the issue. > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index abe74f7..e2ac5cc 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -1844,6 +1844,9 @@ static int emulate_pop(struct x86_emulate_ctxt *ctxt, > int rc; > struct segmented_address addr; > > + if ( !get_segment_selector(ctxt, VCPU_SREG_SS)) > + return emulate_gp(ctxt, 0); > + > addr.ea = reg_read(ctxt, VCPU_REGS_RSP) & stack_mask(ctxt); > addr.seg = VCPU_SREG_SS; > rc = segmented_read(ctxt, addr, dest, len); s/if ( !get_segment_selector /if (!get_segment_selector I think it would also be nice to convert the syzkaller testcase to a new KVM unit test: git://git.kernel.org/pub/scm/virt/kvm/kvm-unit-tests.git There's a test_pop() function in kvm-unit-tests/x86/emulator.c. Thanks, Ingo