From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751609AbdLKWqG (ORCPT ); Mon, 11 Dec 2017 17:46:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41486 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750759AbdLKWqB (ORCPT ); Mon, 11 Dec 2017 17:46:01 -0500 Subject: Re: WARNING in x86_emulate_insn To: Tianyu Lan , Jim Mattson Cc: Wanpeng Li , Dmitry Vyukov , syzbot , "H. Peter Anvin" , kvm , "linux-kernel@vger.kernel.org" , Ingo Molnar , Radim Krcmar , syzkaller-bugs@googlegroups.com, Thomas Gleixner , the arch/x86 maintainers References: <001a1143d526c5b1aa055f9d604c@google.com> From: Paolo Bonzini Message-ID: Date: Mon, 11 Dec 2017 23:45:57 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 11 Dec 2017 22:46:01 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/12/2017 09:28, Tianyu Lan wrote: > 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 is not what the testcase is testing; this is already covered by __load_segment_descriptor: if (null_selector) { if (seg == VCPU_SREG_CS || seg == VCPU_SREG_TR) goto exception; if (seg == VCPU_SREG_SS) { if (ctxt->mode != X86EMUL_MODE_PROT64 || rpl != cpl) goto exception; ... } Is there a path that can return X86EMUL_PROPAGATE_FAULT without setting ctxt->exception.vector and/or without going through emulate_exception? I don't think it's possible to write a test in kvm-unit-tests, because the state has "impossible" segment descriptor cache contents. Paolo > 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);