Skip to content

Kernel userspace access/execution prevention with hash translation

Aneesh Kumar K.V linuxppc-dev 9 versions – Applied

Status from this message: Applied to powerpc/next.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest22 patches 3 repliesApplied
  2. v6 posting 2/222 patches 25 repliesSuperseded
  3. v5 posting 2/223 patches 12 repliesSuperseded
Earlier versions · 6
VersionPostedPatchesRepliesStatus
v6 posting 1/223 patches3 repliesApplied
v5 posting 1/226 patches22 repliesSuperseded
v441 patches3 repliesSuperseded
v341 patches0 repliesSuperseded
v228 patches1 replySuperseded
v1 RFC25 patches0 repliesSuperseded

Changes in v7 from the cover letter

* Address review comments
* Rename MMU FTR defines

Patches in v7 Applied

#Subject and filesSizeRepliesApplied
1/22powerpc: Add new macro to handle NESTED_IFCLRarch/powerpc/include/asm/feature-fixups.h+3 -00 replies
2/22KVM: PPC: BOOK3S: PR: Ignore UAMOR SPRarch/powerpc/kvm/book3s_emulate.c+6 -00 replies
3/22powerpc/book3s64/kuap/kuep: Add PPC_PKEY config on book3s64arch/powerpc/include/asm/book3s/64/kup-radix.h arch/powerpc/include/asm/book3s/64/mmu.h arch/powerpc/include/asm/ptrace.h +4 more+33 -140 replies
4/22powerpc/book3s64/kuap/kuep: Move uamor setup to pkey initarch/powerpc/mm/book3s64/radix_pgtable.c+3 -30 replies
5/22powerpc/book3s64/kuap: Move KUAP related function outside radixarch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/include/asm/kup.h arch/powerpc/mm/book3s64/pkeys.c +1 more+28 -230 replies
6/22powerpc/book3s64/kuep: Move KUEP related function outside radixarch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/mm/book3s64/pkeys.c arch/powerpc/mm/book3s64/radix_pgtable.c+22 -200 replies
7/22powerpc/book3s64/kuap: Rename MMU_FTR_RADIX_KUAP and MMU_FTR_KUEParch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/include/asm/mmu.h arch/powerpc/mm/book3s64/pkeys.c+25 -210 replies
8/22powerpc/book3s64/kuap: Use Key 3 for kernel mapping with hash translationarch/powerpc/include/asm/book3s/64/hash-pkey.h arch/powerpc/include/asm/book3s/64/hash.h arch/powerpc/include/asm/book3s/64/mmu-hash.h +8 more+46 -180 replies
9/22powerpc/exec: Set thread.regs early during execarch/powerpc/include/asm/thread_info.h arch/powerpc/kernel/process.c+13 -160 replies
10/22powerpc/book3s64/pkeys: Store/restore userspace AMR/IAMR correctly on entry and exit from kernelarch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/include/asm/ptrace.h arch/powerpc/kernel/asm-offsets.c +3 more+225 -460 replies
11/22powerpc/book3s64/pkeys: Inherit correctly on fork.arch/powerpc/kernel/process.c+10 -00 replies
12/22powerpc/book3s64/pkeys: Reset userspace AMR correctly on execarch/powerpc/include/asm/book3s/64/pkeys.h arch/powerpc/kernel/process.c arch/powerpc/mm/book3s64/pkeys.c+9 -150 replies
13/22powerpc/ptrace-view: Use pt_regs values instead of thread_struct based one.arch/powerpc/kernel/ptrace/ptrace-view.c+4 -30 replies
14/22powerpc/book3s64/pkeys: Don't update SPRN_AMR when in kernel mode.arch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/include/asm/processor.h arch/powerpc/kernel/process.c +2 more+31 -610 replies
15/22powerpc/book3s64/kuap: Restrict access to userspace based on userspace AMRarch/powerpc/include/asm/book3s/64/kup.h+9 -30 replies
16/22powerpc/book3s64/kuap: Improve error reporting with KUAParch/powerpc/include/asm/book3s/32/kup.h arch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/include/asm/kup.h +2 more+29 -120 replies
17/22powerpc/book3s64/kuap: Use Key 3 to implement KUAP with hash translation.arch/powerpc/include/asm/book3s/64/kup.h+4 -50 replies
18/22powerpc/book3s64/kuep: Use Key 3 to implement KUEP with hash translation.arch/powerpc/include/asm/book3s/64/kup.h+1 -10 replies
19/22powerpc/book3s64/hash/kuap: Enable kuap on hasharch/powerpc/mm/book3s64/pkeys.c+6 -10 replies
20/22powerpc/book3s64/hash/kuep: Enable KUEP on hasharch/powerpc/mm/book3s64/pkeys.c+6 -10 replies
21/22powerpc/book3s64/hash/kup: Don't hardcode kup keyarch/powerpc/include/asm/book3s/64/hash-pkey.h arch/powerpc/include/asm/book3s/64/pkeys.h arch/powerpc/mm/book3s64/pkeys.c+50 -370 replies
21/22powerpc/book3s64/kup: Check max key supported before enabling kuparch/powerpc/include/asm/kup.h arch/powerpc/mm/book3s64/pkeys.c arch/powerpc/mm/init-common.c+26 -141 reply
22/22powerpc/book3s64/pkeys: Optimize KUAP and KUEP feature disabled casearch/powerpc/include/asm/book3s/64/kup.h arch/powerpc/kernel/entry_64.S arch/powerpc/kernel/syscall_64.c+67 -100 replies

Reviews trailers per patch

10 of 23 patches have a Reviewed-by or Acked-by.

PatchSandipan Das
1/22
2/22
3/22
4/22
5/22
6/22
7/22
8/22R-b
9/22
10/22R-b
11/22R-b
12/22R-b
13/22
14/22R-b
15/22R-b
16/22
17/22R-b
18/22R-b
19/22R-b
20/22R-b
21/22
21/22
22/22

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 00/22] Kernel userspace access/execution prevention with hash translation

This patch series implements KUAP and KUEP with hash translation mode using memory keys. The kernel now uses memory protection key 3 to control access to the kernel. Kernel page table entries are now configured with key 3. Access to locations configured with any other key value is denied when in kernel mode (MSR_PR=0). This includes userspace which is by default configured with key 0.

null-syscall benchmark results:

With smap/smep disabled:
Without patch:

	845.29 ns    2451.44 cycles
With patch series:
	858.38 ns    2489.30 cycles

With smap/smep enabled:
Without patch:
NA
With patch series:

	1021.51 ns    2962.44 cycles

Changes from v6:
* Address review comments
* Rename MMU FTR defines

Changes from v5:
* Rework the patch based on suggestion from Michael to avoid the usage of CONFIG_PPC_PKEY on BOOKE platforms.

Changes from v4:
* Repost with other pkey related changes split out as a separate series.
* Improve null-syscall benchmark by optimizing SPRN save and restore.

Changes from v3:
* Fix build error reported by kernel test robot <[email protected]>

Changes from v2:
* Rebase to the latest kernel.
* Fixed a bug with disabling KUEP/KUAP on kernel command line
* Added a patch to make kup key dynamic.

Changes from V1:
* Rebased on latest kernel

Aneesh Kumar K.V (22):
powerpc: Add new macro to handle NESTED_IFCLR
KVM: PPC: BOOK3S: PR: Ignore UAMOR SPR powerpc/book3s64/kuap/kuep: Add PPC_PKEY config on book3s64 powerpc/book3s64/kuap/kuep: Move uamor setup to pkey init powerpc/book3s64/kuap: Move KUAP related function outside radix powerpc/book3s64/kuep: Move KUEP related function outside radix powerpc/book3s64/kuap: Rename MMU_FTR_RADIX_KUAP and MMU_FTR_KUEP powerpc/book3s64/kuap: Use Key 3 for kernel mapping with hash
translation
powerpc/exec: Set thread.regs early during exec powerpc/book3s64/pkeys: Store/restore userspace AMR/IAMR correctly on
entry and exit from kernel
powerpc/book3s64/pkeys: Inherit correctly on fork. powerpc/book3s64/pkeys: Reset userspace AMR correctly on exec powerpc/ptrace-view: Use pt_regs values instead of thread_struct based
one.
powerpc/book3s64/pkeys: Don't update SPRN_AMR when in kernel mode. powerpc/book3s64/kuap: Restrict access to userspace based on userspace
AMR
powerpc/book3s64/kuap: Improve error reporting with KUAP powerpc/book3s64/kuap: Use Key 3 to implement KUAP with hash
translation.
powerpc/book3s64/kuep: Use Key 3 to implement KUEP with hash
translation.
powerpc/book3s64/hash/kuap: Enable kuap on hash powerpc/book3s64/hash/kuep: Enable KUEP on hash powerpc/book3s64/hash/kup: Don't hardcode kup key powerpc/book3s64/pkeys: Optimize KUAP and KUEP feature disabled case

 arch/powerpc/include/asm/book3s/32/kup.h      |   4 +-
 .../powerpc/include/asm/book3s/64/hash-pkey.h |  10 +-
 arch/powerpc/include/asm/book3s/64/hash.h     |   2 +-
 .../powerpc/include/asm/book3s/64/kup-radix.h | 203 --------
 arch/powerpc/include/asm/book3s/64/kup.h      | 442 ++++++++++++++++++
 arch/powerpc/include/asm/book3s/64/mmu-hash.h |   1 +
 arch/powerpc/include/asm/book3s/64/mmu.h      |   2 +-
 arch/powerpc/include/asm/book3s/64/pkeys.h    |   3 +
 arch/powerpc/include/asm/feature-fixups.h     |   3 +
 arch/powerpc/include/asm/kup.h                |   8 +-
 arch/powerpc/include/asm/mmu.h                |  24 +-
 arch/powerpc/include/asm/mmu_context.h        |   2 +-
 arch/powerpc/include/asm/nohash/32/kup-8xx.h  |   4 +-
 arch/powerpc/include/asm/processor.h          |   4 -
 arch/powerpc/include/asm/ptrace.h             |  12 +-
 arch/powerpc/include/asm/thread_info.h        |   2 -
 arch/powerpc/kernel/asm-offsets.c             |   5 +
 arch/powerpc/kernel/entry_64.S                |   6 +-
 arch/powerpc/kernel/exceptions-64s.S          |   4 +-
 arch/powerpc/kernel/process.c                 |  47 +-
 arch/powerpc/kernel/ptrace/ptrace-view.c      |   7 +-
 arch/powerpc/kernel/syscall_64.c              |  38 +-
 arch/powerpc/kernel/traps.c                   |   6 -
 arch/powerpc/kvm/book3s_emulate.c             |   6 +
 arch/powerpc/mm/book3s64/Makefile             |   2 +-
 arch/powerpc/mm/book3s64/hash_4k.c            |   2 +-
 arch/powerpc/mm/book3s64/hash_64k.c           |   4 +-
 arch/powerpc/mm/book3s64/hash_hugepage.c      |   2 +-
 arch/powerpc/mm/book3s64/hash_hugetlbpage.c   |   2 +-
 arch/powerpc/mm/book3s64/hash_pgtable.c       |   2 +-
 arch/powerpc/mm/book3s64/hash_utils.c         |  10 +-
 arch/powerpc/mm/book3s64/pkeys.c              | 177 ++++---
 arch/powerpc/mm/book3s64/radix_pgtable.c      |  45 +-
 arch/powerpc/mm/fault.c                       |   2 +-
 arch/powerpc/platforms/Kconfig.cputype        |   5 +
 35 files changed, 709 insertions(+), 389 deletions(-)
 delete mode 100644 arch/powerpc/include/asm/book3s/64/kup-radix.h
 create mode 100644 arch/powerpc/include/asm/book3s/64/kup.h
Signature · 1 line
2.28.0