* [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu()
@ 2025-04-11 19:48 Chenyuan Yang
2025-04-15 13:39 ` Rafael J. Wysocki
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Chenyuan Yang @ 2025-04-11 19:48 UTC (permalink / raw)
To: rafael, lenb, tglx, mingo, bp, dave.hansen, x86, hpa, bhe,
kai.huang, sathyanarayanan.kuppuswamy
Cc: linux-acpi, linux-kernel, Chenyuan Yang
The result of memremap() may be NULL on failure, leading to a NULL
dereference. Add explicit checks after memremap() call: if the
MADT mailbox fails to map, return immediately.
This is similar to the commit 966d47e1f27c
("efi: fix potential NULL deref in efi_mem_reserve_persistent").
This is found by our static analysis tool KNighter.
Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
Fixes: 2b5e22afae07 ("x86/acpi: Extract ACPI MADT wakeup code into a separate file")
---
arch/x86/kernel/acpi/madt_wakeup.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
index f36f28405dcc..b386ec4b87c2 100644
--- a/arch/x86/kernel/acpi/madt_wakeup.c
+++ b/arch/x86/kernel/acpi/madt_wakeup.c
@@ -143,6 +143,10 @@ static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip)
acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr,
sizeof(*acpi_mp_wake_mailbox),
MEMREMAP_WB);
+ if (!acpi_mp_wake_mailbox) {
+ pr_err("Failed to remap MADT mailbox\n");
+ return -ENOMEM;
+ }
}
/*
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu()
2025-04-11 19:48 [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu() Chenyuan Yang
@ 2025-04-15 13:39 ` Rafael J. Wysocki
2025-04-16 7:26 ` Kirill A. Shutemov
2025-04-15 14:25 ` Sathyanarayanan Kuppuswamy
2025-05-16 14:07 ` Rafael J. Wysocki
2 siblings, 1 reply; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-04-15 13:39 UTC (permalink / raw)
To: Chenyuan Yang, Kirill A. Shutemov
Cc: lenb, tglx, mingo, bp, dave.hansen, x86, hpa, bhe, kai.huang,
sathyanarayanan.kuppuswamy, linux-acpi, linux-kernel
On Fri, Apr 11, 2025 at 9:48 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
>
> The result of memremap() may be NULL on failure, leading to a NULL
> dereference. Add explicit checks after memremap() call: if the
> MADT mailbox fails to map, return immediately.
>
> This is similar to the commit 966d47e1f27c
> ("efi: fix potential NULL deref in efi_mem_reserve_persistent").
>
> This is found by our static analysis tool KNighter.
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 2b5e22afae07 ("x86/acpi: Extract ACPI MADT wakeup code into a separate file")
Well, it's good to add the author of the commit you're trying to fix
to the CC list.
Kirill, what do you think about this?
> ---
> arch/x86/kernel/acpi/madt_wakeup.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
> index f36f28405dcc..b386ec4b87c2 100644
> --- a/arch/x86/kernel/acpi/madt_wakeup.c
> +++ b/arch/x86/kernel/acpi/madt_wakeup.c
> @@ -143,6 +143,10 @@ static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip)
> acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr,
> sizeof(*acpi_mp_wake_mailbox),
> MEMREMAP_WB);
> + if (!acpi_mp_wake_mailbox) {
> + pr_err("Failed to remap MADT mailbox\n");
> + return -ENOMEM;
> + }
> }
>
> /*
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu()
2025-04-11 19:48 [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu() Chenyuan Yang
2025-04-15 13:39 ` Rafael J. Wysocki
@ 2025-04-15 14:25 ` Sathyanarayanan Kuppuswamy
2025-05-16 14:07 ` Rafael J. Wysocki
2 siblings, 0 replies; 5+ messages in thread
From: Sathyanarayanan Kuppuswamy @ 2025-04-15 14:25 UTC (permalink / raw)
To: Chenyuan Yang, rafael, lenb, tglx, mingo, bp, dave.hansen, x86,
hpa, bhe, kai.huang
Cc: linux-acpi, linux-kernel
On 4/11/25 12:48 PM, Chenyuan Yang wrote:
> The result of memremap() may be NULL on failure, leading to a NULL
> dereference. Add explicit checks after memremap() call: if the
> MADT mailbox fails to map, return immediately.
>
> This is similar to the commit 966d47e1f27c
> ("efi: fix potential NULL deref in efi_mem_reserve_persistent").
>
> This is found by our static analysis tool KNighter.
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 2b5e22afae07 ("x86/acpi: Extract ACPI MADT wakeup code into a separate file")
> ---
Looks fine to me
Reviewed-by: Kuppuswamy Sathyanarayanan
<sathyanarayanan.kuppuswamy@linux.intel.com>
> arch/x86/kernel/acpi/madt_wakeup.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
> index f36f28405dcc..b386ec4b87c2 100644
> --- a/arch/x86/kernel/acpi/madt_wakeup.c
> +++ b/arch/x86/kernel/acpi/madt_wakeup.c
> @@ -143,6 +143,10 @@ static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip)
> acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr,
> sizeof(*acpi_mp_wake_mailbox),
> MEMREMAP_WB);
> + if (!acpi_mp_wake_mailbox) {
> + pr_err("Failed to remap MADT mailbox\n");
> + return -ENOMEM;
> + }
> }
>
> /*
--
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu()
2025-04-15 13:39 ` Rafael J. Wysocki
@ 2025-04-16 7:26 ` Kirill A. Shutemov
0 siblings, 0 replies; 5+ messages in thread
From: Kirill A. Shutemov @ 2025-04-16 7:26 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Chenyuan Yang, lenb, tglx, mingo, bp, dave.hansen, x86, hpa, bhe,
kai.huang, sathyanarayanan.kuppuswamy, linux-acpi, linux-kernel
On Tue, Apr 15, 2025 at 03:39:24PM +0200, Rafael J. Wysocki wrote:
> On Fri, Apr 11, 2025 at 9:48 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
> >
> > The result of memremap() may be NULL on failure, leading to a NULL
> > dereference. Add explicit checks after memremap() call: if the
> > MADT mailbox fails to map, return immediately.
> >
> > This is similar to the commit 966d47e1f27c
> > ("efi: fix potential NULL deref in efi_mem_reserve_persistent").
> >
> > This is found by our static analysis tool KNighter.
> >
> > Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> > Fixes: 2b5e22afae07 ("x86/acpi: Extract ACPI MADT wakeup code into a separate file")
>
> Well, it's good to add the author of the commit you're trying to fix
> to the CC list.
>
> Kirill, what do you think about this?
Looks reasonable to me.
We fail to remap a single page. It is likely to be fatally broken system
if we get there. But okay, let's handle it.
Maybe use pr_err_once(). No need to spam an error for every CPU.
> > ---
> > arch/x86/kernel/acpi/madt_wakeup.c | 4 ++++
> > 1 file changed, 4 insertions(+)
> >
> > diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
> > index f36f28405dcc..b386ec4b87c2 100644
> > --- a/arch/x86/kernel/acpi/madt_wakeup.c
> > +++ b/arch/x86/kernel/acpi/madt_wakeup.c
> > @@ -143,6 +143,10 @@ static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip)
> > acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr,
> > sizeof(*acpi_mp_wake_mailbox),
> > MEMREMAP_WB);
> > + if (!acpi_mp_wake_mailbox) {
> > + pr_err("Failed to remap MADT mailbox\n");
> > + return -ENOMEM;
> > + }
> > }
> >
> > /*
> > --
> > 2.34.1
> >
--
Kiryl Shutsemau / Kirill A. Shutemov
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu()
2025-04-11 19:48 [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu() Chenyuan Yang
2025-04-15 13:39 ` Rafael J. Wysocki
2025-04-15 14:25 ` Sathyanarayanan Kuppuswamy
@ 2025-05-16 14:07 ` Rafael J. Wysocki
2 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-05-16 14:07 UTC (permalink / raw)
To: Chenyuan Yang
Cc: rafael, lenb, tglx, mingo, bp, dave.hansen, x86, hpa, bhe,
kai.huang, sathyanarayanan.kuppuswamy, linux-acpi, linux-kernel,
Kirill A. Shutemov
On Fri, Apr 11, 2025 at 9:48 PM Chenyuan Yang <chenyuan0y@gmail.com> wrote:
>
> The result of memremap() may be NULL on failure, leading to a NULL
> dereference. Add explicit checks after memremap() call: if the
> MADT mailbox fails to map, return immediately.
This mailbox is called Multiprocessor Wakeup Mailbox in the
specification, so please follow the established terminology.
> This is similar to the commit 966d47e1f27c
> ("efi: fix potential NULL deref in efi_mem_reserve_persistent").
>
> This is found by our static analysis tool KNighter.
>
> Signed-off-by: Chenyuan Yang <chenyuan0y@gmail.com>
> Fixes: 2b5e22afae07 ("x86/acpi: Extract ACPI MADT wakeup code into a separate file")
> ---
> arch/x86/kernel/acpi/madt_wakeup.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
> index f36f28405dcc..b386ec4b87c2 100644
> --- a/arch/x86/kernel/acpi/madt_wakeup.c
> +++ b/arch/x86/kernel/acpi/madt_wakeup.c
> @@ -143,6 +143,10 @@ static int acpi_wakeup_cpu(u32 apicid, unsigned long start_ip)
> acpi_mp_wake_mailbox = memremap(acpi_mp_wake_mailbox_paddr,
> sizeof(*acpi_mp_wake_mailbox),
> MEMREMAP_WB);
> + if (!acpi_mp_wake_mailbox) {
> + pr_err("Failed to remap MADT mailbox\n");
Please follow Kirill's advice on using pr_err_once() here and use the
proper terminology in the message (also this is mapping, not
remapping, even though memremap() is used).
> + return -ENOMEM;
> + }
> }
>
> /*
> --
Thanks!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-05-16 14:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11 19:48 [PATCH] x86/acpi: fix potential NULL deref in acpi_wakeup_cpu() Chenyuan Yang
2025-04-15 13:39 ` Rafael J. Wysocki
2025-04-16 7:26 ` Kirill A. Shutemov
2025-04-15 14:25 ` Sathyanarayanan Kuppuswamy
2025-05-16 14:07 ` Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).