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:   Wed, 1 Sep 2021 15:00:07 +0200
From:   Borislav Petkov <bp@...en8.de>
To:     Dave Hansen <dave.hansen@...el.com>
Cc:     "Yu, Yu-cheng" <yu-cheng.yu@...el.com>, 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@...nel.org>,
        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>,
        Dave Martin <Dave.Martin@....com>,
        Weijiang Yang <weijiang.yang@...el.com>,
        Pengfei Xu <pengfei.xu@...el.com>,
        Haitao Huang <haitao.huang@...el.com>,
        Rick P Edgecombe <rick.p.edgecombe@...el.com>
Subject: Re: [PATCH v29 23/32] x86/cet/shstk: Add user-mode shadow stack
 support

First of all,

thanks a lot Dave for taking the time to communicate properly with me!

On Fri, Aug 27, 2021 at 01:25:29PM -0700, Dave Hansen wrote:
> I don't think this has anything to do with context-switching, really.
> 
> The code lands in shstk_setup() which wants to make sure that the new
> MSR values are set before the task goes out to userspace.  If
> TIF_NEED_FPU_LOAD was set, it could do that by going out to the XSAVE
> buffer and setting the MSR state in the buffer.  Before returning to
> userspace, it would be XRSTOR'd.  A WRMSR by itself would not be
> persistent because that XRSTOR would overwrite it.
> 
> But, if TIF_NEED_FPU_LOAD is *clear* it means the XSAVE buffer is
> out-of-date and the registers are live.  WRMSR can be used and there
> will be a XSAVE* to the task buffer during a context switch.
> 
> So, this code takes the coward's way out: it *forces* TIF_NEED_FPU_LOAD
> to be clear by making the registers live with fpregs_restore_userregs().
>  That lets it just use WRMSR instead of dealing with the XSAVE buffer
> directly.  If it didn't do this with the *WHOLE* set of user FPU state,
> we'd need more fine-granted "NEED_*_LOAD" tracking than our one FPU bit.
> 
> This is also *only* safe because the task is newly-exec()'d and the FPU
> state was just reset.  Otherwise, we might have had to worry that the
> non-PL3 SSPs have garbage or that non-SHSTK bits are set in MSR_IA32_U_CET.
> 
> That said, after staring at it, I *think* this code is functionally
> correct and OK performance-wise.

Right, except that that is being done in
setup_signal_shadow_stack()/restore_signal_shadow_stack() too, for the
restore token.

Which means, a potential XRSTOR each time just for a single MSR. That
means, twice per signal in the worst case.

Which means, shadow stack should be pretty noticeable in signal-heavy
benchmarks...

> I suspect that the (very blunt) XRSTOR inside of
> start_update_msrs()->fpregs_restore_userregs() is quite rare because
> TIF_NEED_FPU_LOAD will usually be clear due to the proximity to
> execve(). So, adding direct XSAVE buffer manipulation would probably
> only make it more error prone.

@Yu-cheng: please take Dave's explanation as is and stick it over
start_update_msrs() so that it is clear what that thing is doing.

Thx.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ