mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Tristan Madani <tristmd@gmail.com>
Cc: Marius Cristea <marius.cristea@microchip.com>,
	Jonathan Cameron <jic23@kernel.org>,
	David Lechner <dlechner@baylibre.com>,
	Nuno Sa <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: Re: [PATCH v4] iio: adc: pac1934: validate ACPI _DSM return type and bounds
Date: Fri, 30 Oct 2026 11:47:06 +0200	[thread overview]
Message-ID: <auRnmh6129P7WY5i@ashevche-desk.local> (raw)
In-Reply-To: <20261029165602.3265518-1-tristmd@gmail.com>

On Thu, Oct 29, 2026 at 04:56:02PM +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].

...

>  static int pac1934_acpi_parse_channel_config(struct i2c_client *client,
>  					     struct pac1934_chip_info *info)
>  {
> -	acpi_handle handle;
> -	union acpi_object *rez;
>  	struct device *dev = &client->dev;
>  	unsigned short bi_dir_mask;
> -	int idx, i;
> +	union acpi_object *rez;
> +	acpi_handle handle;
> +	unsigned int count;
>  	guid_t guid;
> +	int idx, i;

No need to touch lines that are unrelated to your change. Just make sure that
your change tries to keep reversed xmas tree order as much as possible.

...

> -	for (i = 0; i < rez->package.count; i += 2) {
> +	count = min(rez->package.count & ~1u, PAC1934_MAX_NUM_CHANNELS * 2);

What is the purpose of 'u' suffix? In case if you want to keep that 32-bit
value this might be even wrong (I haven't checked the promotion rules for the
values with suffix, though).

> +	for (i = 0; i < count; i += 2) {

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-10-30  9:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-29 16:56 Tristan Madani
2026-10-30  9:47 ` Andy Shevchenko [this message]

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=auRnmh6129P7WY5i@ashevche-desk.local \
    --to=andriy.shevchenko@intel.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 \
    --cc=tristmd@gmail.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®