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
Raw File
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
Kconfig.iosched
if BLOCK

menu "IO Schedulers"

config IOSCHED_NOOP
	bool
	default y
	---help---
	  The no-op I/O scheduler is a minimal scheduler that does basic merging
	  and sorting. Its main uses include non-disk based block devices like
	  memory devices, and specialised software or hardware environments
	  that do their own scheduling and require only minimal assistance from
	  the kernel.

config IOSCHED_DEADLINE
	tristate "Deadline I/O scheduler"
	default y
	---help---
	  The deadline I/O scheduler is simple and compact. It will provide
	  CSCAN service with FIFO expiration of requests, switching to
	  a new point in the service tree and doing a batch of IO from there
	  in case of expiry.

config IOSCHED_CFQ
	tristate "CFQ I/O scheduler"
	default y
	---help---
	  The CFQ I/O scheduler tries to distribute bandwidth equally
	  among all processes in the system. It should provide a fair
	  and low latency working environment, suitable for both desktop
	  and server systems.

	  This is the default I/O scheduler.

config CFQ_GROUP_IOSCHED
	bool "CFQ Group Scheduling support"
	depends on IOSCHED_CFQ && BLK_CGROUP
	default n
	---help---
	  Enable group IO scheduling in CFQ.

choice
	prompt "Default I/O scheduler"
	default DEFAULT_CFQ
	help
	  Select the I/O scheduler which will be used by default for all
	  block devices.

	config DEFAULT_DEADLINE
		bool "Deadline" if IOSCHED_DEADLINE=y

	config DEFAULT_CFQ
		bool "CFQ" if IOSCHED_CFQ=y

	config DEFAULT_NOOP
		bool "No-op"

endchoice

config DEFAULT_IOSCHED
	string
	default "deadline" if DEFAULT_DEADLINE
	default "cfq" if DEFAULT_CFQ
	default "noop" if DEFAULT_NOOP

endmenu

endif
back to top