linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
@ 2025-08-15  2:42 Charles Han
  2025-08-15 15:51 ` Luck, Tony
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Charles Han @ 2025-08-15  2:42 UTC (permalink / raw)
  To: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
	ira.weiny, zaidal, Jonathan.Cameron, colin.i.king, dan.carpenter,
	dan.j.williams, sudeep.holla
  Cc: linux-acpi, linux-kernel, Charles Han

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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
  2025-08-15  2:42 [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject Charles Han
@ 2025-08-15 15:51 ` Luck, Tony
  2025-08-18 16:06 ` Hanjun Guo
  2025-08-19 14:04 ` Yazen Ghannam
  2 siblings, 0 replies; 5+ messages in thread
From: Luck, Tony @ 2025-08-15 15:51 UTC (permalink / raw)
  To: Charles Han, rafael@kernel.org, bp@alien8.de,
	guohanjun@huawei.com, mchehab@kernel.org,
	xueshuai@linux.alibaba.com, lenb@kernel.org, Weiny, Ira,
	zaidal@os.amperecomputing.com, Jonathan.Cameron@huawei.com,
	colin.i.king@gmail.com, dan.carpenter@linaro.org, Williams, Dan J,
	sudeep.holla@arm.com
  Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org

> 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
  2025-08-15  2:42 [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject Charles Han
  2025-08-15 15:51 ` Luck, Tony
@ 2025-08-18 16:06 ` Hanjun Guo
  2025-08-18 16:11   ` Rafael J. Wysocki
  2025-08-19 14:04 ` Yazen Ghannam
  2 siblings, 1 reply; 5+ messages in thread
From: Hanjun Guo @ 2025-08-18 16:06 UTC (permalink / raw)
  To: Charles Han, rafael, tony.luck, bp, mchehab, xueshuai, lenb,
	ira.weiny, zaidal, Jonathan.Cameron, colin.i.king, dan.carpenter,
	dan.j.williams, sudeep.holla
  Cc: linux-acpi, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
  2025-08-18 16:06 ` Hanjun Guo
@ 2025-08-18 16:11   ` Rafael J. Wysocki
  0 siblings, 0 replies; 5+ messages in thread
From: Rafael J. Wysocki @ 2025-08-18 16:11 UTC (permalink / raw)
  To: Hanjun Guo, tony.luck, Charles Han
  Cc: bp, mchehab, xueshuai, lenb, ira.weiny, zaidal, Jonathan.Cameron,
	colin.i.king, dan.carpenter, dan.j.williams, sudeep.holla,
	linux-acpi, linux-kernel

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!

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject
  2025-08-15  2:42 [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject Charles Han
  2025-08-15 15:51 ` Luck, Tony
  2025-08-18 16:06 ` Hanjun Guo
@ 2025-08-19 14:04 ` Yazen Ghannam
  2 siblings, 0 replies; 5+ messages in thread
From: Yazen Ghannam @ 2025-08-19 14:04 UTC (permalink / raw)
  To: Charles Han
  Cc: rafael, tony.luck, bp, guohanjun, mchehab, xueshuai, lenb,
	ira.weiny, zaidal, Jonathan.Cameron, colin.i.king, dan.carpenter,
	dan.j.williams, sudeep.holla, linux-acpi, linux-kernel

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-08-19 14:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-15  2:42 [PATCH] ACPI: APEI: EINJ: fix potential NULL dereference in __einj_error_inject Charles Han
2025-08-15 15:51 ` Luck, Tony
2025-08-18 16:06 ` Hanjun Guo
2025-08-18 16:11   ` Rafael J. Wysocki
2025-08-19 14:04 ` Yazen Ghannam

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).