1
0
Fork 0
alistair23-linux/arch
Libor Pechacek 27993365c0 powerpc/pseries: Avoid NULL pointer dereference when drmem is unavailable
commit a83836dbc5 upstream.

In guests without hotplugagble memory drmem structure is only zero
initialized. Trying to manipulate DLPAR parameters results in a crash.

  $ echo "memory add count 1" > /sys/kernel/dlpar
  Oops: Kernel access of bad area, sig: 11 [#1]
  LE PAGE_SIZE=64K MMU=Hash SMP NR_CPUS=2048 NUMA pSeries
  ...
  NIP:  c0000000000ff294 LR: c0000000000ff248 CTR: 0000000000000000
  REGS: c0000000fb9d3880 TRAP: 0300   Tainted: G            E      (5.5.0-rc6-2-default)
  MSR:  8000000000009033 <SF,EE,ME,IR,DR,RI,LE>  CR: 28242428  XER: 20000000
  CFAR: c0000000009a6c10 DAR: 0000000000000010 DSISR: 40000000 IRQMASK: 0
  ...
  NIP dlpar_memory+0x6e4/0xd00
  LR  dlpar_memory+0x698/0xd00
  Call Trace:
    dlpar_memory+0x698/0xd00 (unreliable)
    handle_dlpar_errorlog+0xc0/0x190
    dlpar_store+0x198/0x4a0
    kobj_attr_store+0x30/0x50
    sysfs_kf_write+0x64/0x90
    kernfs_fop_write+0x1b0/0x290
    __vfs_write+0x3c/0x70
    vfs_write+0xd0/0x260
    ksys_write+0xdc/0x130
    system_call+0x5c/0x68

Taking closer look at the code, I can see that for_each_drmem_lmb is a
macro expanding into `for (lmb = &drmem_info->lmbs[0]; lmb <=
&drmem_info->lmbs[drmem_info->n_lmbs - 1]; lmb++)`. When drmem_info->lmbs
is NULL, the loop would iterate through the whole address range if it
weren't stopped by the NULL pointer dereference on the next line.

This patch aligns for_each_drmem_lmb and for_each_drmem_lmb_in_range
macro behavior with the common C semantics, where the end marker does
not belong to the scanned range, and alters get_lmb_range() semantics.
As a side effect, the wraparound observed in the crash is prevented.

Fixes: 6c6ea53725 ("powerpc/mm: Separate ibm, dynamic-memory data from DT format")
Cc: stable@vger.kernel.org # v4.16+
Signed-off-by: Libor Pechacek <lpechacek@suse.cz>
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20200131132829.10281-1-msuchanek@suse.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-17 10:50:20 +02:00
..
alpha mm: introduce MADV_PAGEOUT 2019-09-25 17:51:41 -07:00
arc ARC: define __ALIGN_STR and __ALIGN symbols for ARC 2020-03-18 07:17:52 +01:00
arm ARM: dts: exynos: Fix polarity of the LCD SPI bus on UniversalC210 board 2020-04-17 10:50:19 +02:00
arm64 arm64: armv8_deprecated: Fix undef_hook mask for thumb setend 2020-04-17 10:50:19 +02:00
c6x mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
csky csky: Implement copy_thread_tls 2020-03-12 13:00:32 +01:00
h8300 mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
hexagon hexagon: work around compiler crash 2020-01-17 19:49:07 +01:00
ia64 mm/memory_hotplug: shrink zones when offlining memory 2020-01-09 10:19:56 +01:00
m68k mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
microblaze microblaze: Prevent the overflow of the start 2020-02-24 08:37:02 +01:00
mips MIPS: OCTEON: irq: Fix potential NULL pointer dereference 2020-04-17 10:50:12 +02:00
nds32 asm-generic/nds32: don't redefine cacheflush primitives 2020-01-17 19:48:43 +01:00
nios2 nios2 update for v5.4-rc1 2019-09-27 13:02:19 -07:00
openrisc mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
parisc parisc: Use proper printk format for resource_size_t 2020-02-05 21:22:46 +00:00
powerpc powerpc/pseries: Avoid NULL pointer dereference when drmem is unavailable 2020-04-17 10:50:20 +02:00
riscv riscv: Fix range looking for kernel image memblock 2020-03-25 08:25:48 +01:00
s390 KVM: s390: vsie: Fix delivery of addressing exceptions 2020-04-17 10:50:13 +02:00
sh pinctrl: sh-pfc: sh7269: Fix CAN function GPIOs 2020-02-24 08:36:41 +01:00
sparc sparc: Add .exit.data section. 2020-02-24 08:36:27 +01:00
um Revert "um: Enable CONFIG_CONSTRUCTORS" 2020-02-01 09:34:53 +00:00
unicore32 mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
x86 KVM: VMX: fix crash cleanup when KVM wasn't used 2020-04-17 10:50:14 +02:00
xtensa xtensa: Implement copy_thread_tls 2020-01-14 20:08:35 +01:00
.gitignore
Kconfig asm-generic/tlb: add missing CONFIG symbol 2020-02-24 08:37:02 +01:00