From: Ingo Molnar <mingo@kernel.org>
To: Vlastimil Babka <vbabka@suse.cz>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Takashi Iwai <tiwai@suse.de>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
patches@lists.linux.dev, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, Baoquan He <bhe@redhat.com>,
Dave Young <dyoung@redhat.com>,
stable@vger.kernel.org
Subject: Re: [PATCH] x86/kexec: fix double vfree of image->elf_headers
Date: Tue, 3 Jan 2023 11:15:12 +0100 [thread overview]
Message-ID: <Y7QAMIu6j6Y6m8vV@gmail.com> (raw)
In-Reply-To: <d6e965ca-a568-5193-20a0-19b1c9b42ca2@suse.cz>
* Vlastimil Babka <vbabka@suse.cz> wrote:
> On 1/2/23 11:39, Vlastimil Babka wrote:
> > An investigation of a "Trying to vfree() nonexistent vm area" bug
> > occurring in arch_kimage_file_post_load_cleanup() doing a
> > vfree(image->elf_headers) in our 5.14-based kernel yielded the following
> > double vfree() scenario, also present in mainline:
> >
> > SYSCALL_DEFINE5(kexec_file_load)
> > kimage_file_alloc_init()
> > kimage_file_prepare_segments()
> > arch_kexec_kernel_image_probe()
> > kexec_image_load_default()
> > kexec_bzImage64_ops.load()
> > bzImage64_load()
> > crash_load_segments()
> > prepare_elf_headers(image, &kbuf.buffer, &kbuf.bufsz);
> > image->elf_headers = kbuf.buffer;
> > ret = kexec_add_buffer(&kbuf);
> > if (ret) vfree((void *)image->elf_headers); // first vfree()
> > if (ret) kimage_file_post_load_cleanup()
> > vfree(image->elf_headers); // second vfree()
> >
> > AFAICS the scenario is possible since v5.19 commit b3e34a47f989
> > ("x86/kexec: fix memory leak of elf header buffer") that was marked for
> > stable and also was backported to our kernel.
> >
> > Fix the problem by setting the pointer to NULL after the first vfree().
> > Also set elf_headers_sz to 0, as kimage_file_post_load_cleanup() does.
> >
> > Fixes: b3e34a47f989 ("x86/kexec: fix memory leak of elf header buffer")
> > Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
> > Cc: Baoquan He <bhe@redhat.com>
> > Cc: Dave Young <dyoung@redhat.com>
> > Cc: <stable@vger.kernel.org>
>
> Takashi told me he sent a slightly different fix already in November:
> https://lore.kernel.org/all/20221122115122.13937-1-tiwai@suse.de/
>
> Seems it wasn't picked up? You might pick his then, as Baoquan acked it, and
> it's removing code, not adding it.
Thanks, indeed we missed that fix - Boris picked up that version in
tip:x86/urgent, via:
d00dd2f2645d ("x86/kexec: Fix double-free of elf header buffer")
Ingo
prev parent reply other threads:[~2023-01-03 10:15 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-02 10:39 Vlastimil Babka
2023-01-02 11:24 ` Vlastimil Babka
2023-01-03 10:15 ` Ingo Molnar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y7QAMIu6j6Y6m8vV@gmail.com \
--to=mingo@kernel.org \
--cc=bhe@redhat.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=dyoung@redhat.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mingo@redhat.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tiwai@suse.de \
--cc=vbabka@suse.cz \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox