From: Tristan Madani <tristmd@gmail.com>
To: Marius Cristea <marius.cristea@microchip.com>,
Jonathan Cameron <jic23@kernel.org>,
David Lechner <dlechner@baylibre.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
"Tristan Madani" <tristan@talencesecurity.com>
Subject: [PATCH v3] iio: adc: pac1934: validate ACPI _DSM return type and bounds
Date: Thu, 29 Oct 2026 00:14:47 +0000 [thread overview]
Message-ID: <20261029001447.1114691-1-tristmd@gmail.com> (raw)
From: Tristan Madani <tristan@talencesecurity.com>
pac1934_acpi_parse_channel_config() calls acpi_evaluate_dsm() four
times to read channel configuration but does not validate the returned
object type or array bounds:
1. No check that the returned object is ACPI_TYPE_PACKAGE. If
firmware returns a different type, accessing rez->package.count
and rez->package.elements on a non-package object produces
unpredictable values.
2. The loop bounds use rez->package.count directly without capping
to PAC1934_MAX_NUM_CHANNELS (4). A package with more elements
than expected causes writes past the fixed-size labels[],
shunts[], and active_channels[] arrays.
3. The bipolar and sample rate DSM calls access elements[0] without
verifying package.count >= 1.
Use acpi_evaluate_dsm_typed() with ACPI_TYPE_PACKAGE to validate the
return type at evaluation time. Cap loop iterations to
PAC1934_MAX_NUM_CHANNELS, and verify package count >= 1 before
accessing elements[0].
Signed-off-by: Tristan Madani <tristan@talencesecurity.com>
---
Changes in v3:
- Use acpi_evaluate_dsm_typed() instead of manual type checks, per
Andy Shevchenko
- Use (count & ~1u) for the name+mohm loop bound to ensure pairs
are complete, per Andy Shevchenko
- Drop Fixes: and Cc: stable tags since this is hardening rather
than a fix for a specific regression, per Jonathan Cameron
drivers/iio/adc/pac1934.c | 32 ++++++++++++++++++++++++++------
1 file changed, 26 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/pac1934.c b/drivers/iio/adc/pac1934.c
index de59dc27c4405..b6315a13a353e 100644
--- a/drivers/iio/adc/pac1934.c
+++ b/drivers/iio/adc/pac1934.c
@@ -1092,17 +1092,22 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
struct device *dev = &client->dev;
unsigned short bi_dir_mask;
int idx, i;
+ unsigned int count;
guid_t guid;
handle = ACPI_HANDLE(dev);
guid_parse(PAC1934_DSM_UUID, &guid);
- rez = acpi_evaluate_dsm(handle, &guid, 0, PAC1934_ACPI_GET_NAMES_AND_MOHMS_VALS, NULL);
+ rez = acpi_evaluate_dsm_typed(handle, &guid, 0,
+ PAC1934_ACPI_GET_NAMES_AND_MOHMS_VALS,
+ NULL, ACPI_TYPE_PACKAGE);
if (!rez)
return -EINVAL;
- for (i = 0; i < rez->package.count; i += 2) {
+ count = min(rez->package.count & ~1u,
+ (unsigned int)(PAC1934_MAX_NUM_CHANNELS * 2));
+ for (i = 0; i < count; i += 2) {
idx = i / 2;
info->labels[idx] =
devm_kmemdup(dev, rez->package.elements[i].string.pointer,
@@ -1119,7 +1124,9 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
ACPI_FREE(rez);
- rez = acpi_evaluate_dsm(handle, &guid, 1, PAC1934_ACPI_GET_UOHMS_VALS, NULL);
+ rez = acpi_evaluate_dsm_typed(handle, &guid, 1,
+ PAC1934_ACPI_GET_UOHMS_VALS,
+ NULL, ACPI_TYPE_PACKAGE);
if (!rez) {
/*
* initializing with default values
@@ -1130,7 +1137,8 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
return 0;
}
- for (i = 0; i < rez->package.count; i++) {
+ count = min(rez->package.count, (unsigned int)PAC1934_MAX_NUM_CHANNELS);
+ for (i = 0; i < count; i++) {
idx = i;
info->shunts[idx] = rez->package.elements[i].integer.value;
info->active_channels[idx] = (info->shunts[idx] != 0);
@@ -1138,9 +1146,15 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
ACPI_FREE(rez);
- rez = acpi_evaluate_dsm(handle, &guid, 1, PAC1934_ACPI_GET_BIPOLAR_SETTINGS, NULL);
+ rez = acpi_evaluate_dsm_typed(handle, &guid, 1,
+ PAC1934_ACPI_GET_BIPOLAR_SETTINGS,
+ NULL, ACPI_TYPE_PACKAGE);
if (!rez)
return -EINVAL;
+ if (rez->package.count < 1) {
+ ACPI_FREE(rez);
+ return -EINVAL;
+ }
bi_dir_mask = rez->package.elements[0].integer.value;
info->bi_dir[0] = ((bi_dir_mask & (1 << 3)) | (bi_dir_mask & (1 << 7))) != 0;
@@ -1150,9 +1164,15 @@ static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
ACPI_FREE(rez);
- rez = acpi_evaluate_dsm(handle, &guid, 1, PAC1934_ACPI_GET_SAMP, NULL);
+ rez = acpi_evaluate_dsm_typed(handle, &guid, 1,
+ PAC1934_ACPI_GET_SAMP,
+ NULL, ACPI_TYPE_PACKAGE);
if (!rez)
return -EINVAL;
+ if (rez->package.count < 1) {
+ ACPI_FREE(rez);
+ return -EINVAL;
+ }
info->sample_rate_value = rez->package.elements[0].integer.value;
--
2.47.3
next reply other threads:[~2026-10-29 0:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 0:14 Tristan Madani [this message]
2026-10-29 14:11 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261029001447.1114691-1-tristmd@gmail.com \
--to=tristmd@gmail.com \
--cc=andy@kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marius.cristea@microchip.com \
--cc=nuno.sa@analog.com \
--cc=tristan@talencesecurity.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®