Message ID | 20230218211433.26859-13-rick.p.edgecombe@intel.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Shadow stacks for userspace | expand |
On Sat, Feb 18, 2023 at 01:14:04PM -0800, Rick Edgecombe wrote: > The x86 Control-flow Enforcement Technology (CET) feature includes a new > type of memory called shadow stack. This shadow stack memory has some > unusual properties, which requires some core mm changes to function > properly. > > One of these changes is to allow for pmd_mkwrite() to create different > types of writable memory (the existing conventionally writable type and > also the new shadow stack type). Future patches will convert pmd_mkwrite() > to take a VMA in order to facilitate this, however there are places in the > kernel where pmd_mkwrite() is called outside of the context of a VMA. > These are for kernel memory. So create a new variant called > pmd_mkwrite_kernel() and switch the kernel users over to it. Have > pmd_mkwrite() and pmd_mkwrite_kernel() be the same for now. Future patches > will introduce changes to make pmd_mkwrite() take a VMA. > > Only do this for architectures that need it because they call pmd_mkwrite() > in arch code without an associated VMA. Since it will only currently be > used in arch code, so do not include it in arch_pgtable_helpers.rst. > > Cc: linux-kernel@vger.kernel.org > Cc: linux-s390@vger.kernel.org > Cc: linux-arch@vger.kernel.org > Cc: linux-mm@kvack.org > Tested-by: Pengfei Xu <pengfei.xu@intel.com> > Suggested-by: David Hildenbrand <david@redhat.com> > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> Yup, 1:1 refactor. Reviewed-by: Kees Cook <keescook@chromium.org>
On 18.02.23 22:14, Rick Edgecombe wrote: > The x86 Control-flow Enforcement Technology (CET) feature includes a new > type of memory called shadow stack. This shadow stack memory has some > unusual properties, which requires some core mm changes to function > properly. > > One of these changes is to allow for pmd_mkwrite() to create different > types of writable memory (the existing conventionally writable type and > also the new shadow stack type). Future patches will convert pmd_mkwrite() > to take a VMA in order to facilitate this, however there are places in the > kernel where pmd_mkwrite() is called outside of the context of a VMA. > These are for kernel memory. So create a new variant called > pmd_mkwrite_kernel() and switch the kernel users over to it. Have > pmd_mkwrite() and pmd_mkwrite_kernel() be the same for now. Future patches > will introduce changes to make pmd_mkwrite() take a VMA. > > Only do this for architectures that need it because they call pmd_mkwrite() > in arch code without an associated VMA. Since it will only currently be > used in arch code, so do not include it in arch_pgtable_helpers.rst. > > Cc: linux-kernel@vger.kernel.org > Cc: linux-s390@vger.kernel.org > Cc: linux-arch@vger.kernel.org > Cc: linux-mm@kvack.org > Tested-by: Pengfei Xu <pengfei.xu@intel.com> > Suggested-by: David Hildenbrand <david@redhat.com> > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> > Heh, that answers my question to patch #11 Acked-by: David Hildenbrand <david@redhat.com>
On Sat, Feb 18, 2023 at 01:14:04PM -0800, Rick Edgecombe wrote: > The x86 Control-flow Enforcement Technology (CET) feature includes a new > type of memory called shadow stack. This shadow stack memory has some > unusual properties, which requires some core mm changes to function > properly. > > One of these changes is to allow for pmd_mkwrite() to create different > types of writable memory (the existing conventionally writable type and > also the new shadow stack type). Future patches will convert pmd_mkwrite() > to take a VMA in order to facilitate this, however there are places in the > kernel where pmd_mkwrite() is called outside of the context of a VMA. > These are for kernel memory. So create a new variant called > pmd_mkwrite_kernel() and switch the kernel users over to it. Have > pmd_mkwrite() and pmd_mkwrite_kernel() be the same for now. Future patches > will introduce changes to make pmd_mkwrite() take a VMA. > > Only do this for architectures that need it because they call pmd_mkwrite() > in arch code without an associated VMA. Since it will only currently be > used in arch code, so do not include it in arch_pgtable_helpers.rst. > > Cc: linux-kernel@vger.kernel.org > Cc: linux-s390@vger.kernel.org > Cc: linux-arch@vger.kernel.org > Cc: linux-mm@kvack.org > Tested-by: Pengfei Xu <pengfei.xu@intel.com> > Suggested-by: David Hildenbrand <david@redhat.com> > Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com> ... > --- > arch/s390/include/asm/pgtable.h | 7 ++++++- > arch/s390/mm/pageattr.c | 2 +- > 2 files changed, 7 insertions(+), 2 deletions(-) Acked-by: Heiko Carstens <hca@linux.ibm.com>
On Thu, 2023-02-23 at 13:14 +0100, Heiko Carstens wrote:
> Acked-by: Heiko Carstens <hca@linux.ibm.com>
Thanks!
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 29522418b5f4..c48a447d1432 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1425,7 +1425,7 @@ static inline pmd_t pmd_wrprotect(pmd_t pmd) return set_pmd_bit(pmd, __pgprot(_SEGMENT_ENTRY_PROTECT)); } -static inline pmd_t pmd_mkwrite(pmd_t pmd) +static inline pmd_t pmd_mkwrite_kernel(pmd_t pmd) { pmd = set_pmd_bit(pmd, __pgprot(_SEGMENT_ENTRY_WRITE)); if (pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY) @@ -1433,6 +1433,11 @@ static inline pmd_t pmd_mkwrite(pmd_t pmd) return pmd; } +static inline pmd_t pmd_mkwrite(pmd_t pmd) +{ + return pmd_mkwrite_kernel(pmd); +} + static inline pmd_t pmd_mkclean(pmd_t pmd) { pmd = clear_pmd_bit(pmd, __pgprot(_SEGMENT_ENTRY_DIRTY)); diff --git a/arch/s390/mm/pageattr.c b/arch/s390/mm/pageattr.c index 4ee5fe5caa23..7b6967dfacd0 100644 --- a/arch/s390/mm/pageattr.c +++ b/arch/s390/mm/pageattr.c @@ -146,7 +146,7 @@ static void modify_pmd_page(pmd_t *pmdp, unsigned long addr, if (flags & SET_MEMORY_RO) new = pmd_wrprotect(new); else if (flags & SET_MEMORY_RW) - new = pmd_mkwrite(pmd_mkdirty(new)); + new = pmd_mkwrite_kernel(pmd_mkdirty(new)); if (flags & SET_MEMORY_NX) new = set_pmd_bit(new, __pgprot(_SEGMENT_ENTRY_NOEXEC)); else if (flags & SET_MEMORY_X)