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 for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <80094124.4887.1516231532603.JavaMail.zimbra@efficios.com>
Date:   Wed, 17 Jan 2018 23:25:32 +0000 (UTC)
From:   Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To:     Andy Lutomirski <luto@...nel.org>
Cc:     Ingo Molnar <mingo@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        linux-kernel <linux-kernel@...r.kernel.org>,
        linux-api <linux-api@...r.kernel.org>,
        "Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
        Boqun Feng <boqun.feng@...il.com>,
        Andrew Hunter <ahh@...gle.com>,
        maged michael <maged.michael@...il.com>,
        Avi Kivity <avi@...lladb.com>,
        Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        Paul Mackerras <paulus@...ba.org>,
        Michael Ellerman <mpe@...erman.id.au>,
        Dave Watson <davejwatson@...com>,
        "H. Peter Anvin" <hpa@...or.com>,
        Andrea Parri <parri.andrea@...il.com>,
        "Russell King, ARM Linux" <linux@...linux.org.uk>,
        Greg Hackmann <ghackmann@...gle.com>,
        Will Deacon <will.deacon@....com>,
        David Sehr <sehr@...gle.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        x86 <x86@...nel.org>, linux-arch <linux-arch@...r.kernel.org>
Subject: Re: [PATCH for 4.16 07/11] x86: Implement sync_core_before_usermode
 (v3)

----- On Jan 17, 2018, at 1:13 PM, Andy Lutomirski luto@...nel.org wrote:

> On Wed, Jan 17, 2018 at 10:10 AM, Mathieu Desnoyers
> <mathieu.desnoyers@...icios.com> wrote:
>> ----- On Jan 17, 2018, at 12:53 PM, Andy Lutomirski luto@...nel.org wrote:
>>
>>> On Wed, Jan 17, 2018 at 8:54 AM, Mathieu Desnoyers
>>> <mathieu.desnoyers@...icios.com> wrote:
>>>> Ensure that a core serializing instruction is issued before returning to
>>>> user-mode. x86 implements return to user-space through sysexit, sysrel,
>>>> and sysretq, which are not core serializing.
>>>>
>>>> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
>>>> Reviewed-by: Thomas Gleixner <tglx@...utronix.de>
>>>> CC: Peter Zijlstra <peterz@...radead.org>
>>>> CC: Andy Lutomirski <luto@...nel.org>
>>>> CC: Paul E. McKenney <paulmck@...ux.vnet.ibm.com>
>>>> CC: Boqun Feng <boqun.feng@...il.com>
>>>> CC: Andrew Hunter <ahh@...gle.com>
>>>> CC: Maged Michael <maged.michael@...il.com>
>>>> CC: Avi Kivity <avi@...lladb.com>
>>>> CC: Benjamin Herrenschmidt <benh@...nel.crashing.org>
>>>> CC: Paul Mackerras <paulus@...ba.org>
>>>> CC: Michael Ellerman <mpe@...erman.id.au>
>>>> CC: Dave Watson <davejwatson@...com>
>>>> CC: Ingo Molnar <mingo@...hat.com>
>>>> CC: "H. Peter Anvin" <hpa@...or.com>
>>>> CC: Andrea Parri <parri.andrea@...il.com>
>>>> CC: Russell King <linux@...linux.org.uk>
>>>> CC: Greg Hackmann <ghackmann@...gle.com>
>>>> CC: Will Deacon <will.deacon@....com>
>>>> CC: David Sehr <sehr@...gle.com>
>>>> CC: Linus Torvalds <torvalds@...ux-foundation.org>
>>>> CC: x86@...nel.org
>>>> CC: linux-arch@...r.kernel.org
>>>> ---
>>>> Changes since v1:
>>>> - Fix prototype of sync_core_before_usermode in generic code (missing
>>>>   return type).
>>>> - Add linux/processor.h include to sched/core.c.
>>>> - Add ARCH_HAS_SYNC_CORE_BEFORE_USERMODE to init/Kconfig.
>>>> - Fix linux/processor.h ifdef to target
>>>>   CONFIG_ARCH_HAS_SYNC_CORE_BEFORE_USERMODE rather than
>>>>   ARCH_HAS_SYNC_CORE_BEFORE_USERMODE.
>>>> - Move empty static inline in processor.h to generic patch.
>>>> ---
>>>>  arch/x86/Kconfig                 |  1 +
>>>>  arch/x86/include/asm/processor.h | 10 ++++++++++
>>>>  2 files changed, 11 insertions(+)
>>>>
>>>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
>>>> index 20da391b5f32..0b44c8dd0e95 100644
>>>> --- a/arch/x86/Kconfig
>>>> +++ b/arch/x86/Kconfig
>>>> @@ -61,6 +61,7 @@ config X86
>>>>         select ARCH_HAS_SG_CHAIN
>>>>         select ARCH_HAS_STRICT_KERNEL_RWX
>>>>         select ARCH_HAS_STRICT_MODULE_RWX
>>>> +       select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE
>>>>         select ARCH_HAS_UBSAN_SANITIZE_ALL
>>>>         select ARCH_HAS_ZONE_DEVICE             if X86_64
>>>>         select ARCH_HAVE_NMI_SAFE_CMPXCHG
>>>> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
>>>> index d3a67fba200a..3257d34dbb40 100644
>>>> --- a/arch/x86/include/asm/processor.h
>>>> +++ b/arch/x86/include/asm/processor.h
>>>> @@ -722,6 +722,16 @@ static inline void sync_core(void)
>>>>  #endif
>>>>  }
>>>>
>>>> +/*
>>>> + * Ensure that a core serializing instruction is issued before returning
>>>> + * to user-mode. x86 implements return to user-space through sysexit,
>>>> + * sysrel, and sysretq, which are not core serializing.
>>>> + */
>>>> +static inline void sync_core_before_usermode(void)
>>>> +{
>>>
>>> /* With PTI, we unconditionally serialize before running user code. */
>>> if (static_cpu_has(X86_FEATURE_PTI))
>>>  return;
>>
>> One issue I'm facing with this change is header dependency:
>> sync_core_before_usermode() is currently implemented in
>> arch/x86/include/asm/processor.h, but arch/x86/include/asm/cpufeature.h
>> is needed for static_cpu_has, and it happens to include
>> asm/processor.h.
>>
>> I'm facing a similar issue for adding a (in_irq() || in_nmi()) check.
>>
>> Should we move sync_core_before_usermode() to a different header, and if
>> so, any suggestion ?
> 
> tlbflush.h, maybe?

Core serialization seems to be unrelated to TLB flushing though.

I'm considering to create those new header files:

include/asm-generic/sync_core.h (empty function)
arch/x86/include/asm/sync_core.h

for the sync_core_before_usermode() static inlines. Any better idea ?

Thanks,

Mathieu


> 
>>
>> Thanks,
>>
>> Mathieu
>>
>>
>>
>>>
>>>> +       sync_core();
>>>> +}
>>>
>>> --Andy
>>
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
> > http://www.efficios.com

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ