[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e1122e1d77dec0d5f0a698c855833050c740a4bc.camel@intel.com>
Date: Wed, 25 Mar 2020 14:51:13 -0700
From: Yu-cheng Yu <yu-cheng.yu@...el.com>
To: Kees Cook <keescook@...omium.org>
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>,
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>, x86-patch-review@...el.com
Subject: Re: [RFC PATCH v9 25/27] x86/cet/shstk: Handle thread Shadow Stack
On Tue, 2020-02-25 at 13:29 -0800, Kees Cook wrote:
> On Wed, Feb 05, 2020 at 10:19:33AM -0800, Yu-cheng Yu wrote:
> > [...]
> > A 64-bit SHSTK has a fixed size of RLIMIT_STACK. A compat-mode thread SHSTK
> > has a fixed size of 1/4 RLIMIT_STACK. This allows more threads to share a
> > 32-bit address space.
>
> I am not understanding this part. :) Entries are sizeof(unsigned long),
> yes? A 1/2 RLIMIT_STACK would cover 32-bit, but 1/4 is less, so why does
> that provide for more threads?
Each thread has a separate shadow stack. If each shadow stack is smaller, the
address space can accommodate more shadow stack allocations.
> >[...]
> > diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c
> > index cba5c7656aab..5b45abda80a1 100644
> > --- a/arch/x86/kernel/cet.c
> > +++ b/arch/x86/kernel/cet.c
> > @@ -170,6 +170,47 @@ int cet_setup_shstk(void)
> > return 0;
> > }
> >
> > +int cet_setup_thread_shstk(struct task_struct *tsk)
> > +{
> > + unsigned long addr, size;
> > + struct cet_user_state *state;
> > + struct cet_status *cet = &tsk->thread.cet;
> > +
> > + if (!cet->shstk_enabled)
> > + return 0;
> > +
> > + state = get_xsave_addr(&tsk->thread.fpu.state.xsave,
> > + XFEATURE_CET_USER);
> > +
> > + if (!state)
> > + return -EINVAL;
> > +
> > + size = rlimit(RLIMIT_STACK);
>
> Is SHSTK incompatible with RLIM_INFINITY stack rlimits?
I will change it to:
size = min(rlimit(RLIMIT_STACK), 4 GB);
>
> > +
> > + /*
> > + * Compat-mode pthreads share a limited address space.
> > + * If each function call takes an average of four slots
> > + * stack space, we need 1/4 of stack size for shadow stack.
> > + */
> > + if (in_compat_syscall())
> > + size /= 4;
> > +
> > + addr = alloc_shstk(size);
>
> I assume it'd fail here, but I worry about Stack Clash style attacks.
> I'd like to see test cases that make sure the SHSTK gap is working
> correctly.
I will work on some tests.
Thanks,
Yu-cheng
Powered by blists - more mailing lists