[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9e00b2a3d988f7b24d274a108d31f5f0096eeaae.camel@intel.com>
Date: Wed, 8 Mar 2023 23:32:36 +0000
From: "Edgecombe, Rick P" <rick.p.edgecombe@...el.com>
To: "bp@...en8.de" <bp@...en8.de>
CC: "david@...hat.com" <david@...hat.com>,
"bsingharora@...il.com" <bsingharora@...il.com>,
"hpa@...or.com" <hpa@...or.com>,
"Syromiatnikov, Eugene" <esyr@...hat.com>,
"peterz@...radead.org" <peterz@...radead.org>,
"rdunlap@...radead.org" <rdunlap@...radead.org>,
"keescook@...omium.org" <keescook@...omium.org>,
"dave.hansen@...ux.intel.com" <dave.hansen@...ux.intel.com>,
"kirill.shutemov@...ux.intel.com" <kirill.shutemov@...ux.intel.com>,
"Eranian, Stephane" <eranian@...gle.com>,
"linux-mm@...ck.org" <linux-mm@...ck.org>,
"fweimer@...hat.com" <fweimer@...hat.com>,
"nadav.amit@...il.com" <nadav.amit@...il.com>,
"jannh@...gle.com" <jannh@...gle.com>,
"dethoma@...rosoft.com" <dethoma@...rosoft.com>,
"kcc@...gle.com" <kcc@...gle.com>,
"linux-arch@...r.kernel.org" <linux-arch@...r.kernel.org>,
"pavel@....cz" <pavel@....cz>, "oleg@...hat.com" <oleg@...hat.com>,
"hjl.tools@...il.com" <hjl.tools@...il.com>,
"Yang, Weijiang" <weijiang.yang@...el.com>,
"Lutomirski, Andy" <luto@...nel.org>,
"linux-doc@...r.kernel.org" <linux-doc@...r.kernel.org>,
"arnd@...db.de" <arnd@...db.de>,
"tglx@...utronix.de" <tglx@...utronix.de>,
"Schimpe, Christina" <christina.schimpe@...el.com>,
"mike.kravetz@...cle.com" <mike.kravetz@...cle.com>,
"x86@...nel.org" <x86@...nel.org>,
"akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
"debug@...osinc.com" <debug@...osinc.com>,
"jamorris@...ux.microsoft.com" <jamorris@...ux.microsoft.com>,
"john.allen@....com" <john.allen@....com>,
"rppt@...nel.org" <rppt@...nel.org>,
"andrew.cooper3@...rix.com" <andrew.cooper3@...rix.com>,
"mingo@...hat.com" <mingo@...hat.com>,
"corbet@....net" <corbet@....net>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-api@...r.kernel.org" <linux-api@...r.kernel.org>,
"gorcunov@...il.com" <gorcunov@...il.com>
Subject: Re: [PATCH v7 28/41] x86: Introduce userspace API for shadow stack
On Wed, 2023-03-08 at 11:27 +0100, Borislav Petkov wrote:
> On Mon, Feb 27, 2023 at 02:29:44PM -0800, Rick Edgecombe wrote:
> > From: "Kirill A. Shutemov" <kirill.shutemov@...ux.intel.com>
> >
> > Add three new arch_prctl() handles:
> >
> > - ARCH_SHSTK_ENABLE/DISABLE enables or disables the specified
> > feature. Returns 0 on success or an error.
>
> "... or a negative value on error."
Sure.
>
> > - ARCH_SHSTK_LOCK prevents future disabling or enabling of the
> > specified feature. Returns 0 on success or an error
>
> ditto.
>
> What is the use case of the feature locking?
>
> I'm under the simple assumption that once shstk is enabled for an
> app,
> it remains so. I guess my question is rather, what's the use case for
> enabling shadow stack and then disabling it later for an app...?
This would be for things like the "permissive mode", where glibc
determines that it has to do something like dlopen() an unsupporting
DSO much later.
But being able to late lock the features is required for the working
behavior of glibc as well. Glibc enables shadow stack very early, then
disables it later if it finds that any of the normal dynamic libraries
don't support it. It only locks shadow stack after this point even in
non-permissive mode.
The selftest also does a lot of enabling and disabling.
>
> > The features are handled per-thread and inherited over
> > fork(2)/clone(2),
> > but reset on exec().
> >
> > This is preparation patch. It does not implement any features.
>
> That belongs under the "---" line I guess.
Oh, yes.
>
> > Tested-by: Pengfei Xu <pengfei.xu@...el.com>
> > Tested-by: John Allen <john.allen@....com>
> > Tested-by: Kees Cook <keescook@...omium.org>
> > Acked-by: Mike Rapoport (IBM) <rppt@...nel.org>
> > Reviewed-by: Kees Cook <keescook@...omium.org>
> > Signed-off-by: Kirill A. Shutemov <kirill.shutemov@...ux.intel.com>
> > [tweaked with feedback from tglx]
> > Co-developed-by: Rick Edgecombe <rick.p.edgecombe@...el.com>
> > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@...el.com>
> >
> > ---
> > v4:
> > - Remove references to CET and replace with shadow stack (Peterz)
> >
> > v3:
> > - Move shstk.c Makefile changes earlier (Kees)
> > - Add #ifdef around features_locked and features (Kees)
> > - Encapsulate features reset earlier in reset_thread_features() so
> > features and features_locked are not referenced in code that
> > would be
> > compiled !CONFIG_X86_USER_SHADOW_STACK. (Kees)
> > - Fix typo in commit log (Kees)
> > - Switch arch_prctl() numbers to avoid conflict with LAM
> >
> > v2:
> > - Only allow one enable/disable per call (tglx)
> > - Return error code like a normal arch_prctl() (Alexander
> > Potapenko)
> > - Make CET only (tglx)
> > ---
> > arch/x86/include/asm/processor.h | 6 +++++
> > arch/x86/include/asm/shstk.h | 21 +++++++++++++++
> > arch/x86/include/uapi/asm/prctl.h | 6 +++++
> > arch/x86/kernel/Makefile | 2 ++
> > arch/x86/kernel/process_64.c | 7 ++++-
> > arch/x86/kernel/shstk.c | 44
> > +++++++++++++++++++++++++++++++
> > 6 files changed, 85 insertions(+), 1 deletion(-)
> > create mode 100644 arch/x86/include/asm/shstk.h
> > create mode 100644 arch/x86/kernel/shstk.c
>
> ...
>
> > +long shstk_prctl(struct task_struct *task, int option, unsigned
> > long features)
> > +{
> > + if (option == ARCH_SHSTK_LOCK) {
> > + task->thread.features_locked |= features;
> > + return 0;
> > + }
> > +
> > + /* Don't allow via ptrace */
> > + if (task != current)
> > + return -EINVAL;
> > +
> > + /* Do not allow to change locked features */
> > + if (features & task->thread.features_locked)
> > + return -EPERM;
> > +
> > + /* Only support enabling/disabling one feature at a time. */
> > + if (hweight_long(features) > 1)
> > + return -EINVAL;
> > +
> > + if (option == ARCH_SHSTK_DISABLE) {
> > + return -EINVAL;
> > + }
>
> {} braces left over from some previous version. Can go now.
>
This was intentional, but I wasn't sure on it. It makes the diff
cleaner in later patches, is the reason.
Powered by blists - more mailing lists