[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <afd939a0-c49d-c0e2-7d10-d65e18ea02ba@intel.com>
Date: Mon, 26 Apr 2021 11:00:58 -0700
From: "Yu, Yu-cheng" <yu-cheng.yu@...el.com>
To: "Kirill A. Shutemov" <kirill@...temov.name>
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@...nel.org>,
Balbir Singh <bsingharora@...il.com>,
Borislav Petkov <bp@...en8.de>,
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>,
Dave Martin <Dave.Martin@....com>,
Weijiang Yang <weijiang.yang@...el.com>,
Pengfei Xu <pengfei.xu@...el.com>,
Haitao Huang <haitao.huang@...el.com>,
"Kirill A . Shutemov" <kirill.shutemov@...ux.intel.com>
Subject: Re: [PATCH v25 30/30] mm: Introduce PROT_SHSTK for shadow stack
On 4/25/2021 11:52 PM, Kirill A. Shutemov wrote:
> On Thu, Apr 15, 2021 at 03:14:19PM -0700, Yu-cheng Yu wrote:
>> There are three possible options to create a shadow stack allocation API:
>> an arch_prctl, a new syscall, or adding PROT_SHSTK to mmap()/mprotect().
>> Each has its advantages and compromises.
>>
>> An arch_prctl() is the least intrusive. However, the existing x86
>> arch_prctl() takes only two parameters. Multiple parameters must be
>> passed in a memory buffer. There is a proposal to pass more parameters in
>> registers [1], but no active discussion on that.
>>
>> A new syscall minimizes compatibility issues and offers an extensible frame
>> work to other architectures, but this will likely result in some overlap of
>> mmap()/mprotect().
>>
>> The introduction of PROT_SHSTK to mmap()/mprotect() takes advantage of
>
> Maybe PROT_SHADOW_STACK?
>
>> existing APIs. The x86-specific PROT_SHSTK is translated to
>> VM_SHADOW_STACK and a shadow stack mapping is created without reinventing
>> the wheel. There are potential pitfalls though. The most obvious one
>> would be using this as a bypass to shadow stack protection. However, the
>> attacker would have to get to the syscall first.
>>
>> [1] https://lore.kernel.org/lkml/20200828121624.108243-1-hjl.tools@gmail.com/
>>
>> Signed-off-by: Yu-cheng Yu <yu-cheng.yu@...el.com>
>> Cc: Kees Cook <keescook@...omium.org>
>> Cc: Kirill A. Shutemov <kirill.shutemov@...ux.intel.com>
>> ---
>> v24:
>> - Update arch_calc_vm_prot_bits(), leave PROT* checking to
>> arch_validate_prot().
>> - Update arch_validate_prot(), leave vma flags checking to
>> arch_validate_flags().
>> - Add arch_validate_flags().
>>
>> arch/x86/include/asm/mman.h | 59 +++++++++++++++++++++++++++++++-
>> arch/x86/include/uapi/asm/mman.h | 1 +
>> include/linux/mm.h | 1 +
>> 3 files changed, 60 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
>> index 629f6c81263a..1821c179f35d 100644
>> --- a/arch/x86/include/asm/mman.h
>> +++ b/arch/x86/include/asm/mman.h
[...]
>> +
>> +#define arch_validate_prot arch_validate_prot
>> +
>> +static inline bool arch_validate_flags(unsigned long vm_flags, bool is_anon)
>> +{
>> + if (vm_flags & VM_SHADOW_STACK) {
>> + if ((vm_flags & VM_SHARED) || !is_anon)
>
> VM_SHARED check is redundant. vma_is_anonymous() should be enough.
> Anonymous shared mappings would fail vma_is_anonymous().
>
Thanks for looking into this. I will update and send another version.
Yu-cheng
Powered by blists - more mailing lists