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: <752c38422a6536d8df99b619214f935e4bc882ad.camel@intel.com>
Date:   Tue, 04 Dec 2018 09:08:11 -0800
From:   Yu-cheng Yu <yu-cheng.yu@...el.com>
To:     Borislav Petkov <bp@...en8.de>
Cc:     x86@...nel.org, "H. Peter Anvin" <hpa@...or.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Ingo Molnar <mingo@...hat.com>, linux-kernel@...r.kernel.org,
        linux-doc@...r.kernel.org, linux-mm@...ck.org,
        linux-arch@...r.kernel.org, linux-api@...r.kernel.org,
        Arnd Bergmann <arnd@...db.de>,
        Andy Lutomirski <luto@...capital.net>,
        Balbir Singh <bsingharora@...il.com>,
        Cyrill Gorcunov <gorcunov@...il.com>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Eugene Syromiatnikov <esyr@...hat.com>,
        Florian Weimer <fweimer@...hat.com>,
        "H.J. Lu" <hjl.tools@...il.com>, Jann Horn <jannh@...gle.com>,
        Jonathan Corbet <corbet@....net>,
        Kees Cook <keescook@...omium.org>,
        Mike Kravetz <mike.kravetz@...cle.com>,
        Nadav Amit <nadav.amit@...il.com>,
        Oleg Nesterov <oleg@...hat.com>, Pavel Machek <pavel@....cz>,
        Peter Zijlstra <peterz@...radead.org>,
        Randy Dunlap <rdunlap@...radead.org>,
        "Ravi V. Shankar" <ravi.v.shankar@...el.com>,
        Vedvyas Shanbhogue <vedvyas.shanbhogue@...el.com>
Subject: Re: [RFC PATCH v6 04/26] x86/fpu/xstate: Introduce XSAVES system
 states

On Tue, 2018-12-04 at 17:01 +0100, Borislav Petkov wrote:
> On Mon, Nov 19, 2018 at 01:47:47PM -0800, Yu-cheng Yu wrote:
> > Control-flow Enforcement (CET) MSR contents are XSAVES system states.
> > To support CET, introduce XSAVES system states first.
> > 
> > Signed-off-by: Yu-cheng Yu <yu-cheng.yu@...el.com>
> > ---
> >  arch/x86/include/asm/fpu/internal.h |  3 +-
> >  arch/x86/include/asm/fpu/xstate.h   |  4 +-
> >  arch/x86/kernel/fpu/core.c          |  6 +-
> >  arch/x86/kernel/fpu/init.c          | 10 ---
> >  arch/x86/kernel/fpu/xstate.c        | 94 +++++++++++++++++++----------
> >  5 files changed, 69 insertions(+), 48 deletions(-)
> 
> ...
> 
> > @@ -704,6 +710,7 @@ static int init_xstate_size(void)
> >   */
> >  static void fpu__init_disable_system_xstate(void)
> >  {
> > +	xfeatures_mask_all = 0;
> >  	xfeatures_mask_user = 0;
> >  	cr4_clear_bits(X86_CR4_OSXSAVE);
> >  	fpu__xstate_clear_all_cpu_caps();
> > @@ -717,6 +724,8 @@ void __init fpu__init_system_xstate(void)
> >  {
> >  	unsigned int eax, ebx, ecx, edx;
> >  	static int on_boot_cpu __initdata = 1;
> > +	u64 cpu_system_xfeatures_mask;
> > +	u64 cpu_user_xfeatures_mask;
> 
> So what I had in mind is to not have those local vars but use
> xfeatures_mask_user and xfeatures_mask_system here directly...

Ok, I will re-write it.

...

> >  
> > @@ -739,10 +748,23 @@ void __init fpu__init_system_xstate(void)
> >  		return;
> >  	}
> >  
> > +	/*
> > +	 * Find user states supported by the processor.
> > +	 * Only these bits can be set in XCR0.
> > +	 */
> >  	cpuid_count(XSTATE_CPUID, 0, &eax, &ebx, &ecx, &edx);
> > -	xfeatures_mask_user = eax + ((u64)edx << 32);
> > +	cpu_user_xfeatures_mask = eax + ((u64)edx << 32);
> >  
> > -	if ((xfeatures_mask_user & XFEATURE_MASK_FPSSE) !=
> > XFEATURE_MASK_FPSSE) {
> > +	/*
> > +	 * Find system states supported by the processor.
> > +	 * Only these bits can be set in IA32_XSS MSR.
> > +	 */
> > +	cpuid_count(XSTATE_CPUID, 1, &eax, &ebx, &ecx, &edx);
> > +	cpu_system_xfeatures_mask = ecx + ((u64)edx << 32);
> > +
> > +	xfeatures_mask_all = cpu_user_xfeatures_mask |
> > cpu_system_xfeatures_mask;
> 
> ... and not introduce xfeatures_mask_all at all but everywhere you need
> all features, to do:
> 
> 	(xfeatures_mask_user | xfeatures_mask_system)
> 
> and work with that.

Then we will do this very often.  Why don't we create all three in the
beginning: xfeatures_mask_all, xfeatures_mask_user, and xfeatures_mask_system?

> ...
> 
> > @@ -1178,7 +1208,7 @@ int copy_kernel_to_xstate(struct xregs_state *xsave,
> > const void *kbuf)
> >  	 * The state that came in from userspace was user-state only.
> >  	 * Mask all the user states out of 'xfeatures':
> >  	 */
> > -	xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR;
> > +	xsave->header.xfeatures &= (xfeatures_mask_all &
> > ~xfeatures_mask_user);
> 
> ... and this would be
> 
> 	xsave->header.xfeatures &= xfeatures_mask_system;

Yes.

> 
> >  
> >  	/*
> >  	 * Add back in the features that came in from userspace:
> > @@ -1234,7 +1264,7 @@ int copy_user_to_xstate(struct xregs_state *xsave,
> > const void __user *ubuf)
> >  	 * The state that came in from userspace was user-state only.
> >  	 * Mask all the user states out of 'xfeatures':
> >  	 */
> > -	xsave->header.xfeatures &= XFEATURE_MASK_SUPERVISOR;
> > +	xsave->header.xfeatures &= (xfeatures_mask_all &
> > ~xfeatures_mask_user);
> 
> Ditto here.
> 
> This way you have *two* mask variables and code queries them only.
> 
> Hmmm?
> 
> Or am I missing something?

We actually have three.

Yu-cheng

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ