lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 1 Aug 2023 14:08:27 +0200
From:   Borislav Petkov <bp@...en8.de>
To:     Ard Biesheuvel <ardb@...nel.org>
Cc:     linux-efi@...r.kernel.org, linux-kernel@...r.kernel.org,
        Evgeniy Baskov <baskov@...ras.ru>,
        Andy Lutomirski <luto@...nel.org>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Ingo Molnar <mingo@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Alexey Khoroshilov <khoroshilov@...ras.ru>,
        Peter Jones <pjones@...hat.com>,
        Gerd Hoffmann <kraxel@...hat.com>,
        Dave Young <dyoung@...hat.com>,
        Mario Limonciello <mario.limonciello@....com>,
        Kees Cook <keescook@...omium.org>,
        Tom Lendacky <thomas.lendacky@....com>,
        "Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Joerg Roedel <jroedel@...e.de>
Subject: Re: [PATCH v7 14/22] x86/decompressor: Merge trampoline cleanup with
 switching code

On Fri, Jul 28, 2023 at 11:09:08AM +0200, Ard Biesheuvel wrote:
> diff --git a/arch/x86/boot/compressed/pgtable_64.c b/arch/x86/boot/compressed/pgtable_64.c
> index 4016444e6788304f..4f50af23a0854f18 100644
> --- a/arch/x86/boot/compressed/pgtable_64.c
> +++ b/arch/x86/boot/compressed/pgtable_64.c
> @@ -101,9 +101,10 @@ static unsigned long find_trampoline_placement(void)
>  	return bios_start - TRAMPOLINE_32BIT_SIZE;
>  }
>  
> -asmlinkage void set_paging_levels(void *rmode)
> +asmlinkage void set_paging_levels(void *rmode, void *pgtable)

Please get rid of this silly rmode arg which gets passed in here as
boot_params and then gets assigned to an extern pointer to boot_params.
This is just silly. Just do what the other functions get from %r15 now
- a struct boot_params *bp arg.

But perhaps in a separate patch.

>  {
>  	void (*toggle_la57)(void *trampoline, bool enable_5lvl);
> +	void *trampoline_pgtable;
>  	bool l5_required = false;
>  
>  	/* Initialize boot_params. Required for cmdline_find_option_bool(). */
> @@ -133,7 +134,7 @@ asmlinkage void set_paging_levels(void *rmode)
>  	 * the desired one.
>  	 */
>  	if (l5_required == !!(native_read_cr4() & X86_CR4_LA57))
> -		return;
> +		goto out;
>  
>  	trampoline_32bit = (unsigned long *)find_trampoline_placement();
>  
> @@ -163,6 +164,8 @@ asmlinkage void set_paging_levels(void *rmode)
>  	 * The new page table will be used by trampoline code for switching
>  	 * from 4- to 5-level paging or vice versa.
>  	 */
> +	trampoline_pgtable = trampoline_32bit +
> +			     TRAMPOLINE_32BIT_PGTABLE_OFFSET / sizeof(unsigned long);
>  
>  	if (l5_required) {
>  		/*
> @@ -182,31 +185,21 @@ asmlinkage void set_paging_levels(void *rmode)
>  		 * may be above 4G.
>  		 */
>  		src = *(unsigned long *)__native_read_cr3() & PAGE_MASK;
> -		memcpy(trampoline_32bit + TRAMPOLINE_32BIT_PGTABLE_OFFSET / sizeof(unsigned long),
> -		       (void *)src, PAGE_SIZE);
> +		memcpy(trampoline_pgtable, (void *)src, PAGE_SIZE);
>  	}
>  
>  	toggle_la57(trampoline_32bit, l5_required);
> -}
> -
> -void cleanup_trampoline(void *pgtable)
> -{
> -	void *trampoline_pgtable;
> -
> -	trampoline_pgtable = trampoline_32bit + TRAMPOLINE_32BIT_PGTABLE_OFFSET / sizeof(unsigned long);
>  
>  	/*
> -	 * Move the top level page table out of trampoline memory,
> -	 * if it's there.
> +	 * Move the top level page table out of trampoline memory.
>  	 */
> -	if ((void *)__native_read_cr3() == trampoline_pgtable) {
> -		memcpy(pgtable, trampoline_pgtable, PAGE_SIZE);
> -		native_write_cr3((unsigned long)pgtable);
> -	}
> +	memcpy(pgtable, trampoline_pgtable, PAGE_SIZE);
> +	native_write_cr3((unsigned long)pgtable);
>  
>  	/* Restore trampoline memory */
>  	memcpy(trampoline_32bit, trampoline_save, TRAMPOLINE_32BIT_SIZE);
>  
> +out:
>  	/* Initialize variables for 5-level paging */
>  #ifdef CONFIG_X86_5LEVEL
>  	if (__read_cr4() & X86_CR4_LA57) {
> @@ -215,4 +208,5 @@ void cleanup_trampoline(void *pgtable)
>  		ptrs_per_p4d = 512;
>  	}
>  #endif
> +	return;

No need for that one. It'll return without it. :-)

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ