Re: [PATCH v6 13/41] mm: Make pte_mkwrite() take a VMA

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 unusual properties is that shadow stack memory is writable,
but only in limited ways. These limits are applied via a specific PTE
bit combination. Nevertheless, the memory is writable, and core mm code
will need to apply the writable permissions in the typical paths that
call pte_mkwrite().

In addition to VM_WRITE, the shadow stack VMA's will have a flag denoting
that they are special shadow stack flavor of writable memory. So make
pte_mkwrite() take a VMA, so that the x86 implementation of it can know to
create regular writable memory or shadow stack memory.

Apply the same changes for pmd_mkwrite() and huge_pte_mkwrite().

No functional change.

Cc: linux-doc@xxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: linux-alpha@xxxxxxxxxxxxxxx
Cc: linux-snps-arc@xxxxxxxxxxxxxxxxxxx
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-csky@xxxxxxxxxxxxxxx
Cc: linux-hexagon@xxxxxxxxxxxxxxx
Cc: linux-ia64@xxxxxxxxxxxxxxx
Cc: loongarch@xxxxxxxxxxxxxxx
Cc: linux-m68k@xxxxxxxxxxxxxxxxxxxx
Cc: Michal Simek <monstr@xxxxxxxxx>
Cc: Dinh Nguyen <dinguyen@xxxxxxxxxx>
Cc: linux-mips@xxxxxxxxxxxxxxx
Cc: openrisc@xxxxxxxxxxxxxxxxxxxx
Cc: linux-parisc@xxxxxxxxxxxxxxx
Cc: linuxppc-dev@xxxxxxxxxxxxxxxx
Cc: linux-riscv@xxxxxxxxxxxxxxxxxxx
Cc: linux-s390@xxxxxxxxxxxxxxx
Cc: linux-sh@xxxxxxxxxxxxxxx
Cc: sparclinux@xxxxxxxxxxxxxxx
Cc: linux-um@xxxxxxxxxxxxxxxxxxx
Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx
Cc: linux-arch@xxxxxxxxxxxxxxx
Cc: linux-mm@xxxxxxxxx
Tested-by: Pengfei Xu <pengfei.xu@xxxxxxxxx>
Suggested-by: David Hildenbrand <david@xxxxxxxxxx>
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>

---
Hi Non-x86 Arch’s,

x86 has a feature that allows for the creation of a special type of
writable memory (shadow stack) that is only writable in limited specific
ways. Previously, changes were proposed to core MM code to teach it to
decide when to create normally writable memory or the special shadow stack
writable memory, but David Hildenbrand suggested[0] to change
pXX_mkwrite() to take a VMA, so awareness of shadow stack memory can be
moved into x86 code.

Since pXX_mkwrite() is defined in every arch, it requires some tree-wide
changes. So that is why you are seeing some patches out of a big x86
series pop up in your arch mailing list. There is no functional change.
After this refactor, the shadow stack series goes on to use the arch
helpers to push shadow stack memory details inside arch/x86.

Testing was just 0-day build testing.

Hopefully that is enough context. Thanks!

[0] https://lore.kernel.org/lkml/0e29a2d0-08d8-bcd6-ff26-4bea0e4037b0@xxxxxxxxxx/#t

v6:
  - New patch
---
  Documentation/mm/arch_pgtable_helpers.rst    |  9 ++++++---
  arch/alpha/include/asm/pgtable.h             |  6 +++++-
  arch/arc/include/asm/hugepage.h              |  2 +-
  arch/arc/include/asm/pgtable-bits-arcv2.h    |  7 ++++++-
  arch/arm/include/asm/pgtable-3level.h        |  7 ++++++-
  arch/arm/include/asm/pgtable.h               |  2 +-
  arch/arm64/include/asm/pgtable.h             |  4 ++--
  arch/csky/include/asm/pgtable.h              |  2 +-
  arch/hexagon/include/asm/pgtable.h           |  2 +-
  arch/ia64/include/asm/pgtable.h              |  2 +-
  arch/loongarch/include/asm/pgtable.h         |  4 ++--
  arch/m68k/include/asm/mcf_pgtable.h          |  2 +-
  arch/m68k/include/asm/motorola_pgtable.h     |  6 +++++-
  arch/m68k/include/asm/sun3_pgtable.h         |  6 +++++-
  arch/microblaze/include/asm/pgtable.h        |  2 +-
  arch/mips/include/asm/pgtable.h              |  6 +++---
  arch/nios2/include/asm/pgtable.h             |  2 +-
  arch/openrisc/include/asm/pgtable.h          |  2 +-
  arch/parisc/include/asm/pgtable.h            |  6 +++++-
  arch/powerpc/include/asm/book3s/32/pgtable.h |  2 +-
  arch/powerpc/include/asm/book3s/64/pgtable.h |  4 ++--
  arch/powerpc/include/asm/nohash/32/pgtable.h |  2 +-
  arch/powerpc/include/asm/nohash/32/pte-8xx.h |  2 +-
  arch/powerpc/include/asm/nohash/64/pgtable.h |  2 +-
  arch/riscv/include/asm/pgtable.h             |  6 +++---
  arch/s390/include/asm/hugetlb.h              |  4 ++--
  arch/s390/include/asm/pgtable.h              |  4 ++--
  arch/sh/include/asm/pgtable_32.h             | 10 ++++++++--
  arch/sparc/include/asm/pgtable_32.h          |  2 +-
  arch/sparc/include/asm/pgtable_64.h          |  6 +++---
  arch/um/include/asm/pgtable.h                |  2 +-
  arch/x86/include/asm/pgtable.h               |  6 ++++--
  arch/xtensa/include/asm/pgtable.h            |  2 +-
  include/asm-generic/hugetlb.h                |  4 ++--
  include/linux/mm.h                           |  2 +-
  mm/debug_vm_pgtable.c                        | 16 ++++++++--------
  mm/huge_memory.c                             |  6 +++---
  mm/hugetlb.c                                 |  4 ++--
  mm/memory.c                                  |  4 ++--
  mm/migrate_device.c                          |  2 +-
  mm/mprotect.c                                |  2 +-
  mm/userfaultfd.c                             |  2 +-
  42 files changed, 106 insertions(+), 69 deletions(-)

That looks painful but IMHO worth it :)

Acked-by: David Hildenbrand <david@xxxxxxxxxx>

--
Thanks,

David / dhildenb




[Index of Archives]     [LKML Archive]     [Linux ARM Kernel]     [Linux ARM]     [Git]     [Yosemite News]     [Linux SCSI]     [Linux Hams]

  Powered by Linux