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]
Message-ID: <20231117094103.GM8262@noisy.programming.kicks-ass.net>
Date:   Fri, 17 Nov 2023 10:41:03 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Uros Bizjak <ubizjak@...il.com>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...nel.org>, Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>, kirill.shutemov@...ux.intel.com
Subject: Re: [PATCH -tip] x86/mm: Use %RIP-relative address in untagged_addr()

On Thu, Nov 16, 2023 at 08:10:59PM +0100, Uros Bizjak wrote:
> %RIP-relative addresses are nowadays correctly handled in alternative
> instructions, so remove misleading comment and improve assembly to
> use %RIP-relative address.

Ha!, it might've been this exact case (and Kirill grumbling) that got me
to fix the alternative code :-)

> Also, explicitly using %gs: prefix will segfault for non-SMP builds.
> Use macros from percpu.h which will DTRT with segment prefix register
> as far as SMP/non-SMP builds are concerned.

> Signed-off-by: Uros Bizjak <ubizjak@...il.com>

Acked-byL Peter Zijlstra (Intel) <peterz@...radaed.org>

> ---
>  arch/x86/include/asm/uaccess_64.h | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
> index f2c02e4469cc..01455c0b070c 100644
> --- a/arch/x86/include/asm/uaccess_64.h
> +++ b/arch/x86/include/asm/uaccess_64.h
> @@ -11,6 +11,7 @@
>  #include <asm/alternative.h>
>  #include <asm/cpufeatures.h>
>  #include <asm/page.h>
> +#include <asm/percpu.h>
>  
>  #ifdef CONFIG_ADDRESS_MASKING
>  /*
> @@ -18,14 +19,10 @@
>   */
>  static inline unsigned long __untagged_addr(unsigned long addr)
>  {
> -	/*
> -	 * Refer tlbstate_untag_mask directly to avoid RIP-relative relocation
> -	 * in alternative instructions. The relocation gets wrong when gets
> -	 * copied to the target place.
> -	 */
>  	asm (ALTERNATIVE("",
> -			 "and %%gs:tlbstate_untag_mask, %[addr]\n\t", X86_FEATURE_LAM)
> -	     : [addr] "+r" (addr) : "m" (tlbstate_untag_mask));
> +			 "and " __percpu_arg([mask]) ", %[addr]", X86_FEATURE_LAM)
> +	     : [addr] "+r" (addr)
> +	     : [mask] "m" (__my_cpu_var(tlbstate_untag_mask)));
>  
>  	return addr;
>  }
> -- 
> 2.41.0
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ