Re: [patch 35/60] x86/espfix: Ensure that ESPFIX is visible in user PGD

From: Andy Lutomirski
Date: Mon Dec 04 2017 - 17:29:14 EST


On Mon, Dec 4, 2017 at 6:07 AM, Thomas Gleixner <tglx@xxxxxxxxxxxxx> wrote:
> From: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
>
> Clone the ESPFIX alias mapping area so the entry/exit code has access to it
> even with the user space page tables.
>
> [ tglx: Remove the per cpu user mapped oddity ]
>
> Signed-off-by: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>
> ---
> arch/x86/kernel/espfix_64.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> --- a/arch/x86/kernel/espfix_64.c
> +++ b/arch/x86/kernel/espfix_64.c
> @@ -129,6 +129,22 @@ void __init init_espfix_bsp(void)
> p4d = p4d_alloc(&init_mm, pgd, ESPFIX_BASE_ADDR);
> p4d_populate(&init_mm, p4d, espfix_pud_page);
>
> + /*
> + * Just copy the top-level PGD that is mapping the espfix area to
> + * ensure it is mapped into the user page tables.
> + *
> + * For 5-level paging, the espfix pgd was populated when
> + * kpti_init() pre-populated all the pgd entries. The above
> + * p4d_alloc() would never do anything and the p4d_populate() would
> + * be done to a p4d already mapped in the userspace pgd.
> + */

Is this actually true? From brief inspection, it doesn't seem to be
the case, nor do I see why it should be true.

> +#ifdef CONFIG_KERNEL_PAGE_TABLE_ISOLATION
> + if (CONFIG_PGTABLE_LEVELS <= 4) {
> + set_pgd(kernel_to_user_pgdp(pgd),
> + __pgd(_KERNPG_TABLE | (p4d_pfn(*p4d) << PAGE_SHIFT)));
> + }
> +#endif
> +
> /* Randomize the locations */
> init_espfix_random();
>
>
>