Re: Linux 6.11-rc1

From: Peter Zijlstra
Date: Wed Jul 31 2024 - 12:51:20 EST


On Wed, Jul 31, 2024 at 06:31:05PM +0200, Peter Zijlstra wrote:
> On Wed, Jul 31, 2024 at 09:17:44AM -0700, Linus Torvalds wrote:
> > On Wed, 31 Jul 2024 at 08:55, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> > >
> > > Right, so Thomas found that i386-pti fails to map the entire entry text.
> > > Specifically pti_clone_pgtable() hard relies -- and does not verify --
> > > that the start address is aligned to the given granularity.
> > >
> > > Now, i386 does not align __entry_text_start, and so the termination
> > > condition goes sideways and pte_clone_entry() does not always work right
> > > and it becomes a games of code layout roulette.
> >
> > Lovely.
>
> :-)
>
> This fixes the alignment assumptions and makes it all go again.

Thomas, this all still relies on the full text section being PMD mapped,
and since we don't have ALIGN_ENTRY_TEXT_END and _etext has PAGE_SIZE
alignment, can't have a PAGE mapped tail which then doesn't get cloned?

Do we want to make pto_clone_entry_text() use PTI_LEVEL_KERNEL_IMAGE
such that it will clone whatever it has?

> diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
> index 2e69abf4f852..bfdf5f45b137 100644
> --- a/arch/x86/mm/pti.c
> +++ b/arch/x86/mm/pti.c
> @@ -374,14 +374,14 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
> */
> *target_pmd = *pmd;
>
> - addr += PMD_SIZE;
> + addr = round_up(addr + 1, PMD_SIZE);
>
> } else if (level == PTI_CLONE_PTE) {
>
> /* Walk the page-table down to the pte level */
> pte = pte_offset_kernel(pmd, addr);
> if (pte_none(*pte)) {
> - addr += PAGE_SIZE;
> + addr = round_up(addr + 1, PAGE_SIZE);
> continue;
> }
>
> @@ -401,7 +401,7 @@ pti_clone_pgtable(unsigned long start, unsigned long end,
> /* Clone the PTE */
> *target_pte = *pte;
>
> - addr += PAGE_SIZE;
> + addr = round_up(addr + 1, PAGE_SIZE);
>
> } else {
> BUG();