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: <12147db9-e975-268f-55ee-247868e0e0d8@amd.com>
Date:   Tue, 9 Jan 2018 17:01:10 -0600
From:   Tom Lendacky <thomas.lendacky@....com>
To:     Thomas Gleixner <tglx@...utronix.de>
Cc:     x86@...nel.org, linux-kernel@...r.kernel.org,
        Rik van Riel <riel@...hat.com>,
        Andi Kleen <ak@...ux.intel.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Jiri Kosina <jikos@...nel.org>,
        Dan Williams <dan.j.williams@...el.com>,
        Dave Hansen <dave.hansen@...el.com>,
        Borislav Petkov <bp@...en8.de>,
        Andy Lutomirski <luto@...nel.org>,
        Kees Cook <keescook@...gle.com>,
        Tim Chen <tim.c.chen@...ux.intel.com>,
        Greg Kroah-Hartman <gregkh@...ux-foundation.org>,
        David Woodhouse <dwmw@...zon.co.uk>,
        Paul Turner <pjt@...gle.com>
Subject: Re: [PATCH v1 1/2] x86/retpoline: Add a function to clear the
 RETPOLINE_AMD feature

On 1/9/2018 4:46 PM, Thomas Gleixner wrote:
> On Tue, 9 Jan 2018, Tom Lendacky wrote:
>> For AMD hardware, the RETPOLINE_AMD feature is dependent on LFENCE being
>> a serializing instruction.  Create a function to allow RETPOLINE_AMD to
>> be cleared if it cannot be determined that LFENCE is serializing. In
>> addition, update the spectre_v2_enabled variable so that sysfs output is
>> correct.
>>
>> Signed-off-by: Tom Lendacky <thomas.lendacky@....com>
>> ---
>>  arch/x86/include/asm/nospec-branch.h |    1 +
>>  arch/x86/kernel/cpu/bugs.c           |   10 ++++++++++
>>  2 files changed, 11 insertions(+)
>>
>> diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
>> index 8ddf851..5785684 100644
>> --- a/arch/x86/include/asm/nospec-branch.h
>> +++ b/arch/x86/include/asm/nospec-branch.h
>> @@ -153,6 +153,7 @@
>>  #endif
>>  
>>  void spectre_v2_check_boottime_disable(void);
>> +void retpoline_amd_disable(void);
>>  
>>  #endif /* __ASSEMBLY__ */
>>  #endif /* __NOSPEC_BRANCH_H__ */
>> diff --git a/arch/x86/kernel/cpu/bugs.c b/arch/x86/kernel/cpu/bugs.c
>> index b957f77..a4c594c 100644
>> --- a/arch/x86/kernel/cpu/bugs.c
>> +++ b/arch/x86/kernel/cpu/bugs.c
>> @@ -170,6 +170,16 @@ void __init spectre_v2_check_boottime_disable(void)
>>  	return;
>>  }
>>  
>> +void retpoline_amd_disable(void)
>> +{
>> +	if (!boot_cpu_has(X86_FEATURE_RETPOLINE_AMD))
>> +		return;
>> +
>> +	setup_clear_cpu_cap(X86_FEATURE_RETPOLINE_AMD);
>> +	spectre_v2_enabled = retp_compiler() ?
>> +		SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL;
>> +}
> 
> Urgh. That's an awful hack. why not do the obvious?

My first attempt was very similar to your change below, but testing
showed that spectre_v2_check_boottime_disable() is called before the
X86_FEATURE_LFENCE_RDTSC can be set.  I can look at moving where the
X86_FEATURE_LFENCE_RDTSC is set, maybe into early_init_amd() or such
if you think that would be best.

Thanks,
Tom

> 
> Thanks,
> 
> 	tglx
> 
> --- a/arch/x86/kernel/cpu/bugs.c
> +++ b/arch/x86/kernel/cpu/bugs.c
> @@ -148,14 +148,21 @@ void __init spectre_v2_check_boottime_di
>  retpoline:
>  	if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
>  	retpoline_amd:
> +		if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD ||
> +		    !boot_cpu_has(X86_FEATURE_LFENCE_RDTSC)) {
> +			pr_info("AMD retpoline not supported, fall back to generic\n");
> +			goto retpoline_generic;
> +		}
> +
>  		spectre_v2_enabled = retp_compiler() ?
>  			SPECTRE_V2_RETPOLINE_AMD : SPECTRE_V2_RETPOLINE_MINIMAL_AMD;
>  		setup_force_cpu_cap(X86_FEATURE_RETPOLINE_AMD);
> -	} else {
> -	retpoline_generic:
> -		spectre_v2_enabled = retp_compiler() ?
> -			SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL;
> +		setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
> +		return;
>  	}
> +retpoline_generic:
> +	spectre_v2_enabled = retp_compiler() ?
> +		SPECTRE_V2_RETPOLINE_GENERIC : SPECTRE_V2_RETPOLINE_MINIMAL;
>  	setup_force_cpu_cap(X86_FEATURE_RETPOLINE);
>  	return;
>  #else
> 
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ