Mike Galbraith 5849cdf8c1 x86/crash: Fix crash_setup_memmap_entries() out-of-bounds access
Commit in Fixes: added support for kexec-ing a kernel on panic using a
new system call. As part of it, it does prepare a memory map for the new
kernel.

However, while doing so, it wrongly accesses memory it has not
allocated: it accesses the first element of the cmem->ranges[] array in
memmap_exclude_ranges() but it has not allocated the memory for it in
crash_setup_memmap_entries(). As KASAN reports:

  BUG: KASAN: vmalloc-out-of-bounds in crash_setup_memmap_entries+0x17e/0x3a0
  Write of size 8 at addr ffffc90000426008 by task kexec/1187

  (gdb) list *crash_setup_memmap_entries+0x17e
  0xffffffff8107cafe is in crash_setup_memmap_entries (arch/x86/kernel/crash.c:322).
  317                                      unsigned long long mend)
  318     {
  319             unsigned long start, end;
  320
  321             cmem->ranges[0].start = mstart;
  322             cmem->ranges[0].end = mend;
  323             cmem->nr_ranges = 1;
  324
  325             /* Exclude elf header region */
  326             start = image->arch.elf_load_addr;
  (gdb)

Make sure the ranges array becomes a single element allocated.

 [ bp: Write a proper commit message. ]

Fixes: dd5f726076cc ("kexec: support for kexec on panic using new system call")
Signed-off-by: Mike Galbraith <efault@gmx.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Reviewed-by: Dave Young <dyoung@redhat.com>
Cc: <stable@vger.kernel.org>
Link: https://lkml.kernel.org/r/725fa3dc1da2737f0f6188a1a9701bead257ea9d.camel@gmx.de
2021-04-20 17:32:46 +02:00
..
2021-02-24 16:32:23 -08:00
2020-11-19 11:43:17 +01:00
2020-03-30 19:14:28 -07:00
2020-11-24 16:47:49 +01:00
2020-11-20 17:43:15 +01:00
2021-02-24 16:32:23 -08:00
2019-11-12 16:21:15 +01:00
2019-11-12 16:21:15 +01:00
2021-02-21 13:31:43 -08:00
2020-06-02 10:59:12 -07:00
2020-08-20 13:12:58 +02:00
2020-06-11 15:54:31 -07:00
2020-07-27 14:31:07 -04:00
2020-07-27 14:31:07 -04:00
2020-02-16 20:58:06 +01:00
2020-09-10 11:19:29 +02:00
2020-08-04 14:47:45 -07:00
2020-12-14 17:34:12 -08:00