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:   Thu, 17 Jun 2021 14:22:11 +0200
From:   Borislav Petkov <bp@...e.de>
To:     Thomas Gleixner <tglx@...utronix.de>
Cc:     LKML <linux-kernel@...r.kernel.org>,
        Andy Lutomirski <luto@...nel.org>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Fenghua Yu <fenghua.yu@...el.com>,
        Tony Luck <tony.luck@...el.com>,
        Yu-cheng Yu <yu-cheng.yu@...el.com>,
        Sebastian Andrzej Siewior <bigeasy@...utronix.de>,
        Peter Zijlstra <peterz@...radead.org>,
        Kan Liang <kan.liang@...ux.intel.com>
Subject: Re: [patch V2 20/52] x86/fpu: Cleanup arch_set_user_pkey_access()

On Mon, Jun 14, 2021 at 05:44:28PM +0200, Thomas Gleixner wrote:
> The function is having a sanity check with a WARN_ON_ONCE() but happily

"The function does a sanity check..."

> proceeds when the pkey argument is out of range.
> 
> Clean it up.
> 
> Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
> ---
>  arch/x86/kernel/fpu/xstate.c |   11 ++++++-----
>  1 file changed, 6 insertions(+), 5 deletions(-)
> 
> --- a/arch/x86/kernel/fpu/xstate.c
> +++ b/arch/x86/kernel/fpu/xstate.c
> @@ -887,11 +887,10 @@ EXPORT_SYMBOL_GPL(get_xsave_addr);
>   * rights for @pkey to @init_val.
>   */
>  int arch_set_user_pkey_access(struct task_struct *tsk, int pkey,
> -		unsigned long init_val)
> +			      unsigned long init_val)
>  {
> -	u32 old_pkru;
> -	int pkey_shift = (pkey * PKRU_BITS_PER_PKEY);
> -	u32 new_pkru_bits = 0;
> +	u32 old_pkru, new_pkru_bits = 0;
> +	int pkey_shift;
>  
>  	/*
>  	 * This check implies XSAVE support.  OSPKE only gets

There's a boot_cpu_has() check

<--- here

Might wanna convert it to cpu_feature_enabled(), while at it.

> @@ -905,7 +904,8 @@ int arch_set_user_pkey_access(struct tas
>  	 * values originating from in-kernel users.  Complain
>  	 * if a bad value is observed.
>  	 */
> -	WARN_ON_ONCE(pkey >= arch_max_pkey());
> +	if (WARN_ON_ONCE(pkey >= arch_max_pkey()))
> +		return -EINVAL;
>  
>  	/* Set the bits we need in PKRU:  */
>  	if (init_val & PKEY_DISABLE_ACCESS)
> @@ -914,6 +914,7 @@ int arch_set_user_pkey_access(struct tas
>  		new_pkru_bits |= PKRU_WD_BIT;
>  
>  	/* Shift the bits in to the correct place in PKRU for pkey: */
> +	pkey_shift = pkey * PKRU_BITS_PER_PKEY;
>  	new_pkru_bits <<= pkey_shift;
>  
>  	/* Get old PKRU and mask off any old bits in place: */

With those addressed:

Reviewed-by: Borislav Petkov <bp@...e.de>

-- 
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ