Skip to content

Commit

Permalink
x86/kexec: Fix double-free of elf header buffer
Browse files Browse the repository at this point in the history
After

  b3e34a4 ("x86/kexec: fix memory leak of elf header buffer"),

freeing image->elf_headers in the error path of crash_load_segments()
is not needed because kimage_file_post_load_cleanup() will take
care of that later. And not clearing it could result in a double-free.

Drop the superfluous vfree() call at the error path of
crash_load_segments().

Fixes: b3e34a4 ("x86/kexec: fix memory leak of elf header buffer")
Signed-off-by: Takashi Iwai <[email protected]>
Signed-off-by: Borislav Petkov (AMD) <[email protected]>
Acked-by: Baoquan He <[email protected]>
Acked-by: Vlastimil Babka <[email protected]>
Cc: <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
tiwai authored and bp3tk0v committed Jan 2, 2023
1 parent 88603b6 commit d00dd2f
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions arch/x86/kernel/crash.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,8 @@ int crash_load_segments(struct kimage *image)
kbuf.buf_align = ELF_CORE_HEADER_ALIGN;
kbuf.mem = KEXEC_BUF_MEM_UNKNOWN;
ret = kexec_add_buffer(&kbuf);
if (ret) {
vfree((void *)image->elf_headers);
if (ret)
return ret;
}
image->elf_load_addr = kbuf.mem;
pr_debug("Loaded ELF headers at 0x%lx bufsz=0x%lx memsz=0x%lx\n",
image->elf_load_addr, kbuf.bufsz, kbuf.memsz);
Expand Down

0 comments on commit d00dd2f

Please sign in to comment.