Re: [PATCH v5] iio: adc: pac1934: validate ACPI _DSM return type and bounds
From: Andy Shevchenko
Date: Sat Oct 31 2026 - 10:42:01 EST
On Fri, Oct 30, 2026 at 12:35:28PM +0000, Tristan Madani wrote:
> 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].
...
> + count = min_t(unsigned int, rez->package.count,
> + PAC1934_MAX_NUM_CHANNELS * 2);
We have already discussed that, that min_t() has not to be in use.
Ditto for the rest of the similar cases.
I would recommend you to slow down, drop AI assistance and check
the code (variable types, available macros and their usages) first.
Don't send a new version until you understand what AI is trying to
do and what we want to have at the end.
--
With Best Regards,
Andy Shevchenko