Re: [PATCH 06/10] x86/cet: Add arch_prctl functions for shadow stack

From: Yu-cheng Yu
Date: Thu Jun 21 2018 - 19:10:58 EST


On Tue, 2018-06-19 at 17:50 -0700, Andy Lutomirski wrote:
>
> >
> > On Jun 19, 2018, at 3:38 PM, Yu-cheng Yu <yu-cheng.yu@xxxxxxxxx>
> > wrote:
> >
> > On Tue, 2018-06-19 at 13:47 -0700, Andy Lutomirski wrote:
> > >
> > > >
> > > >
> > > > On Jun 19, 2018, at 1:12 PM, Kees Cook <keescook@xxxxxxxxxxxx>
> > > > wrote:
> > > >
> > > > >
> > > > >
> > > > > On Tue, Jun 19, 2018 at 10:20 AM, Andy Lutomirski <luto@amaca
> > > > > pita
> > > > > l.net> wrote:
> > > > >
> > > > > >
> > > > > >
> > > > > > On Jun 19, 2018, at 10:07 AM, Kees Cook <keescook@chromium.
> > > > > > org>
> > > > > > wrote:
> > > > > >
> > > > > > Does it provide anything beyond what PR_DUMPABLE does?
> > > > > What do you mean?
> > > > I was just going by the name of it. I wasn't sure what "ptrace
> > > > CET
> > > > lock" meant, so I was trying to understand if it was another
> > > > "you
> > > > can't ptrace me" toggle, and if so, wouldn't it be redundant
> > > > with
> > > > PR_SET_DUMPABLE = 0, etc.
> > > >
> > > No, other way around. The valid CET states are on/unlocked,
> > > off/unlocked, on/locked, off/locked. arch_prctl can freely the
> > > state
> > > unless locked. ptrace can change it no matter what.ÂÂThe lock is
> > > to
> > > prevent the existence of a gadget to disable CET (unless the
> > > gadget
> > > involves ptrace, but I donât think thatâs a real concern).
> > We have the arch_prctl now and only need to add ptrace lock/unlock.
> >
> > Back to the dlopen() "relaxed" mode. Would the following work?
> >
> > If the lib being loaded does not use setjmp/getcontext families
> > (the
> > loader knows?), then the loader leaves shstk on.ÂÂ
> Will that actually work?ÂÂAre there libs that do something like
> longjmp without actually using the glibc longjmp routine?ÂÂWhat about
> compilers that statically match a throw to a catch and try to return
> through several frames at once?
>

The compiler throw/catch is already handled similarly to how longjmp is
handled.

To summarize the dlopen() situation,

----
(1) We don't want to fall back like the following. ÂOne reason is
turning off SHSTK for threads is tricky.

if ((dlopen() a legacy library) && (cet_policy==relaxed)) {
/*
Â* We don't care if the library will actually fault;
Â* just turn off CET protection now.
Â*/
Turn off CET;
}

(2) We cannot predict what version of a library will be dlopen'ed, and
cannot turn off CET reliably from the beginning of an application.
----

Can we mandate a signal handler (to turn off CET) when ((dlopen is used
) && (cet_policy==relaxed))?

> >
> > Otherwise, if the
> > system-wide setting is "relaxed", the loader turns off shstk and
> > issues
> > a warning.ÂÂIn addition, if (dlopen == relaxed), then cet is not
> > locked
> > in any time.
> >
> > The system-wide setting (somewhere in /etc?) can be:
> >
> > ÂÂÂdlopen=force|relaxed /* controls dlopen of non-cet libs */
> > ÂÂÂexec=force|relaxed /* controls exec of non-cet apps */
> >
> >
> Why do we need a whole new mechanism here?ÂÂCanât all this use
> regular glibc tunables?

Ok, got it.

Yu-cheng