From: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
To: "david@redhat.com" <david@redhat.com>,
"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>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"kirill.shutemov@linux.intel.com"
<kirill.shutemov@linux.intel.com>,
"Eranian, Stephane" <eranian@google.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>,
"linux-arch@vger.kernel.org" <linux-arch@vger.kernel.org>,
"kcc@google.com" <kcc@google.com>, "pavel@ucw.cz" <pavel@ucw.cz>,
"oleg@redhat.com" <oleg@redhat.com>,
"hjl.tools@gmail.com" <hjl.tools@gmail.com>,
"bp@alien8.de" <bp@alien8.de>,
"Lutomirski, Andy" <luto@kernel.org>,
"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>,
"arnd@arndb.de" <arnd@arndb.de>,
"tglx@linutronix.de" <tglx@linutronix.de>,
"Schimpe, Christina" <christina.schimpe@intel.com>,
"x86@kernel.org" <x86@kernel.org>,
"mike.kravetz@oracle.com" <mike.kravetz@oracle.com>,
"Yang, Weijiang" <weijiang.yang@intel.com>,
"debug@rivosinc.com" <debug@rivosinc.com>,
"jamorris@linux.microsoft.com" <jamorris@linux.microsoft.com>,
"john.allen@amd.com" <john.allen@amd.com>,
"rppt@kernel.org" <rppt@kernel.org>,
"andrew.cooper3@citrix.com" <andrew.cooper3@citrix.com>,
"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>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: "Yu, Yu-cheng" <yu-cheng.yu@intel.com>
Subject: Re: [PATCH v6 19/41] x86/mm: Check shadow stack page fault errors
Date: Wed, 22 Feb 2023 23:07:39 +0000 [thread overview]
Message-ID: <c67f511516d2f28385bbe079b7d7d40f136adb27.camel@intel.com> (raw)
In-Reply-To: <458b3d39-ddce-c0f2-fe80-4e0cc5b101bd@redhat.com>
On Mon, 2023-02-20 at 13:57 +0100, David Hildenbrand wrote:
> >
> > + /*
> > + * When a page becomes COW it changes from a shadow stack
> > permission
> > + * page (Write=0,Dirty=1) to (Write=0,Dirty=0,SavedDirty=1),
> > which is simply
> > + * read-only to the CPU. When shadow stack is enabled, a RET
> > would
> > + * normally pop the shadow stack by reading it with a "shadow
> > stack
> > + * read" access. However, in the COW case the shadow stack
> > memory does
> > + * not have shadow stack permissions, it is read-only. So it
> > will
> > + * generate a fault.
> > + *
> > + * For conventionally writable pages, a read can be serviced
> > with a
> > + * read only PTE, and COW would not have to happen. But for
> > shadow
> > + * stack, there isn't the concept of read-only shadow stack
> > memory.
> > + * If it is shadow stack permission, it can be modified via
> > CALL and
> > + * RET instructions. So COW needs to happen before any memory
> > can be
> > + * mapped with shadow stack permissions.
> > + *
> > + * Shadow stack accesses (read or write) need to be serviced
> > with
> > + * shadow stack permission memory, so in the case of a shadow
> > stack
> > + * read access, treat it as a WRITE fault so both COW will
> > happen and
> > + * the write fault path will tickle maybe_mkwrite() and map
> > the memory
> > + * shadow stack.
> > + */
>
> Again, I suggest dropping all details about COW from this comment
> and
> from the patch description. It's just one such case that can happen.
Hi David,
I was just trying to edit this one to drop COW details, but I think in
this case, one of the major reasons for the code *is* actually COW. We
are not working around the whole inadvertent shadow stack memory piece
here, but something else: Making sure shadow stack memory is faulted in
and doing COW if required to make this possible. I came up with this,
does it seem better?
/*
* For conventionally writable pages, a read can be serviced with a
*
read only PTE. But for shadow stack, there isn't a concept of
* read-
only shadow stack memory. If it a PTE has the shadow stack
*
permission, it can be modified via CALL and RET instructions. So
* core
MM needs to fault in a writable PTE and do things it already
* does for
write faults.
*
* Shadow stack accesses (read or write) need to be
serviced with
* shadow stack permission memory, so in the case of a
shadow stack
* read access, treat it as a WRITE fault so both any
required COW will
* happen and the write fault path will tickle
maybe_mkwrite() and map
* the memory shadow stack.
*/
Thanks,
Rick
next prev parent reply other threads:[~2023-02-22 23:07 UTC|newest]
Thread overview: 115+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-18 21:13 [PATCH v6 00/41] Shadow stacks for userspace Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 01/41] Documentation/x86: Add CET shadow stack description Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 02/41] x86/shstk: Add Kconfig option for shadow stack Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 03/41] x86/cpufeatures: Add CPU feature flags for shadow stacks Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 04/41] x86/cpufeatures: Enable CET CR4 bit for shadow stack Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 05/41] x86/fpu/xstate: Introduce CET MSR and XSAVES supervisor states Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 06/41] x86/fpu: Add helper for modifying xstate Rick Edgecombe
2023-02-18 21:13 ` [PATCH v6 07/41] x86: Move control protection handler to separate file Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 08/41] x86/shstk: Add user control-protection fault handler Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 09/41] x86/mm: Remove _PAGE_DIRTY from kernel RO pages Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 10/41] x86/mm: Move pmd_write(), pud_write() up in the file Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 11/41] mm: Introduce pte_mkwrite_kernel() Rick Edgecombe
2023-02-19 20:38 ` Kees Cook
2023-02-20 11:17 ` David Hildenbrand
2023-02-20 11:19 ` David Hildenbrand
2023-03-01 15:39 ` Deepak Gupta
2023-02-18 21:14 ` [PATCH v6 12/41] s390/mm: Introduce pmd_mkwrite_kernel() Rick Edgecombe
2023-02-19 20:39 ` Kees Cook
2023-02-20 11:21 ` David Hildenbrand
2023-02-23 12:14 ` Heiko Carstens
2023-02-23 17:59 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 13/41] mm: Make pte_mkwrite() take a VMA Rick Edgecombe
2023-02-19 20:40 ` Kees Cook
2023-02-20 1:00 ` Michael Ellerman
2023-02-20 21:24 ` Edgecombe, Rick P
2023-02-20 11:23 ` David Hildenbrand
2023-02-20 22:56 ` Edgecombe, Rick P
2023-03-01 15:41 ` Deepak Gupta
2023-02-18 21:14 ` [PATCH v6 14/41] x86/mm: Introduce _PAGE_SAVED_DIRTY Rick Edgecombe
2023-02-20 11:32 ` David Hildenbrand
2023-02-20 21:38 ` Edgecombe, Rick P
2023-02-21 8:38 ` David Hildenbrand
2023-02-21 20:08 ` Edgecombe, Rick P
2023-02-21 20:13 ` Dave Hansen
2023-02-22 1:02 ` Edgecombe, Rick P
2023-02-22 9:05 ` David Hildenbrand
2023-02-22 17:23 ` Dave Hansen
2023-02-22 17:27 ` David Hildenbrand
2023-02-22 17:42 ` Kees Cook
2023-02-22 17:54 ` Dave Hansen
2023-02-22 19:39 ` Kees Cook
2023-02-18 21:14 ` [PATCH v6 15/41] x86/mm: Update ptep/pmdp_set_wrprotect() for _PAGE_SAVED_DIRTY Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 16/41] x86/mm: Start actually marking _PAGE_SAVED_DIRTY Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 17/41] mm: Move VM_UFFD_MINOR_BIT from 37 to 38 Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 18/41] mm: Introduce VM_SHADOW_STACK for shadow stack memory Rick Edgecombe
2023-02-20 12:56 ` David Hildenbrand
2023-02-20 22:08 ` Edgecombe, Rick P
2023-02-21 8:34 ` David Hildenbrand
2023-02-22 22:13 ` Deepak Gupta
2023-02-18 21:14 ` [PATCH v6 19/41] x86/mm: Check shadow stack page fault errors Rick Edgecombe
2023-02-20 12:57 ` David Hildenbrand
2023-02-22 23:07 ` Edgecombe, Rick P [this message]
2023-02-23 12:55 ` David Hildenbrand
2023-02-18 21:14 ` [PATCH v6 20/41] x86/mm: Teach pte_mkwrite() about stack memory Rick Edgecombe
2023-02-19 20:41 ` Kees Cook
2023-02-20 22:52 ` Edgecombe, Rick P
2023-03-01 15:42 ` Deepak Gupta
2023-02-18 21:14 ` [PATCH v6 21/41] mm: Add guard pages around a shadow stack Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 22/41] mm/mmap: Add shadow stack pages to memory accounting Rick Edgecombe
2023-02-20 12:58 ` David Hildenbrand
2023-02-20 22:44 ` Edgecombe, Rick P
2023-02-21 8:31 ` David Hildenbrand
2023-02-22 0:06 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 23/41] mm: Re-introduce vm_flags to do_mmap() Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 24/41] mm: Don't allow write GUPs to shadow stack memory Rick Edgecombe
2023-02-21 8:42 ` David Hildenbrand
2023-02-21 20:02 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 25/41] x86/mm: Introduce MAP_ABOVE4G Rick Edgecombe
2023-02-19 20:43 ` Kees Cook
2023-02-20 22:38 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 26/41] mm: Warn on shadow stack memory in wrong vma Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 27/41] x86/mm: Warn if create Write=0,Dirty=1 with raw prot Rick Edgecombe
2023-02-19 20:45 ` Kees Cook
2023-02-20 22:32 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 28/41] x86: Introduce userspace API for shadow stack Rick Edgecombe
2023-02-24 12:20 ` Borislav Petkov
2023-02-24 18:37 ` Edgecombe, Rick P
2023-02-28 10:58 ` Borislav Petkov
2023-02-28 22:35 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 29/41] x86/shstk: Add user-mode shadow stack support Rick Edgecombe
2023-02-24 12:22 ` Borislav Petkov
2023-02-24 18:25 ` Edgecombe, Rick P
2023-02-24 18:33 ` Borislav Petkov
2023-02-18 21:14 ` [PATCH v6 30/41] x86/shstk: Handle thread shadow stack Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 31/41] x86/shstk: Introduce routines modifying shstk Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 32/41] x86/shstk: Handle signals for shadow stack Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 33/41] x86/shstk: Introduce map_shadow_stack syscall Rick Edgecombe
2023-02-23 0:03 ` Deepak Gupta
2023-02-23 1:11 ` Edgecombe, Rick P
2023-02-23 21:20 ` Deepak Gupta
2023-02-23 23:42 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 34/41] x86/shstk: Support WRSS for userspace Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 35/41] x86: Expose thread features in /proc/$PID/status Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 36/41] x86/shstk: Wire in shadow stack interface Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 37/41] selftests/x86: Add shadow stack test Rick Edgecombe
2023-02-19 20:47 ` Kees Cook
2023-02-21 8:48 ` David Hildenbrand
2023-02-21 20:02 ` Edgecombe, Rick P
2023-02-23 13:47 ` Borislav Petkov
2023-02-23 17:54 ` Edgecombe, Rick P
2023-02-24 11:45 ` Borislav Petkov
2023-02-24 18:39 ` Edgecombe, Rick P
2023-02-18 21:14 ` [PATCH v6 38/41] x86/fpu: Add helper for initing features Rick Edgecombe
2023-02-19 20:48 ` Kees Cook
2023-02-18 21:14 ` [PATCH v6 39/41] x86: Add PTRACE interface for shadow stack Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 40/41] x86/shstk: Add ARCH_SHSTK_UNLOCK Rick Edgecombe
2023-02-18 21:14 ` [PATCH v6 41/41] x86/shstk: Add ARCH_SHSTK_STATUS Rick Edgecombe
2023-02-20 3:42 ` [PATCH v6 00/41] Shadow stacks for userspace Kees Cook
2023-02-20 22:54 ` Edgecombe, Rick P
2023-02-20 6:50 ` Mike Rapoport
2023-02-20 21:23 ` Edgecombe, Rick P
2023-02-20 20:22 ` John Allen
2023-02-21 2:38 ` Pengfei Xu
2023-02-22 19:28 ` Borislav Petkov
2023-02-22 19:31 ` Edgecombe, Rick P
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=c67f511516d2f28385bbe079b7d7d40f136adb27.camel@intel.com \
--to=rick.p.edgecombe@intel.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=david@redhat.com \
--cc=debug@rivosinc.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=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).