WSL2-Linux-Kernel/arch/powerpc/mm/book3s64
Michael Ellerman 111bcb3738 powerpc/64s/radix: Fix RWX mapping with relocated kernel
If a relocatable kernel is loaded at a non-zero address and told not to
relocate to zero (kdump or RELOCATABLE_TEST), the mapping of the
interrupt code at zero is left with RWX permissions.

That is a security weakness, and leads to a warning at boot if
CONFIG_DEBUG_WX is enabled:

  powerpc/mm: Found insecure W+X mapping at address 00000000056435bc/0xc000000000000000
  WARNING: CPU: 1 PID: 1 at arch/powerpc/mm/ptdump/ptdump.c:193 note_page+0x484/0x4c0
  CPU: 1 PID: 1 Comm: swapper/0 Not tainted 6.2.0-rc1-00001-g8ae8e98aea82-dirty #175
  Hardware name: IBM pSeries (emulated by qemu) POWER9 (raw) 0x4e1202 0xf000005 of:SLOF,git-dd0dca hv:linux,kvm pSeries
  NIP:  c0000000004a1c34 LR: c0000000004a1c30 CTR: 0000000000000000
  REGS: c000000003503770 TRAP: 0700   Not tainted  (6.2.0-rc1-00001-g8ae8e98aea82-dirty)
  MSR:  8000000002029033 <SF,VEC,EE,ME,IR,DR,RI,LE>  CR: 24000220  XER: 00000000
  CFAR: c000000000545a58 IRQMASK: 0
  ...
  NIP note_page+0x484/0x4c0
  LR  note_page+0x480/0x4c0
  Call Trace:
    note_page+0x480/0x4c0 (unreliable)
    ptdump_pmd_entry+0xc8/0x100
    walk_pgd_range+0x618/0xab0
    walk_page_range_novma+0x74/0xc0
    ptdump_walk_pgd+0x98/0x170
    ptdump_check_wx+0x94/0x100
    mark_rodata_ro+0x30/0x70
    kernel_init+0x78/0x1a0
    ret_from_kernel_thread+0x5c/0x64

The fix has two parts. Firstly the pages from zero up to the end of
interrupts need to be marked read-only, so that they are left with R-X
permissions. Secondly the mapping logic needs to be taught to ensure
there is a page boundary at the end of the interrupt region, so that the
permission change only applies to the interrupt text, and not the region
following it.

Fixes: c55d7b5e64 ("powerpc: Remove STRICT_KERNEL_RWX incompatibility with RELOCATABLE")
Reported-by: Sachin Sant <sachinp@linux.ibm.com>
Tested-by: Sachin Sant <sachinp@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20230110124753.1325426-2-mpe@ellerman.id.au
2023-01-31 21:37:39 +11:00
..
Makefile powerpc: Book3S 64-bit outline-only KASAN support 2022-05-22 15:58:29 +10:00
hash_4k.c powerpc/64s/hash: add stress_hpt kernel boot option to increase hash faults 2022-12-02 18:04:25 +11:00
hash_64k.c powerpc/64s/hash: add stress_hpt kernel boot option to increase hash faults 2022-12-02 18:04:25 +11:00
hash_hugepage.c powerpc/book3s64/kuap: Use Key 3 for kernel mapping with hash translation 2020-12-04 01:01:25 +11:00
hash_native.c powerpc/64s: make HPTE lock and native_tlbie_lock irq-safe 2022-10-18 22:46:18 +11:00
hash_pgtable.c powerpc/64s: Fix hash__change_memory_range preemption warning 2022-10-18 22:46:18 +11:00
hash_tlb.c powerpc/mm/book3s/hash: Rename flush_tlb_pmd_range 2022-09-30 18:35:52 +10:00
hash_utils.c powerpc/64s/hash: Make stress_hpt_timer_fn() static 2023-01-12 10:53:37 +11:00
hugetlbpage.c powerpc/mm: Update default hugetlb size early 2022-02-12 22:47:44 +11:00
internal.h powerpc/64s/hash: add stress_hpt kernel boot option to increase hash faults 2022-12-02 18:04:25 +11:00
iommu_api.c KVM: PPC: Book3s: Retire H_PUT_TCE/etc real mode handlers 2022-05-19 00:44:01 +10:00
mmu_context.c powerpc/mm: Add __init attribute to eligible functions 2021-12-23 22:33:11 +11:00
pgtable.c powerpc: Remove find_current_mm_pte() 2022-11-24 23:12:18 +11:00
pkeys.c powerpc: Include asm/firmware.h in all users of firmware_has_feature() 2022-06-29 16:45:05 +10:00
radix_hugetlbpage.c powerpc/64s: POWER10 nest MMU can upgrade PTE access authority without TLB flush 2022-07-27 21:36:04 +10:00
radix_pgtable.c powerpc/64s/radix: Fix RWX mapping with relocated kernel 2023-01-31 21:37:39 +11:00
radix_tlb.c powerpc/64s: POWER10 nest MMU does not require flush escalation workaround 2022-07-27 21:36:04 +10:00
slb.c powerpc: fix typos in comments 2022-05-05 22:12:44 +10:00
slice.c powerpc/mm: Enable full randomisation of memory mappings 2022-05-05 22:11:58 +10:00
subpage_prot.c powerpc: remove mmap linked list walks 2022-09-26 19:46:19 -07:00
trace.c mm/migration: add trace events for THP migrations 2022-03-24 19:06:45 -07:00