Skip to contentSkip to conversation

ACPICA: fix NULL pointer dereference in acpi_ns_custom_package()

PATCH In review Weiming Shi 2 participants 2 messages Mar 22 – Mar 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ACPICA: fix NULL pointer dereference in acpi_ns_custom_package()

acpi_ns_custom_package() unconditionally dereferences the first element of the package to read the _BIX version number, without checking for NULL:

if ((*elements)->common.type != ACPI_TYPE_INTEGER)

When firmware returns a _BIX package whose first element is an unresolvable reference, ACPICA evaluates that entry to NULL. acpi_ns_remove_null_elements() does not strip NULL entries for ACPI_PTYPE_CUSTOM packages (fixed-position format would break if elements were shifted), so acpi_ns_custom_package() sees the NULL and panics.

 general protection fault, probably for non-canonical address
 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI
 KASAN: null-ptr-deref in range
 [0x0000000000000008-0x000000000000000f]
 RIP: acpi_ns_check_package
 (drivers/acpi/acpica/nsprepkg.c:634
  drivers/acpi/acpica/nsprepkg.c:110)
 Call Trace:
  <TASK>
  acpi_ns_check_return_value (nspredef.c:136)
  acpi_ns_evaluate (nseval.c:266)
  acpi_evaluate_object (nsxfeval.c:360)
  acpi_battery_get_info (battery.c:537)
  acpi_battery_update (battery.c:1007)
  acpi_battery_add (battery.c:1237)
  acpi_device_probe (bus.c:1076)
  really_probe (dd.c:659)
  </TASK>

Add a NULL check for the first element (version field) before dereferencing it. The battery probe then fails gracefully with AE_AML_OPERAND_TYPE instead of crashing the kernel.

Required CONFIG: CONFIG_ACPI_BATTERY=y

Fixes 7952d40240855932 ("ACPICA: ACPI 6.0: Update _BIX support for new package element")
---
 drivers/acpi/acpica/nsprepkg.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/acpica/nsprepkg.c +7 -0
index ca137ce5674f..c32770570120 100644
@@ -631,6 +631,13 @@ acpi_ns_custom_package(struct acpi_evaluate_info *info,
 
 	/* Get version number, must be Integer */
 
+	if (!(*elements)) {
+		ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
+				      info->node_flags,
+				      "Return Package has a NULL version element"));
+		return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+	}
+
 	if ((*elements)->common.type != ACPI_TYPE_INTEGER) {
 		ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
 				      info->node_flags,
Signature · 1 line
2.43.0
#1 lore raw
Quoted 55 lines · Weiming Shi

acpi_ns_custom_package() unconditionally dereferences the first element of the package to read the _BIX version number, without checking for NULL:

if ((*elements)->common.type != ACPI_TYPE_INTEGER)

When firmware returns a _BIX package whose first element is an unresolvable reference, ACPICA evaluates that entry to NULL. acpi_ns_remove_null_elements() does not strip NULL entries for ACPI_PTYPE_CUSTOM packages (fixed-position format would break if elements were shifted), so acpi_ns_custom_package() sees the NULL and panics.

 general protection fault, probably for non-canonical address
 0xdffffc0000000001: 0000 [#1] SMP KASAN NOPTI
 KASAN: null-ptr-deref in range
 [0x0000000000000008-0x000000000000000f]
 RIP: acpi_ns_check_package
 (drivers/acpi/acpica/nsprepkg.c:634
  drivers/acpi/acpica/nsprepkg.c:110)
 Call Trace:
  <TASK>
  acpi_ns_check_return_value (nspredef.c:136)
  acpi_ns_evaluate (nseval.c:266)
  acpi_evaluate_object (nsxfeval.c:360)
  acpi_battery_get_info (battery.c:537)
  acpi_battery_update (battery.c:1007)
  acpi_battery_add (battery.c:1237)
  acpi_device_probe (bus.c:1076)
  really_probe (dd.c:659)
  </TASK>

Add a NULL check for the first element (version field) before dereferencing it. The battery probe then fails gracefully with AE_AML_OPERAND_TYPE instead of crashing the kernel.

Required CONFIG: CONFIG_ACPI_BATTERY=y

Fixes 7952d40240855932 ("ACPICA: ACPI 6.0: Update _BIX support for new package element")
---
 drivers/acpi/acpica/nsprepkg.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/acpi/acpica/nsprepkg.c +1 -0
index ca137ce5674f..c32770570120 100644
@@ -631,6 +631,13 @@ acpi_ns_custom_package(struct acpi_evaluate_info *info,
 
        /* Get version number, must be Integer */
 
+       if (!(*elements)) {

drivers/acpi/acpica/nsprepkg.c acpi_ns_custom_package(struct acpi_evaluate_info *info,

Quoted 10 lines
drivers/acpi/acpica/nsprepkg.c +6 -1
+               ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
+                                     info->node_flags,
+                                     "Return Package has a NULL version element"));
+               return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
+       }
+
        if ((*elements)->common.type != ACPI_TYPE_INTEGER) {
                ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
                                      info->node_flags,
--

ACPICA changes need to be routed via upstream ACPICA project on GitHub.

Please see Documentation/driver-api/acpi/linuxized-acpica.rst