All of lore.kernel.org
 help / color / mirror / Atom feed
From: Deepak Gupta <debug@rivosinc.com>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Cc: "bsingharora@gmail.com" <bsingharora@gmail.com>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"Syromiatnikov, Eugene" <esyr@redhat.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"rdunlap@infradead.org" <rdunlap@infradead.org>,
	"keescook@chromium.org" <keescook@chromium.org>,
	"Yu, Yu-cheng" <yu-cheng.yu@intel.com>,
	"Eranian, Stephane" <eranian@google.com>,
	"kirill.shutemov@linux.intel.com"
	<kirill.shutemov@linux.intel.com>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"linux-mm@kvack.org" <linux-mm@kvack.org>,
	"fweimer@redhat.com" <fweimer@redhat.com>,
	"nadav.amit@gmail.com" <nadav.amit@gmail.com>,
	"jannh@google.com" <jannh@google.com>,
	"dethoma@microsoft.com" <dethoma@microsoft.com>,
	"kcc@google.com" <kcc@google.com>,
	"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
	"bp@alien8.de" <bp@alien8.de>,
	"oleg@redhat.com" <oleg@redhat.com>,
	"hjl.tools@gmail.com" <hjl.tools@gmail.com>,
	"Yang, Weijiang" <weijiang.yang@intel.com>,
	"Lutomirski, Andy" <luto@kernel.org>,
	"jamorris@linux.microsoft.com" <jamorris@linux.microsoft.com>,
	"arnd@arndb.de" <arnd@arndb.de>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
	"Schimpe, Christina" <christina.schimpe@intel.com>,
	"mike.kravetz@oracle.com" <mike.kravetz@oracle.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"akpm@linux-foundation.org" <akpm@linux-foundation.org>,
	"pavel@ucw.cz" <pavel@ucw.cz>,
	"andrew.cooper3@citrix.com" <andrew.cooper3@citrix.com>,
	"john.allen@amd.com" <john.allen@amd.com>,
	"rppt@kernel.org" <rppt@kernel.org>,
	"tglx@linutronix.de" <tglx@linutronix.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"corbet@lwn.net" <corbet@lwn.net>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"linux-api@vger.kernel.org" <linux-api@vger.kernel.org>,
	"gorcunov@gmail.com" <gorcunov@gmail.com>
Subject: Re: [PATCH v5 19/39] mm: Fixup places that call pte_mkwrite() directly
Date: Tue, 14 Feb 2023 22:37:16 -0800	[thread overview]
Message-ID: <CAKC1njST4i=88zqk6kQfjnVjr+eU=hdDYmTJSb_TGrKX9UftjQ@mail.gmail.com> (raw)
In-Reply-To: <9ea047ed05d75822991325b709f583ee10b0fa34.camel@intel.com>

On Tue, Feb 14, 2023 at 10:24 AM Edgecombe, Rick P
<rick.p.edgecombe@intel.com> wrote:
>
> On Mon, 2023-02-13 at 22:10 -0800, Deepak Gupta wrote:
> > On Tue, Feb 14, 2023 at 01:07:24AM +0000, Edgecombe, Rick P wrote:
> > > On Mon, 2023-02-13 at 16:09 -0800, Deepak Gupta wrote:
> > > > Since I've a general question on outcome of discussion of how to
> > > > handle
> > > > `pte_mkwrite`, so I am top posting.
> > > >
> > > > I have posted patches yesterday targeting riscv zisslpcfi
> > > > extension.
> > > >
> > >
> > >
> https://lore.kernel.org/lkml/20230213045351.3945824-1-debug@rivosinc.com/
> > > >
> > > > Since there're similarities in extension(s), patches have
> > > > similarity
> > > > too.
> > > > One of the similarity was updating `maybe_mkwrite`. I was asked
> > > > (by
> > > > dhildenb
> > > > on my patch #11) to look at x86 approach on how to approach this
> > > > so
> > > > that
> > > > core-mm approach fits multiple architectures along with the need
> > > > to
> > > > update `pte_mkwrite` to consume vma flags.
> > > > In x86 CET patch series, I see that locations where `pte_mkwrite`
> > > > is
> > > > invoked are updated to check for shadow stack vma and not
> > > > necessarily
> > > > `pte_mkwrite` itself is updated to consume vma flags. Let me know
> > > > if
> > > > my
> > > > understanding is correct and that's the current direction (to
> > > > update
> > > > call sites for vma check where `pte_mkwrite` is invoked)
> > > >
> > > > Being said that as I've mentioned in my patch series that
> > > > there're
> > > > similarities between x86, arm and now riscv for implementing
> > > > shadow
> > > > stack
> > > > and indirect branch tracking, overall it'll be a good thing if we
> > > > can
> > > > collaborate and come up with common bits.
> > >
> > > Oh interesting. I've made the changes to have pte_mkwrite() take a
> > > VMA.
> > > It seems to work pretty well with the core MM code, but I'm letting
> > > 0-
> > > day chew on it for a bit because it touched so many arch's. I'll
> > > include you when I send it out, hopefully later this week.
> >
> > Thanks.
> > >
> > > From just a quick look, I see some design aspects that have been
> > > problematic on the x86 implementation.
> > >
> > > There was something like PROT_SHADOW_STACK before, but there were
> > > two
> > > problems:
> > > 1. Writable windows while provisioning restore tokens (maybe this
> > > is
> > > just an x86 thing)
> > > 2. Adding guard pages when a shadow stack was mprotect()ed to
> > > change it
> > > from writable to shadow stack. Again this might be an x86 need,
> > > since
> > > it needed to have it writable to add a restore token, and the guard
> > > pages help with security.
> >
> > I've not seen your earlier patch but I am assuming when you say
> > window you
> > mean that shadow stack was open to regular stores (or I may be
> > missing
> > something here)
> >
> > I am wondering if mapping it as shadow stack (instead of having
> > temporary
> > writeable mapping) and using `wruss` was an option to put the token
> > or
> > you wanted to avoid it?
> >
> > And yes on riscv, architecture itself doesn't define token or its
> > format.
> > Since it's RISC, software can define the token format and thus can
> > use
> > either `sspush` or `ssamoswap` to put a token on `shadow stack`
> > virtual
> > memory.
>
> With WRSS a token could be created via software, but x86 shadow stack
> includes instructions to create and switch to tokens in limited ways
> (RSTORSSP, SAVEPREVSSP), where WRSS lets you write anything. These
> other instructions are enough for glibc, except for writing a restore
> token on a brand new shadow stack.
>
> So WRSS is made optional since it weakens the protection of the shadow
> stack. Some apps may prefer to use it to do exotic things, but the
> glibc implementation didn't require it.
>

Yes, I understand WRSS in user mode is not safe and defeat the purpose as well.

I actually had meant why WRUSS couldn't be used in the kernel to
manufacture the token when the kernel
creates the shadow stack while parsing elf bits. But then I went
through you earlier patch series now and I've a
a little bit of context now. There is a lot of history and context
(and mess) here.

> >
> > >
> > > So instead this series creates a map_shadow_stack syscall that maps
> > > a
> > > shadow stack and writes the token from the kernel side. Then
> > > mprotect()
> > > is prevented from making shadow stack's conventionally writable.
> > >
> > > another difference is enabling shadow stack based on elf header
> > > bits
> > > instead of the arch_prctl()s. See the history and reasoning here
> > > (section "Switch Enabling Interface"):
> > >
> > >
> https://lore.kernel.org/lkml/20220130211838.8382-1-rick.p.edgecombe@intel.com/
> > >
> > > Not sure if those two issues would be problems on riscv or not.
> >
> > Apart from mapping and window issue that you mentioned, I couldn't
> > understand on why elf header bit is an issue only in this case for
> > x86
> > shadow stack and not an issue for let's say aarch64. I can see that
> > aarch64 pretty much uses elf header bit for BTI. Eventually indirect
> > branch tracking also needs to be enabled which is analogous to BTI.
>
> Well for one, we had to deal with those old glibc's. But doesn't BTI
> text need to be mapped with a special PROT as well? So it doesn't just
> turn on enforcement automatically if it detects the elf bit.
>
> >
> > BTW eventually riscv binaries plan to use `.riscv.attributes` section
> > in riscv elf binary instead of `.gnu.note.property`. So I am hoping
> > that
> > part will go into arch specific code of elf parsing for riscv and
> > will be
> > contained.
> >
> > >
> > > For sharing the prctl() interface. The other thing is that x86 also
> > > has
> > > this "wrss" instruction that can be enabled with shadow stack. The
> > > current arch_prctl() interface supports both. I'm thinking it's
> > > probably a pretty arch-specific thing.
> >
> > yes ability to perform writes on shadow stack absolutely are
> > prevented on
> > x86. So enabling that should be a arch specific prctl.
> >
> > >
> > > ABI-wise, are you planning to automatically allocate shadow stacks
> > > for
> > > new tasks? If the ABI is completely different it might be best to
> > > not
> > > share user interfaces. But also, I wonder why is it different.
> >
> > Yes as of now planning both:
> > - allocate shadow stack for new task based on elf header
> > - task can create them using `prctls` (from glibc)
> >
> > And yes `fork` will get the all cfi properties (shdow stack and
> > branch tracking)
> > from parent.
>
> Have you looked at a riscv libc implementation yet? For unifying ABI I
> think that might be best interface to target, for app developers. Then
> each arch can implement enough kernel functionality to support libc
> (for example map_shadow_stack).
>
>

  reply	other threads:[~2023-02-15  6:37 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19 21:22 [PATCH v5 00/39] Shadow stacks for userspace Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 01/39] Documentation/x86: Add CET shadow stack description Rick Edgecombe
2023-01-20  0:38   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 02/39] x86/shstk: Add Kconfig option for shadow stack Rick Edgecombe
2023-01-20  0:40   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 03/39] x86/cpufeatures: Add CPU feature flags for shadow stacks Rick Edgecombe
2023-01-20  0:44   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 04/39] x86/cpufeatures: Enable CET CR4 bit for shadow stack Rick Edgecombe
2023-01-20  0:46   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 05/39] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states Rick Edgecombe
2023-01-20  0:46   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 06/39] x86/fpu: Add helper for modifying xstate Rick Edgecombe
2023-01-20  0:47   ` Kees Cook
2023-02-01 11:01   ` Borislav Petkov
2023-02-01 17:31     ` Edgecombe, Rick P
2023-02-01 18:18       ` Borislav Petkov
2023-01-19 21:22 ` [PATCH v5 07/39] x86: Add user control-protection fault handler Rick Edgecombe
2023-01-20  0:50   ` Kees Cook
2023-02-03 19:09   ` Borislav Petkov
2023-02-03 19:24     ` Edgecombe, Rick P
2023-02-03 19:44       ` Borislav Petkov
2023-02-03 23:01         ` Edgecombe, Rick P
2023-02-04 10:37           ` Borislav Petkov
2023-01-19 21:22 ` [PATCH v5 08/39] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Rick Edgecombe
2023-01-20  0:52   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 09/39] x86/mm: Move pmd_write(), pud_write() up in the file Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 10/39] x86/mm: Introduce _PAGE_COW Rick Edgecombe
2023-01-20  0:55   ` Kees Cook
2023-01-23  9:16   ` David Hildenbrand
2023-01-23  9:28   ` David Hildenbrand
2023-01-23 20:56     ` Edgecombe, Rick P
2023-01-24 16:28       ` David Hildenbrand
2023-01-19 21:22 ` [PATCH v5 11/39] x86/mm: Update pte_modify for _PAGE_COW Rick Edgecombe
2023-01-20  0:57   ` Kees Cook
2023-02-09 14:08   ` Borislav Petkov
2023-02-09 17:09     ` Edgecombe, Rick P
2023-02-10 13:57       ` Borislav Petkov
2023-02-10 17:00         ` Edgecombe, Rick P
2023-02-17 16:11           ` Borislav Petkov
2023-02-17 16:53             ` Edgecombe, Rick P
2023-01-19 21:22 ` [PATCH v5 12/39] x86/mm: Update ptep_set_wrprotect() and pmdp_set_wrprotect() for transition from _PAGE_DIRTY to _PAGE_COW Rick Edgecombe
2023-01-20  0:58   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 13/39] x86/mm: Start actually marking _PAGE_COW Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 14/39] mm: Move VM_UFFD_MINOR_BIT from 37 to 38 Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 15/39] mm: Introduce VM_SHADOW_STACK for shadow stack memory Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 16/39] x86/mm: Check shadow stack page fault errors Rick Edgecombe
2023-01-20  0:59   ` Kees Cook
2023-01-19 21:22 ` [PATCH v5 17/39] x86/mm: Update maybe_mkwrite() for shadow stack Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 18/39] mm: Handle faultless write upgrades for shstk Rick Edgecombe
2023-01-23  9:50   ` David Hildenbrand
2023-01-23 20:47     ` Edgecombe, Rick P
2023-01-24 16:24       ` David Hildenbrand
2023-01-24 18:14         ` Edgecombe, Rick P
2023-01-25  9:27           ` David Hildenbrand
2023-01-25 18:43             ` Edgecombe, Rick P
2023-01-26  0:59               ` Edgecombe, Rick P
2023-01-26  8:46                 ` David Hildenbrand
2023-01-26 20:19                   ` Edgecombe, Rick P
2023-01-27 16:12                     ` David Hildenbrand
2023-01-28  0:51                       ` Edgecombe, Rick P
2023-01-31  8:46                         ` David Hildenbrand
2023-01-31 23:33                           ` Edgecombe, Rick P
2023-02-01  9:03                             ` David Hildenbrand
2023-02-01 17:32                               ` Edgecombe, Rick P
2023-02-01 18:03                                 ` David Hildenbrand
2023-01-26  8:57               ` David Hildenbrand
2023-01-26 20:16                 ` Edgecombe, Rick P
2023-01-27 16:19                   ` David Hildenbrand
2023-01-19 21:22 ` [PATCH v5 19/39] mm: Fixup places that call pte_mkwrite() directly Rick Edgecombe
2023-01-20  1:01   ` Kees Cook
2023-02-14  0:09   ` Deepak Gupta
2023-02-14  1:07     ` Edgecombe, Rick P
2023-02-14  6:10       ` Deepak Gupta
2023-02-14 18:24         ` Edgecombe, Rick P
2023-02-15  6:37           ` Deepak Gupta [this message]
2023-01-19 21:22 ` [PATCH v5 20/39] mm: Add guard pages around a shadow stack Rick Edgecombe
2023-01-19 21:22 ` [PATCH v5 21/39] mm/mmap: Add shadow stack pages to memory accounting Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 22/39] mm: Re-introduce vm_flags to do_mmap() Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 23/39] mm: Don't allow write GUPs to shadow stack memory Rick Edgecombe
2023-01-23  9:10   ` David Hildenbrand
2023-01-23 10:45     ` Florian Weimer
2023-01-23 20:46       ` Edgecombe, Rick P
2023-01-24 16:26         ` David Hildenbrand
2023-01-24 18:42           ` Edgecombe, Rick P
2023-01-24 23:08             ` Kees Cook
2023-01-24 23:41               ` Edgecombe, Rick P
2023-01-25  9:29                 ` David Hildenbrand
2023-01-25 15:23                   ` Kees Cook
2023-01-25 15:36             ` Schimpe, Christina
2023-01-25 16:43               ` Schimpe, Christina
2023-01-19 21:23 ` [PATCH v5 24/39] x86/mm: Introduce MAP_ABOVE4G Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 25/39] mm: Warn on shadow stack memory in wrong vma Rick Edgecombe
2023-01-20  1:01   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 26/39] x86: Introduce userspace API for shadow stack Rick Edgecombe
2023-01-20  1:04   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 27/39] x86/shstk: Add user-mode shadow stack support Rick Edgecombe
2023-01-20  1:05   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 28/39] x86/shstk: Handle thread shadow stack Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 29/39] x86/shstk: Introduce routines modifying shstk Rick Edgecombe
2023-01-20  1:05   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 30/39] x86/shstk: Handle signals for shadow stack Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 31/39] x86/shstk: Introduce map_shadow_stack syscall Rick Edgecombe
2023-01-20  1:07   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 32/39] x86/shstk: Support WRSS for userspace Rick Edgecombe
2023-01-20  1:06   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 33/39] x86: Expose thread features in /proc/$PID/status Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 34/39] x86/shstk: Wire in shadow stack interface Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 35/39] selftests/x86: Add shadow stack test Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 36/39] x86/fpu: Add helper for initing features Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 37/39] x86: Add PTRACE interface for shadow stack Rick Edgecombe
2023-01-20  1:08   ` Kees Cook
2023-01-19 21:23 ` [PATCH v5 38/39] x86/shstk: Add ARCH_SHSTK_UNLOCK Rick Edgecombe
2023-01-19 21:23 ` [PATCH v5 39/39] x86/shstk: Add ARCH_SHSTK_STATUS Rick Edgecombe
2023-01-20  1:08   ` Kees Cook
2023-01-19 22:26 ` [PATCH v5 00/39] Shadow stacks for userspace Andrew Morton
2023-01-20 17:27   ` Edgecombe, Rick P
2023-01-20 19:19     ` Kees Cook
2023-01-25 19:46       ` Edgecombe, Rick P
2023-01-20 17:48 ` John Allen
2023-01-22  8:20 ` Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKC1njST4i=88zqk6kQfjnVjr+eU=hdDYmTJSb_TGrKX9UftjQ@mail.gmail.com' \
    --to=debug@rivosinc.com \
    --cc=akpm@linux-foundation.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=bsingharora@gmail.com \
    --cc=christina.schimpe@intel.com \
    --cc=corbet@lwn.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=dethoma@microsoft.com \
    --cc=eranian@google.com \
    --cc=esyr@redhat.com \
    --cc=fweimer@redhat.com \
    --cc=gorcunov@gmail.com \
    --cc=hjl.tools@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jamorris@linux.microsoft.com \
    --cc=jannh@google.com \
    --cc=john.allen@amd.com \
    --cc=kcc@google.com \
    --cc=keescook@chromium.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mike.kravetz@oracle.com \
    --cc=mingo@redhat.com \
    --cc=nadav.amit@gmail.com \
    --cc=oleg@redhat.com \
    --cc=pavel@ucw.cz \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=rppt@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=weijiang.yang@intel.com \
    --cc=x86@kernel.org \
    --cc=yu-cheng.yu@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.