All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Ingo Molnar <mingo@kernel.org>
Cc: Dave Hansen <dave.hansen@intel.com>,
	Changbin Du <changbin.du@gmail.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Andy Lutomirski <luto@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/mm: determine whether the fault address is canonical
Date: Mon, 7 Oct 2019 08:13:23 -0700	[thread overview]
Message-ID: <20191007151323.GB18016@linux.intel.com> (raw)
In-Reply-To: <20191007144423.GA25181@gmail.com>

On Mon, Oct 07, 2019 at 04:44:23PM +0200, Ingo Molnar wrote:
> 
> * Ingo Molnar <mingo@kernel.org> wrote:
> 
> > > All the other reasons would require a fairly egregious kernel bug, hence
> > > the speculation that the #GP is due to a non-canonical address.  Something
> > > like the following would be more precise, though highly unlikely to ever
> > > be exercised, e.g. KVM had a fatal bug related to injecting a non-zero
> > > error code that went unnoticed for years.
> > > 
> > > 	WARN_ONCE(trapnr == X86_TRAP_GP, "General protection fault in user access. %s?\n",
> > > 		  (IS_ENABLED(CONFIG_X86_64) && !error_code) ? "Non-canonical address" :
> > > 		  					       "Segmentation bug");
> > 
> > Instead of trying to guess the reason of the #GPF (which guess might be 
> > wrong), please just state it as the reason if we are sure that the cause 
> > is a non-canonical address - and provide a best-guess if it's not but 
> > clearly signal that it's a guess.
> > 
> > I.e. if I understood all the cases correctly we'd have three types of 
> > messages generated:
> > 
> >  !error_code:
> > 	"General protection fault in user access, due to non-canonical address."

A non-canonical #GP always has an error code of '0', but the reverse isn't
technically true.  And 32-bit mode obviously can't generate a non-canonical
address.

But practically speaking, since _ASM_EXTABLE_UA() should only be used for
reg<->mem instructions, the only way to get a #GP on a usercopy instruction
would be to corrupt the code itself or have a bad segment loaded in 32-bit
mode.  So qualifying the non-canonical message on '64-bit && !error_code'
is techncally more precise/correct, but likely meaningless in practice.

> >  error_code && !is_canonical_addr(fault_addr):
> > 	"General protection fault in user access. Non-canonical address?"
> > 
> >  error_code && is_canonical_addr(fault_addr):
> > 	"General protection fault in user access. Segmentation bug?"
> 
> Now that I've read the rest of the thread, since fault_addr is always 0 
> we can ignore most of this I suspect ...

  reply	other threads:[~2019-10-07 15:13 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-04 13:45 [PATCH] x86/mm: determine whether the fault address is canonical Changbin Du
2019-10-04 14:39 ` Dave Hansen
2019-10-04 15:31   ` Sean Christopherson
2019-10-07 14:32     ` Ingo Molnar
2019-10-07 14:44       ` Ingo Molnar
2019-10-07 15:13         ` Sean Christopherson [this message]
2019-10-04 14:59 ` Andy Lutomirski
2019-10-04 15:14   ` Dave Hansen
2019-10-06  2:29     ` Changbin Du

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=20191007151323.GB18016@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=changbin.du@gmail.com \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.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 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.