All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Tianyu Lan <lantianyu1986@gmail.com>
Cc: Jim Mattson <jmattson@google.com>,
	Wanpeng Li <kernellwp@gmail.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	syzbot
	<bot+75375385991b4f8c599704a10849863c586ea284@syzkaller.appspotmail.com>,
	"H. Peter Anvin" <hpa@zytor.com>, kvm <kvm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Radim Krcmar <rkrcmar@redhat.com>,
	syzkaller-bugs@googlegroups.com,
	Thomas Gleixner <tglx@linutronix.de>,
	the arch/x86 maintainers <x86@kernel.org>,
	Andrew Jones <drjones@redhat.com>
Subject: Re: WARNING in x86_emulate_insn
Date: Fri, 8 Dec 2017 09:44:06 +0100	[thread overview]
Message-ID: <20171208084406.hogx5aidikmp4nwl@gmail.com> (raw)
In-Reply-To: <CAOLK0pwczbQrno_vc2Uj6czyELyiEHeCAoi2SgDvvKcRNiijiw@mail.gmail.com>


* Tianyu Lan <lantianyu1986@gmail.com> wrote:

> Hi Jim&Wanpeng:
>          Thanks for your help.
> 
> 2017-12-08 5:25 GMT+08:00 Jim Mattson <jmattson@google.com>:
> > 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

  reply	other threads:[~2017-12-08  8:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-05 20:07 WARNING in x86_emulate_insn syzbot
2017-12-07  0:44 ` Wanpeng Li
2017-12-07  6:25   ` Dmitry Vyukov
2017-12-07  7:49     ` 蓝天宇
2017-12-07  7:52       ` Wanpeng Li
2017-12-07 10:40         ` Wanpeng Li
2017-12-07 21:25           ` Jim Mattson
2017-12-08  8:28             ` Tianyu Lan
2017-12-08  8:44               ` Ingo Molnar [this message]
2017-12-08  8:48                 ` Tianyu Lan
2017-12-08  9:27               ` Wanpeng Li
2017-12-09  5:44                 ` Lan, Tianyu
2017-12-11 22:45               ` Paolo Bonzini
2017-12-12  8:50                 ` Lan Tianyu
2017-12-08  3:22 ` syzbot
2017-12-08  3:33   ` Wanpeng Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171208084406.hogx5aidikmp4nwl@gmail.com \
    --to=mingo@kernel.org \
    --cc=bot+75375385991b4f8c599704a10849863c586ea284@syzkaller.appspotmail.com \
    --cc=drjones@redhat.com \
    --cc=dvyukov@google.com \
    --cc=hpa@zytor.com \
    --cc=jmattson@google.com \
    --cc=kernellwp@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=lantianyu1986@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.com \
    --cc=syzkaller-bugs@googlegroups.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.