https://github.com/torvalds/linux
Revision 070c43eea5043e950daa423707ae3c77e2f48edb authored by Thiago Jung Bauermann on 01 September 2016, 23:14:44 UTC, committed by Linus Torvalds on 02 September 2016, 00:52:01 UTC
If kexec_apply_relocations fails, kexec_load_purgatory frees pi->sechdrs
and pi->purgatory_buf.  This is redundant, because in case of error
kimage_file_prepare_segments calls kimage_file_post_load_cleanup, which
will also free those buffers.

This causes two warnings like the following, one for pi->sechdrs and the
other for pi->purgatory_buf:

  kexec-bzImage64: Loading purgatory failed
  ------------[ cut here ]------------
  WARNING: CPU: 1 PID: 2119 at mm/vmalloc.c:1490 __vunmap+0xc1/0xd0
  Trying to vfree() nonexistent vm area (ffffc90000e91000)
  Modules linked in:
  CPU: 1 PID: 2119 Comm: kexec Not tainted 4.8.0-rc3+ #5
  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011
  Call Trace:
    dump_stack+0x4d/0x65
    __warn+0xcb/0xf0
    warn_slowpath_fmt+0x4f/0x60
    ? find_vmap_area+0x19/0x70
    ? kimage_file_post_load_cleanup+0x47/0xb0
    __vunmap+0xc1/0xd0
    vfree+0x2e/0x70
    kimage_file_post_load_cleanup+0x5e/0xb0
    SyS_kexec_file_load+0x448/0x680
    ? putname+0x54/0x60
    ? do_sys_open+0x190/0x1f0
    entry_SYSCALL_64_fastpath+0x13/0x8f
  ---[ end trace 158bb74f5950ca2b ]---

Fix by setting pi->sechdrs an pi->purgatory_buf to NULL, since vfree
won't try to free a NULL pointer.

Link: http://lkml.kernel.org/r/1472083546-23683-1-git-send-email-bauerman@linux.vnet.ibm.com
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Acked-by: Baoquan He <bhe@redhat.com>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
Cc: Dave Young <dyoung@redhat.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 6b4e318
History
Tip revision: 070c43eea5043e950daa423707ae3c77e2f48edb authored by Thiago Jung Bauermann on 01 September 2016, 23:14:44 UTC
kexec: fix double-free when failing to relocate the purgatory
Tip revision: 070c43e
File Mode Size
partitions
Kconfig -rw-r--r-- 3.7 KB
Kconfig.iosched -rw-r--r-- 1.6 KB
Makefile -rw-r--r-- 922 bytes
badblocks.c -rw-r--r-- 14.1 KB
bio-integrity.c -rw-r--r-- 14.2 KB
bio.c -rw-r--r-- 48.5 KB
blk-cgroup.c -rw-r--r-- 35.8 KB
blk-core.c -rw-r--r-- 93.1 KB
blk-exec.c -rw-r--r-- 3.2 KB
blk-flush.c -rw-r--r-- 15.4 KB
blk-integrity.c -rw-r--r-- 12.3 KB
blk-ioc.c -rw-r--r-- 10.2 KB
blk-lib.c -rw-r--r-- 6.9 KB
blk-map.c -rw-r--r-- 5.8 KB
blk-merge.c -rw-r--r-- 19.6 KB
blk-mq-cpu.c -rw-r--r-- 1.6 KB
blk-mq-cpumap.c -rw-r--r-- 2.6 KB
blk-mq-sysfs.c -rw-r--r-- 11.4 KB
blk-mq-tag.c -rw-r--r-- 17.4 KB
blk-mq-tag.h -rw-r--r-- 2.6 KB
blk-mq.c -rw-r--r-- 58.0 KB
blk-mq.h -rw-r--r-- 3.3 KB
blk-settings.c -rw-r--r-- 27.0 KB
blk-softirq.c -rw-r--r-- 4.4 KB
blk-sysfs.c -rw-r--r-- 18.5 KB
blk-tag.c -rw-r--r-- 10.0 KB
blk-throttle.c -rw-r--r-- 42.5 KB
blk-timeout.c -rw-r--r-- 5.9 KB
blk.h -rw-r--r-- 9.1 KB
bounce.c -rw-r--r-- 5.8 KB
bsg-lib.c -rw-r--r-- 6.0 KB
bsg.c -rw-r--r-- 22.9 KB
cfq-iosched.c -rw-r--r-- 127.0 KB
cmdline-parser.c -rw-r--r-- 4.9 KB
compat_ioctl.c -rw-r--r-- 20.8 KB
deadline-iosched.c -rw-r--r-- 11.3 KB
elevator.c -rw-r--r-- 23.8 KB
genhd.c -rw-r--r-- 45.0 KB
ioctl.c -rw-r--r-- 14.6 KB
ioprio.c -rw-r--r-- 5.1 KB
noop-iosched.c -rw-r--r-- 2.6 KB
partition-generic.c -rw-r--r-- 14.7 KB
scsi_ioctl.c -rw-r--r-- 19.4 KB
t10-pi.c -rw-r--r-- 4.8 KB

back to top