From: James Le Cuirot <chewi@gentoo.org>
To: Ard Biesheuvel <ardb@kernel.org>, Ingo Molnar <mingo@kernel.org>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH] x86: fix oops caused by old EFI info on kexec boot
Date: Thu, 04 Dec 2025 21:40:09 +0000 [thread overview]
Message-ID: <552cf43e8ce7c7e430cd18feb20efb1dee2350e0.camel@gentoo.org> (raw)
In-Reply-To: <CAMj1kXF37bqxObpf11Lj=iCCCGNEYVZQU-AS2PFKAwOA7fT2ug@mail.gmail.com>
On Thu, 2025-12-04 at 00:01 +0100, Ard Biesheuvel wrote:
> On Wed, 3 Dec 2025 at 23:57, Ard Biesheuvel <ardb@kernel.org> wrote:
> >
> > On Wed, 3 Dec 2025 at 19:13, Ingo Molnar <mingo@kernel.org> wrote:
> > >
> > > * James Le Cuirot <chewi@gentoo.org> wrote:
> > >
> > > > kexec on x86 passes initrd details via the boot_params. If no initrd is
> > > > supplied, then ramdisk_size is 0. When determining whether to reserve
> > > > memory for the initrd on the subsequent boot, ramdisk_size being 0
> > > > causes the logic to fall back to phys_initrd_start and phys_initrd_size
> > > > set from the EFI tables in efi.c. This is stale information from the
> > > > initial boot. The system continues to boot and has even been seen to
> > > > function under heavy load for days, but allocating very large amounts of
> > > > memory reliably triggers an oops rather than the OOM killer.
> > > >
> > > > BUG: kernel NULL pointer dereference, address: 0000000000000008
> > > > #PF: supervisor write access in kernel mode
> > > > #PF: error_code(0x0002) - not-present page
> > > > PGD 0 P4D 0
> > > > Oops: Oops: 0002 [#1] SMP NOPTI
> > > >
> > > > This issue was introduced in f4dc7fffa9873db50ec25624572f8217a6225de8
> > > > when the EFI stub initrd loading was unified between architectures.
> > > >
> > > > Avoid the issue by checking whether the bootloader is not kexec before
> > > > falling back to the EFI table values.
> > > >
> > > > I strongly suspect this also affects other architectures. A different
> > > > fix would be required there, and I do have a fix in mind, but I was
> > > > unable to reproduce the issue under QEMU's aarch64 virt machine. I think
> > > > this is at least partly because it relies on ACPI while kexec passes the
> > > > initd details via the device tree.
> > > >
> > > > Signed-off-by: James Le Cuirot <chewi@gentoo.org>
> > > > ---
> > > > arch/x86/kernel/setup.c | 6 ++++--
> > > > 1 file changed, 4 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
> > > > index 1b2edd07a3e1..8aa65daf121f 100644
> > > > --- a/arch/x86/kernel/setup.c
> > > > +++ b/arch/x86/kernel/setup.c
> > > > @@ -300,7 +300,8 @@ static u64 __init get_ramdisk_image(void)
> > > >
> > > > ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
> > > >
> > > > - if (ramdisk_image == 0)
> > > > + /* Don't fall back for kexec as phys_initrd_start will be stale */
> > > > + if (ramdisk_image == 0 && (boot_params.hdr.type_of_loader >> 4) != 0xD)
> > > > ramdisk_image = phys_initrd_start;
> > > >
> > > > return ramdisk_image;
> > > > @@ -311,7 +312,8 @@ static u64 __init get_ramdisk_size(void)
> > > >
> > > > ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
> > > >
> > > > - if (ramdisk_size == 0)
> > > > + /* Don't fall back for kexec as phys_initrd_start will be stale */
> > > > + if (ramdisk_size == 0 && (boot_params.hdr.type_of_loader >> 4) != 0xD)
> > > > ramdisk_size = phys_initrd_size;
> > >
> > > Yeah, so this looks like a good fix - but please let's
> > > introduce some sort of enum for the bootloader IDs
> > > in arch/x86/include/uapi/asm/bootparam.h, I had to search
> > > way too long to figure out what 0xD is and where it
> > > was defined :-)
> > >
> > > Also, please introduce a "x86_bootloader_is_kexec()" kind
> > > of helper inline function as well.
> > >
> >
> > It might be better to fix this in the generic EFI code, and simply
> > wipe the EFI config table that the EFI stub created to pass the initrd
> > info. That way, it works for all architectures, and there is no need
> > for special x86 hacks.
>
> I.e.,
>
> --- a/drivers/firmware/efi/efi.c
> +++ b/drivers/firmware/efi/efi.c
> @@ -818,6 +818,7 @@
> if (tbl) {
> phys_initrd_start = tbl->base;
> phys_initrd_size = tbl->size;
> + tbl->base = tbl->size = 0;
> early_memunmap(tbl, sizeof(*tbl));
> }
> }
I can confirm that this fixes the problem. I had considered wiping the table,
but I was trying to do it later, which seemed harder to do. I didn't consider
wiping it immediately, but I now realise this data isn't needed afterwards. I
only tested amd64, but I trust it will work for other architectures. Please go
ahead with this.
next prev parent reply other threads:[~2025-12-04 21:40 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 17:32 James Le Cuirot
2025-12-03 18:12 ` Ingo Molnar
2025-12-03 20:59 ` H. Peter Anvin
2025-12-03 21:27 ` H. Peter Anvin
2025-12-06 11:45 ` Ingo Molnar
2025-12-03 22:57 ` Ard Biesheuvel
2025-12-03 23:01 ` Ard Biesheuvel
2025-12-04 21:40 ` James Le Cuirot [this message]
2025-12-04 23:18 ` H. Peter Anvin
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=552cf43e8ce7c7e430cd18feb20efb1dee2350e0.camel@gentoo.org \
--to=chewi@gentoo.org \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®