mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] iio: imu: inv_mpu6050: validate the CNF0 package
@ 2026-11-03 11:41 Kang Chen
  2026-11-03 11:56 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Kang Chen @ 2026-11-03 11:41 UTC (permalink / raw)
  To: Jean-Baptiste Maneyrol
  Cc: Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, Srinivas Pandruvada, linux-iio, linux-kernel

asus_acpi_get_sensor_info() walks the package returned by CNF0 and uses
each element as a package without checking the object type or the
element type.  A top-level string or buffer makes package.count alias
its length and package.elements alias its data pointer.  For a
non-package element, the inner count and elements pointer are taken
from unrelated union members, so the driver can walk a firmware-chosen
pointer and pass it to strscpy().

Require a top-level package and skip elements that are not packages.

Fixes: a35c5d1aa96a ("iio: imu: inv_mpu6050: Create mux clients for ACPI")
Signed-off-by: Kang Chen <k.chen@smail.nju.edu.cn>
---
 drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
index 460792ed27e0..0dc6c042043e 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_acpi.c
@@ -57,11 +57,19 @@ static int asus_acpi_get_sensor_info(struct acpi_device *adev,
 		return -ENODEV;
 
 	cpm = buffer.pointer;
+	if (!cpm || cpm->type != ACPI_TYPE_PACKAGE) {
+		kfree(buffer.pointer);
+		return -ENODEV;
+	}
+
 	for (i = 0; i < cpm->package.count; ++i) {
 		union acpi_object *elem;
 		int j;
 
 		elem = &cpm->package.elements[i];
+		if (elem->type != ACPI_TYPE_PACKAGE)
+			continue;
+
 		for (j = 0; j < elem->package.count; ++j) {
 			union acpi_object *sub_elem;
 
-- 
2.34.1


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

end of thread, other threads:[~2026-11-03 11:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 11:41 [PATCH] iio: imu: inv_mpu6050: validate the CNF0 package Kang Chen
2026-11-03 11:56 ` Andy Shevchenko

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®