[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <7fa20642-4841-30b4-2ced-828f34a6d397@intel.com>
Date: Wed, 1 Sep 2021 08:24:27 -0700
From: Dave Hansen <dave.hansen@...el.com>
To: Borislav Petkov <bp@...en8.de>
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
On 9/1/21 6:00 AM, Borislav Petkov wrote:
>> 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...
Ahh, good point. I totally missed the signal side.
Yu-cheng, it would probably be wise to take a look at where
TIF_NEED_FPU_LOAD is set in the signal paths. I suspect the new shadow
stack code is clearing it pretty quickly. That's not *necessarily* a
waste because it has to be XRSTOR'd somewhere before returning to
userspace. But, it does impose an extra XSAVE/XRSTOR burden if the code
is preempted somewhere between
setup_signal_shadow_stack()/restore_signal_shadow_stack() and the return
to usersspace.
Some performance numbers would be nice.
Even nicer would be to make your code work without requiring
TIF_NEED_FPU_LOAD to be clear, or actively clearing it.
Powered by blists - more mailing lists