mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave.hansen@intel.com>
To: Andy Lutomirski <luto@kernel.org>, x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Borislav Petkov <bp@alien8.de>,
	Brian Gerst <brgerst@gmail.com>,
	David Laight <David.Laight@aculab.com>,
	Kees Cook <keescook@chromium.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [RFC PTI 1/3] x86/pti: Vastly simplify pgd synchronization
Date: Fri, 8 Dec 2017 12:17:34 -0800	[thread overview]
Message-ID: <155be67c-e0b8-2416-8631-91936284216a@intel.com> (raw)
In-Reply-To: <66878233e09ff325b018e1bc5a521e9b20c58214.1512763129.git.luto@kernel.org>

>From a high level, what finally allowed this to happen?  Because
kpti_add_user_map() all went away, including the LDT one?


> +	if (pgdp_maps_userspace(pgdp)) {
>  		/*
> +		 * The user page tables get the full PGD,
> +		 * accessible from userspace:
>  		 */
> +		kernel_to_user_pgdp(pgdp)->pgd = pgd.pgd;
> +
> +		/*
> +		 * If this is normal user memory, make it NX in the kernel
> +		 * pagetables so that, if we somehow screw up and return to
> +		 * usermode with the kernel CR3 loaded, we'll get a page
> +		 * fault instead of allowing user code to execute with
> +		 * the wrong CR3.
> +		 *
> +		 * As exceptions, we don't set NX if:
> +		 *  - this is EFI or similar, the kernel may execute from it
> +		 *  - we don't have NX support
> +		 *  - we're clearing the PGD (i.e. pgd.pgd == 0).
> +		 */
> +		if ((pgd.pgd & _PAGE_USER) && (__supported_pte_mask & _PAGE_NX))
> +			pgd.pgd |= _PAGE_NX;

I scratched my head for a sec to realize why you didn't need an explicit
pgd.pgd==0 check.  It's part of the _PAGE_USER check, which is a bit
confusing.  Could we do:

if ((pgd.pgd & (_PAGE_USER|_PAGE_PRESENT)) &&
    (__supported_pte_mask & _PAGE_NX))

And change the comment:

	 * As exceptions, we don't set NX fo:
	 *  - PGDs without _PAGE_USER:  Assume this is for a weird in-kernel
	 *    user like EFI from which we may need to execute.
	 *  - PGDs withoout _PAGE_PRESENT: PGD is being cleared, must
	 *    not set _PAGE_NX
	 *  - we don't have NX support





>  	} else {
>  		/*
> +		 * Changes to the high (kernel) portion of the kernelmode
> +		 * page tables are not automatically propagated to the
> +		 * usermode tables.
> +		 *
> +		 * Users should keep in mind that, unlike the kernelmode
> +		 * tables, there is no vmalloc_fault equivalent for the
> +		 * usermode tables.  Top-level entries added to init_mm's
> +		 * usermode pgd after boot will not be automatically
> +		 * propagated to other mms.
>  		 */
> -		WARN_ON_ONCE(system_state == SYSTEM_RUNNING);
>  	}
>  #endif

How does the VSYSCALL page get into the user page tables now?

  reply	other threads:[~2017-12-08 20:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 19:59 [RFC PTI 0/3] Clean up pgd handling and fix VSYSCALL and LDT Andy Lutomirski
2017-12-08 19:59 ` [RFC PTI 1/3] x86/pti: Vastly simplify pgd synchronization Andy Lutomirski
2017-12-08 20:17   ` Dave Hansen [this message]
2017-12-08 20:49     ` Andy Lutomirski
2017-12-08 20:48       ` Dave Hansen
2017-12-08 19:59 ` [RFC PTI 2/3] Revert "x86/mm/pti: Disable native VSYSCALL" Andy Lutomirski
2017-12-08 19:59 ` [RFC PTI 3/3] x86/pti: Put the LDT in its own PGD if PTI is on Andy Lutomirski
2017-12-08 21:48   ` Thomas Gleixner

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=155be67c-e0b8-2416-8631-91936284216a@intel.com \
    --to=dave.hansen@intel.com \
    --cc=David.Laight@aculab.com \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.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

all inboxes | Powered by JetHome®