Re: x86: pgtable / kaslr initialisation (OOB) help

From: Dave Hansen
Date: Wed Jun 14 2023 - 10:45:31 EST


On 6/14/23 07:37, Lee Jones wrote:
> Still unsure how we (the kernel) can/should write to an area of memory
> that does not belong to it. Should we allocate enough memory
> (2*PAGE_SIZE? rather than 8-Bytes) for trampoline_pgd_entry to consume
> in a more sane way?

No.

I think this:

set_pgd(&trampoline_pgd_entry,
__pgd(_KERNPG_TABLE | __pa(p4d_page_tramp)));

is bogus-ish. set_pgd() wants to operate on a pgd_t inside a pgd
*PAGE*. But it's just being pointed at a single _entry_. The address
of 'trampoline_pgd_entry' in your case also just (unfortunately)
happens to pass the:

__pti_set_user_pgtbl -> pgdp_maps_userspace()

test. I _think_ we want these to just be something like:

trampoline_pgd_entry = __pgd(_KERNPG_TABLE |
__pa(p4d_page_tramp);

That'll keep us away from all of the set_pgd()-induced nastiness.