linux-xiaomi-chiron/arch/powerpc/include/asm
Aneesh Kumar K.V 5d2e5dd584 powerpc/mm/hash: Fix sharing context ids between kernel & userspace
Commit 0034d395f8 ("powerpc/mm/hash64: Map all the kernel regions in
the same 0xc range") has a bug in the definition of MIN_USER_CONTEXT.

The result is that the context id used for the vmemmap and the lowest
context id handed out to userspace are the same. The context id is
essentially the process identifier as far as the first stage of the
MMU translation is concerned.

This can result in multiple SLB entries with the same VSID (Virtual
Segment ID), accessible to the kernel and some random userspace
process that happens to get the overlapping id, which is not expected
eg:

  07 c00c000008000000 40066bdea7000500  1T  ESID=   c00c00  VSID=      66bdea7 LLP:100
  12 0002000008000000 40066bdea7000d80  1T  ESID=      200  VSID=      66bdea7 LLP:100

Even though the user process and the kernel use the same VSID, the
permissions in the hash page table prevent the user process from
reading or writing to any kernel mappings.

It can also lead to SLB entries with different base page size
encodings (LLP), eg:

  05 c00c000008000000 00006bde0053b500 256M ESID=c00c00000  VSID=    6bde0053b LLP:100
  09 0000000008000000 00006bde0053bc80 256M ESID=        0  VSID=    6bde0053b LLP:  0

Such SLB entries can result in machine checks, eg. as seen on a G5:

  Oops: Machine check, sig: 7 [#1]
  BE PAGE SIZE=64K MU-Hash SMP NR_CPUS=4 NUMA Power Mac
  NIP: c00000000026f248 LR: c000000000295e58 CTR: 0000000000000000
  REGS: c0000000erfd3d70 TRAP: 0200 Tainted: G M (5.5.0-rcl-gcc-8.2.0-00010-g228b667d8ea1)
  MSR: 9000000000109032 <SF,HV,EE,ME,IR,DR,RI> CR: 24282048 XER: 00000000
  DAR: c00c000000612c80 DSISR: 00000400 IRQMASK: 0
  ...
  NIP [c00000000026f248] .kmem_cache_free+0x58/0x140
  LR  [c088000008295e58] .putname 8x88/0xa
  Call Trace:
    .putname+0xB8/0xa
    .filename_lookup.part.76+0xbe/0x160
    .do_faccessat+0xe0/0x380
    system_call+0x5c/ex68

This happens with 256MB segments and 64K pages, as the duplicate VSID
is hit with the first vmemmap segment and the first user segment, and
older 32-bit userspace maps things in the first user segment.

On other CPUs a machine check is not seen. Instead the userspace
process can get stuck continuously faulting, with the fault never
properly serviced, due to the kernel not understanding that there is
already a HPTE for the address but with inaccessible permissions.

On machines with 1T segments we've not seen the bug hit other than by
deliberately exercising it. That seems to be just a matter of luck
though, due to the typical layout of the user virtual address space
and the ranges of vmemmap that are typically populated.

To fix it we add 2 to MIN_USER_CONTEXT. This ensures the lowest
context given to userspace doesn't overlap with the VMEMMAP context,
or with the context for INVALID_REGION_ID.

Fixes: 0034d395f8 ("powerpc/mm/hash64: Map all the kernel regions in the same 0xc range")
Cc: stable@vger.kernel.org # v5.2+
Reported-by: Christian Marillat <marillat@debian.org>
Reported-by: Romain Dolbeau <romain@dolbeau.org>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
[mpe: Account for INVALID_REGION_ID, mostly rewrite change log]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200123102547.11623-1-mpe@ellerman.id.au
2020-01-23 21:26:20 +11:00
..
book3s powerpc/mm/hash: Fix sharing context ids between kernel & userspace 2020-01-23 21:26:20 +11:00
nohash powerpc: permanently include 8xx registers in reg.h 2019-11-18 22:27:52 +11:00
8xx_immap.h
accounting.h
agp.h
archrandom.h powerpc/archrandom: fix arch_get_random_seed_int() 2019-12-05 08:21:16 +11:00
asm-405.h
asm-compat.h
asm-const.h
asm-offsets.h
asm-prototypes.h y2038: syscall implementation cleanups 2019-12-01 14:00:59 -08:00
async_tx.h
atomic.h
backlight.h
barrier.h
bitops.h powerpc: support KASAN instrumentation of bitops 2019-11-07 13:15:40 +11:00
bootx.h
btext.h
bug.h powerpc: Refactor BUG/WARN macros 2019-11-18 22:27:51 +11:00
bugs.h
cache.h powerpc: Convert flush_icache_range & friends to C 2019-11-07 23:35:37 +11:00
cacheflush.h powerpc: Convert flush_icache_range & friends to C 2019-11-07 23:35:37 +11:00
cell-pmu.h
cell-regs.h
checksum.h
cmpxchg.h
code-patching-asm.h
code-patching.h
compat.h
context_tracking.h
copro.h
cpm.h
cpm1.h
cpm2.h
cpu_has_feature.h
cpufeature.h
cpuidle.h
cputable.h powerpc/mm: Fixup tlbie vs mtpidr/mtlpidr ordering issue on POWER9 2019-09-24 20:58:55 +10:00
cputhreads.h
cputime.h
current.h powerpc/64: allow compiler to cache 'current' 2019-08-20 21:22:15 +10:00
dbdma.h
dbell.h
dcr-generic.h
dcr-mmio.h
dcr-native.h
dcr-regs.h
dcr.h
debug.h
debugfs.h
delay.h
device.h
disassemble.h
dma-direct.h powerpc: remove support for NULL dev in __phys_to_dma / __dma_to_phys 2019-11-20 20:31:40 +01:00
dma.h
drmem.h
dt_cpu_ftrs.h
edac.h
eeh.h powerpc/eeh: Fix build with STACKTRACE=n 2019-09-14 00:01:14 +10:00
eeh_event.h
ehv_pic.h
elf.h powerpc/prom_init: Undo relocation before entering secure mode 2019-10-29 15:12:17 +11:00
elfnote.h powerpc: Add PowerPC Capabilities ELF note 2019-08-30 09:40:15 +10:00
emergency-restart.h
emulated_ops.h
epapr_hcalls.h
exception-64e.h
exception-64s.h
exec.h
extable.h
fadump-internal.h powerpc/fadump: support holes in kernel boot memory area 2019-09-14 00:04:46 +10:00
fadump.h powerpc/fadump: add support to preserve crash data on FADUMP disabled kernel 2019-09-14 00:04:45 +10:00
fb.h
feature-fixups.h
firmware.h powerpc/powernv: Introduce FW_FEATURE_ULTRAVISOR 2019-08-30 09:40:15 +10:00
fixmap.h powerpc/83xx: map IMMR with a BAT. 2019-11-19 19:38:38 +11:00
floppy.h
fs_pd.h
fsl_85xx_cache_sram.h
fsl_gtm.h
fsl_hcalls.h
fsl_lbc.h
fsl_pamu_stash.h
fsl_pm.h
ftrace.h powerpc/ftrace: Enable HAVE_FUNCTION_GRAPH_RET_ADDR_PTR 2019-09-18 12:24:55 +10:00
futex.h powerpc/futex: Fix warning: 'oldval' may be used uninitialized in this function 2019-08-20 21:22:12 +10:00
grackle.h
hardirq.h
head-64.h powerpc/64s/exception: move head-64.h exception code to exception-64s.S 2019-08-30 10:32:36 +10:00
heathrow.h
highmem.h
hmi.h
hugetlb.h powerpc/mm: move FSL_BOOK3 version of update_mmu_cache() 2019-08-20 21:22:14 +10:00
hvcall.h KVM: PPC: Book3S HV: Shared pages support for secure guests 2019-11-28 16:47:38 +11:00
hvconsole.h
hvcserver.h
hvsi.h
hw_breakpoint.h powerpc/watchpoint: Fix ptrace code that muck around with address/len 2019-11-13 16:58:03 +11:00
hw_irq.h powerpc: cleanup hw_irq.h 2019-11-18 22:27:52 +11:00
hydra.h
i8259.h
ibmebus.h
icswx.h
ide.h
ima.h
imc-pmu.h
immap_cpm2.h
io-defs.h
io-workarounds.h powerpc/mm: rework io-workaround invocation. 2019-08-27 13:03:34 +10:00
io.h powerpc/mm: split out early ioremap path. 2019-08-27 13:03:35 +10:00
io_event_irq.h
iommu.h Merge branch 'topic/ppc-kvm' into next 2019-08-30 09:52:57 +10:00
ipic.h
irq.h
irq_work.h
irqflags.h
isa-bridge.h
jump_label.h
kasan.h
Kbuild pci-v5.5-changes 2019-12-03 13:58:22 -08:00
kdebug.h
kdump.h
kexec.h
keylargo.h
kgdb.h
kmap_types.h
kprobes.h
kup.h
kvm_asm.h
kvm_book3s.h
kvm_book3s_32.h
kvm_book3s_64.h treewide: Rename rcu_dereference_raw_notrace() to _check() 2019-08-01 14:16:21 -07:00
kvm_book3s_asm.h
kvm_book3s_uvmem.h KVM: PPC: Book3S HV: Handle memory plug/unplug to secure VM 2019-11-28 17:02:26 +11:00
kvm_booke.h
kvm_booke_hv_asm.h
kvm_fpu.h
kvm_host.h KVM: PPC: Book3S HV: Support for running secure guests 2019-11-28 16:30:02 +11:00
kvm_para.h
kvm_ppc.h KVM: PPC: Book3S HV: Support reset of secure guest 2019-11-28 17:02:31 +11:00
libata-portmap.h
linkage.h
livepatch.h
local.h powerpc: Add const qual to local_read() parameter 2019-11-24 15:06:33 -08:00
lppaca.h
lv1call.h
machdep.h powerpc: Remove empty comment 2019-09-05 14:22:41 +10:00
macio.h
mc146818rtc.h
mce.h powerpc/64s/pseries: machine check convert to use common event code 2019-08-30 10:32:35 +10:00
mediabay.h
mem_encrypt.h powerpc/pseries/svm: Force SWIOTLB for secure guests 2019-08-30 09:55:41 +10:00
membarrier.h
mm-arch-hooks.h
mman.h
mmiowb.h
mmu.h powerpc/64s: make mmu_partition_table_set_entry TLB flush optional 2019-09-05 14:22:40 +10:00
mmu_context.h
mmzone.h
module.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
mpc5xxx.h
mpc6xx.h
mpc52xx.h
mpc52xx_psc.h
mpc85xx.h
mpc5121.h
mpc8260.h
mpic.h
mpic_msgr.h
mpic_timer.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152 2019-05-30 11:26:32 -07:00
msi_bitmap.h
nmi.h
nvram.h
ohare.h
opal-api.h powerpc/powernv: Add OPAL API interface to access secure variable 2019-11-13 00:33:22 +11:00
opal.h powerpc/powernv: Add OPAL API interface to access secure variable 2019-11-13 00:33:22 +11:00
oprofile_impl.h
paca.h
page.h powerpc updates for 5.5 2019-11-30 14:35:43 -08:00
page_32.h powerpc/32: Add warning on misaligned copy_page() or clear_page() 2019-08-20 21:22:15 +10:00
page_64.h
parport.h
pasemi_dma.h
pci-bridge.h powerpc/eeh: Fix race when freeing PDNs 2019-09-05 14:22:37 +10:00
pci.h PCI: Convert pci_resource_to_user() to a weak function 2019-08-08 15:12:07 -05:00
percpu.h
perf_event.h
perf_event_fsl_emb.h
perf_event_server.h
pgalloc.h mm: remove quicklist page table caches 2019-09-24 15:54:09 -07:00
pgtable-be-types.h
pgtable-types.h
pgtable.h powerpc/mm: drop #ifdef CONFIG_MMU in is_ioremap_addr() 2019-11-18 22:27:51 +11:00
pkeys.h
plpar_wrappers.h powerpc/ptdump: drop non vital #ifdefs 2019-08-20 21:22:09 +10:00
pmac_feature.h
pmac_low_i2c.h
pmac_pfunc.h
pmc.h
pmi.h
pnv-ocxl.h
pnv-pci.h
powernv.h
ppc-opcode.h
ppc-pci.h powerpc/eeh: Convert log messages to eeh_edev_* macros 2019-08-22 23:12:47 +10:00
ppc4xx.h
ppc_asm.h powerpc/32s: get rid of CPU_FTR_601 feature 2019-08-28 23:19:33 +10:00
probes.h
processor.h
prom.h
ps3.h
ps3av.h
ps3gpu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 340 2019-06-05 17:37:07 +02:00
ps3stor.h
pte-walk.h
ptrace.h powerpc/32s: get rid of CPU_FTR_601 feature 2019-08-28 23:19:33 +10:00
reg.h powerpc updates for 5.5 2019-11-30 14:35:43 -08:00
reg_8xx.h powerpc: permanently include 8xx registers in reg.h 2019-11-18 22:27:52 +11:00
reg_a2.h
reg_booke.h
reg_fsl_emb.h
rheap.h
rio.h
rtas.h
runlatch.h
seccomp.h
sections.h powerpc: Define arch_is_kernel_initmem_freed() for lockdep 2019-11-27 18:41:26 +11:00
secure_boot.h powerpc: Detect the trusted boot state of the system 2019-11-12 12:25:49 +11:00
security_features.h powerpc updates for 5.5 2019-11-30 14:35:43 -08:00
secvar.h powerpc/powernv: Add OPAL API interface to access secure variable 2019-11-13 00:33:22 +11:00
serial.h
setjmp.h powerpc: Add attributes for setjmp/longjmp 2019-09-12 09:26:59 +10:00
setup.h
sfp-machine.h
shmparam.h
signal.h
slice.h
smp.h
smu.h
sparsemem.h
spinlock.h powerpc/spinlocks: Include correct header for static key 2019-12-30 21:20:41 +11:00
spinlock_types.h
spu.h
spu_csa.h
spu_info.h
spu_priv1.h
sstep.h
stackprotector.h
stacktrace.h
string.h powerpc/memcpy: Add memcpy_mcsafe for pmem 2019-08-21 22:23:48 +10:00
svm.h powerpc/pseries/svm: Use shared memory for Debug Trace Log (DTL) 2019-08-30 09:55:40 +10:00
swab.h
swiotlb.h
switch_to.h
synch.h
syscall.h
syscalls.h
task_size_32.h
task_size_64.h
tce.h
termios.h
thread_info.h
time.h powerpc/32s: drop CPU_FTR_USE_RTC feature 2019-08-28 23:19:33 +10:00
timex.h powerpc/32s: get rid of CPU_FTR_601 feature 2019-08-28 23:19:33 +10:00
tlb.h
tlbflush.h
tm.h
topology.h
trace.h
trace_clock.h
tsi108.h
tsi108_irq.h
tsi108_pci.h
types.h
uaccess.h powerpc: Fix __clear_user() with KUAP enabled 2019-12-16 23:19:44 +11:00
udbg.h
uic.h
ultravisor-api.h KVM: PPC: Book3S HV: Support reset of secure guest 2019-11-28 17:02:31 +11:00
ultravisor.h KVM: PPC: Book3S HV: Support reset of secure guest 2019-11-28 17:02:31 +11:00
unaligned.h
uninorth.h
unistd.h powerpc: Wire up clone3 syscall 2019-07-29 09:34:27 +10:00
uprobes.h
user.h
vas.h
vdso.h
vdso_datapage.h powerpc: Fix vDSO clock_getres() 2019-12-05 00:13:55 +11:00
vga.h
vio.h
word-at-a-time.h
xics.h
xilinx_intc.h
xilinx_pci.h
xive-regs.h powerpc/xive: Discard ESB load value when interrupt is invalid 2020-01-22 20:31:41 +11:00
xive.h powerpc updates for 5.4 2019-09-20 11:48:06 -07:00
xmon.h
xor.h
xor_altivec.h