linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>,
	Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, Pavel Machek <pavel@ucw.cz>,
	"Rafael J. Wysocki" <rjw@rjwysocki.net>, X86 ML <x86@kernel.org>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Denys Vlasenko <dvlasenk@redhat.com>,
	Borislav Petkov <bp@alien8.de>, Brian Gerst <brgerst@gmail.com>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] x86: General protection fault after STR (32 bit systems only)
Date: Fri, 12 Jun 2015 09:15:07 +0200	[thread overview]
Message-ID: <20150612071507.GA6411@gmail.com> (raw)
In-Reply-To: <CALCETrWjckJqfBdvhjGk81-tOOKu8QVeT6WC=hjtXYURvJ7dmA@mail.gmail.com>


* Andy Lutomirski <luto@amacapital.net> wrote:

> > 1)
> >
> > So the first critical question is: if the ACPI/BIOS suspend code corrupts the 
> > kernel's DS, how can we get so far as to resume fully, return to user-space, 
> > and segfault there so that it can all be reported?
> >
> > So neither the explanation nor the code makes any sense in the context of the 
> > reported bugs. Can anyone else offer any plausible theory about why this patch 
> > would fix 32-bit user-space segfaults?
> 
> I'm too tired to look at this intelligently right now, but this reminds me of 
> the sysret_ss_attrs thing.  What if we have a situation where, after 
> suspend/resume, we end up with a perfectly valid ss *selector* (or, on 64-bit 
> kernels, a ds selector that does not matter one whit) but a somehow-screwed-up 
> ds *cached hidden descriptor*.  (On 32-bit kernels, this could be something 
> exotic like grows-down limit 2^31.)

Yes, that theory is what my patch tests, by reloading DS with __KERNEL_DS.

This should be safe as the first thing to execute after re-entry, as we don't 
save/restore the GDT. (If the BIOS mucks with the GDT without restoring it to our 
value we are probably screwed in any case.)

> Now we do the very first return.  If we're on AMD hardware and that return is 
> SYSRET, then we end up with some complete random garbage loaded in the hidden DS 
> descriptor if SYSRET on 32-bit mode is indeed screwed up on AMD.

But why would this change from v3.10 to v3.11? I cannot see any low level x86 
change that should make a difference there.

> Don't even bother saving it.  Just load the known value on resume.

Yeah, so that's what my simple patch does.

> Here's my full-fledged half-asleep theory:
> 
> We suspend to RAM.  We resume.  DS and/or ES contains something unusual but not 
> unusual enough to crash us.  Our first entry to userspace is via SYSEXIT.  
> Because we're daft, we don't reload DS or ES at any point along the way.  Now 
> we're in userspace with an even more screwed up DS or ES than usual.  We get 
> SIGSEGV (presumably #GP) and try to deliver the signal.  We end up with 
> impossible pt_regs (bogus RPL) but who cares?  We get to __setup_frame, which 
> fixes the garbage in pt_regs and we re-enter user mode through an IRET patch, so 
> we finally reload DS and ES.  As a result, we successfully deliver the signal.  
> The saved regs would reveal the damage, but systemd throws them away, and we 
> remain confused for a full ten kernel versions.

That's indeed plausible.

If so then the DS reloading patch I sent should help.

So we should also do a full review of all the DS/ES save/restore paths, 
everywhere, as they don't seem to be very consistently done.

Thanks,

	Ingo

  reply	other threads:[~2015-06-12  7:15 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11 23:45 [PATCH] x86: General protection fault after STR (32 bit systems only) Srinivas Pandruvada
2015-06-12  6:07 ` Ingo Molnar
2015-06-12  6:48   ` Andy Lutomirski
2015-06-12  7:15     ` Ingo Molnar [this message]
2015-06-12  7:41   ` Andy Lutomirski
2015-06-12  7:50     ` Ingo Molnar
2015-06-12  8:15       ` H. Peter Anvin
2015-06-12  8:36         ` Ingo Molnar
2015-06-12 15:48           ` Brian Gerst
2015-06-12 18:11             ` Andy Lutomirski
2015-06-12 18:31               ` Srinivas Pandruvada
2015-06-13  7:00                 ` Ingo Molnar
2015-06-12 22:45             ` Denys Vlasenko
2015-06-13 14:20               ` Pavel Machek
2015-06-13  7:03             ` Ingo Molnar
2015-06-13 18:23               ` Andy Lutomirski
2015-06-13 21:30                 ` Brian Gerst
2015-06-14  6:56                   ` [PATCH] x86: Load __USER_DS into DS/ES after resume Ingo Molnar
2015-06-14  7:03                     ` Pavel Machek
     [not found]                     ` <CA+55aFzB9dYidEf_7Hs47FOF7WPPJnJQwj_RiwL--c5Gb1uqyw@mail.gmail.com>
2015-06-14  7:49                       ` [PATCH v2] " Ingo Molnar
2015-06-14  8:57                         ` Pavel Machek
2015-06-14 14:22                           ` Brian Gerst
2015-06-15 16:12                         ` Srinivas Pandruvada
2015-06-16  9:13                         ` Pavel Machek
2015-06-16 21:40                           ` Rafael J. Wysocki
2015-06-17  8:59                             ` x86: allow using different kernel version for 32-bit, too Pavel Machek
2015-06-18  9:13                             ` [PATCH v2] x86: Load __USER_DS into DS/ES after resume Ingo Molnar
2015-06-22 14:06                               ` Rafael J. Wysocki
2015-06-12 16:15   ` [PATCH] x86: General protection fault after STR (32 bit systems only) Srinivas Pandruvada
2015-06-13  7:15     ` [PATCH, DEBUG] x86/32: Add small delay after resume Ingo Molnar
2015-06-15 16:10       ` Srinivas Pandruvada
2015-06-16 21:33         ` H. Peter Anvin
2015-06-16 22:25           ` Srinivas Pandruvada
2015-06-17 16:33           ` Konrad Rzeszutek Wilk
2015-06-17 17:22             ` H. Peter Anvin
2015-06-17 18:29               ` Konrad Rzeszutek Wilk

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=20150612071507.GA6411@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mingo@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=rjw@rjwysocki.net \
    --cc=srinivas.pandruvada@linux.intel.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).