[PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject

Charles Han posted 1 patch 1 month, 2 weeks ago
drivers/acpi/apei/einj-core.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
Posted by Charles Han 1 month, 2 weeks ago
The __einj_error_inject() function allocates memory via kmalloc()
without checking for allocation failure, which could lead to a
NULL pointer dereference.

Return -ENOMEM in case allocation fails.

Fixes: b47610296d17 ("ACPI: APEI: EINJ: Enable EINJv2 error injections")
Signed-off-by: Charles Han <hanchunchao@inspur.com>
---
 drivers/acpi/apei/einj-core.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
index bf8dc92a373a..93a3ae1325e5 100644
--- a/drivers/acpi/apei/einj-core.c
+++ b/drivers/acpi/apei/einj-core.c
@@ -540,6 +540,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
 		struct set_error_type_with_address *v5param;
 
 		v5param = kmalloc(v5param_size, GFP_KERNEL);
+		if (!v5param)
+			return -ENOMEM;
+
 		memcpy_fromio(v5param, einj_param, v5param_size);
 		v5param->type = type;
 		if (type & ACPI5_VENDOR_BIT) {
-- 
2.43.0
Re: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
Posted by Yazen Ghannam 1 month, 2 weeks ago
On Fri, Aug 15, 2025 at 10:42:06AM +0800, Charles Han wrote:
> The __einj_error_inject() function allocates memory via kmalloc()
> without checking for allocation failure, which could lead to a
> NULL pointer dereference.
> 
> Return -ENOMEM in case allocation fails.
> 
> Fixes: b47610296d17 ("ACPI: APEI: EINJ: Enable EINJv2 error injections")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>

Reviewed-by: Yazen Ghannam <yazen.ghannam@amd.com>

Thanks,
Yazen
Re: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
Posted by Hanjun Guo 1 month, 2 weeks ago
On 2025/8/15 10:42, Charles Han wrote:
> The __einj_error_inject() function allocates memory via kmalloc()
> without checking for allocation failure, which could lead to a
> NULL pointer dereference.
> 
> Return -ENOMEM in case allocation fails.
> 
> Fixes: b47610296d17 ("ACPI: APEI: EINJ: Enable EINJv2 error injections")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>
> ---
>   drivers/acpi/apei/einj-core.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
> index bf8dc92a373a..93a3ae1325e5 100644
> --- a/drivers/acpi/apei/einj-core.c
> +++ b/drivers/acpi/apei/einj-core.c
> @@ -540,6 +540,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
>   		struct set_error_type_with_address *v5param;
>   
>   		v5param = kmalloc(v5param_size, GFP_KERNEL);
> +		if (!v5param)
> +			return -ENOMEM;
> +
>   		memcpy_fromio(v5param, einj_param, v5param_size);
>   		v5param->type = type;
>   		if (type & ACPI5_VENDOR_BIT) {

Reviewed-by: Hanjun Guo <guohanjun@huawei.com>

Thanks
Hanjun
Re: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
Posted by Rafael J. Wysocki 1 month, 2 weeks ago
On Mon, Aug 18, 2025 at 6:07 PM Hanjun Guo <guohanjun@huawei.com> wrote:
>
> On 2025/8/15 10:42, Charles Han wrote:
> > The __einj_error_inject() function allocates memory via kmalloc()
> > without checking for allocation failure, which could lead to a
> > NULL pointer dereference.
> >
> > Return -ENOMEM in case allocation fails.
> >
> > Fixes: b47610296d17 ("ACPI: APEI: EINJ: Enable EINJv2 error injections")
> > Signed-off-by: Charles Han <hanchunchao@inspur.com>
> > ---
> >   drivers/acpi/apei/einj-core.c | 3 +++
> >   1 file changed, 3 insertions(+)
> >
> > diff --git a/drivers/acpi/apei/einj-core.c b/drivers/acpi/apei/einj-core.c
> > index bf8dc92a373a..93a3ae1325e5 100644
> > --- a/drivers/acpi/apei/einj-core.c
> > +++ b/drivers/acpi/apei/einj-core.c
> > @@ -540,6 +540,9 @@ static int __einj_error_inject(u32 type, u32 flags, u64 param1, u64 param2,
> >               struct set_error_type_with_address *v5param;
> >
> >               v5param = kmalloc(v5param_size, GFP_KERNEL);
> > +             if (!v5param)
> > +                     return -ENOMEM;
> > +
> >               memcpy_fromio(v5param, einj_param, v5param_size);
> >               v5param->type = type;
> >               if (type & ACPI5_VENDOR_BIT) {
>
> Reviewed-by: Hanjun Guo <guohanjun@huawei.com>

Applied as 6.17-rc material, thanks!
RE: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
Posted by Luck, Tony 1 month, 2 weeks ago
> The __einj_error_inject() function allocates memory via kmalloc()
> without checking for allocation failure, which could lead to a
> NULL pointer dereference.
>
> Return -ENOMEM in case allocation fails.
>
> Fixes: b47610296d17 ("ACPI: APEI: EINJ: Enable EINJv2 error injections")
> Signed-off-by: Charles Han <hanchunchao@inspur.com>

Reviewed-by: Tony Luck <tony.luck@intel.com>

-Tony