mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Mika Westerberg <westeri@kernel.org>,
	Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>
Subject: Re: [PATCH v1 1/1] gpiolib: acpi: Fix potential out-of-boundary left shift
Date: Tue, 27 Jan 2026 09:11:36 +0100	[thread overview]
Message-ID: <20260127081136.GZ2275908@black.igk.intel.com> (raw)
In-Reply-To: <20260126134226.3617924-1-andriy.shevchenko@linux.intel.com>

On Mon, Jan 26, 2026 at 02:42:26PM +0100, Andy Shevchenko wrote:
> GPIO Address Space handler gets a pointer to the in or out value.
> This value is supposed to be at least 64-bit, but it's not limited
> to be exactly 64-bit. When ACPI tables are being parsed, for
> the bigger Connection():s ACPICA creates a Buffer instead of regular
> Integer object. The Buffer exists as long as Namespace holds
> the certain Connection(). Hence we can access the necessary bits
> without worrying. On the other hand, the left shift used in the
> code is limited by 31 (on 32-bit platforms) and otherwise considered
> to be Undefined Behaviour. Also the code uses only the first 64-bit
> address for the value, and anything bigger than	63 will be also
                                                 ^^^^^^^
There is some extra whitespace above.

> subject to UB. Fix all this by modifying the code to correctly set or
> clear the respective bit in the bitmap constructed of 64-bit values.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpio/gpiolib-acpi-core.c | 16 ++++++++++++----
>  1 file changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
> index 83dd227dbbec..da0ab749b4dc 100644
> --- a/drivers/gpio/gpiolib-acpi-core.c
> +++ b/drivers/gpio/gpiolib-acpi-core.c
> @@ -1104,6 +1104,7 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
>  		unsigned int pin = agpio->pin_table[i];
>  		struct acpi_gpio_connection *conn;
>  		struct gpio_desc *desc;
> +		u16 vala, valo;

Perhaps bit more descriptive names.

And while at it, add comment why this is needed.

>  		bool found;
>  
>  		mutex_lock(&achip->conn_lock);
> @@ -1158,10 +1159,17 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
>  
>  		mutex_unlock(&achip->conn_lock);
>  
> -		if (function == ACPI_WRITE)
> -			gpiod_set_raw_value_cansleep(desc, !!(*value & BIT(i)));
> -		else
> -			*value |= (u64)gpiod_get_raw_value_cansleep(desc) << i;
> +		vala = i / 64;
> +		valo = i % 64;
> +
> +		if (function == ACPI_WRITE) {
> +			gpiod_set_raw_value_cansleep(desc, value[vala] & BIT_ULL(valo));
> +		} else {
> +			if (gpiod_get_raw_value_cansleep(desc))
> +				value[vala] |= BIT_ULL(valo);
> +			else
> +				value[vala] &= ~BIT_ULL(valo);
> +		}
>  	}
>  
>  out:
> -- 
> 2.50.1

      reply	other threads:[~2026-01-27  8:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26 13:42 Andy Shevchenko
2026-01-27  8:11 ` Mika Westerberg [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=20260127081136.GZ2275908@black.igk.intel.com \
    --to=mika.westerberg@linux.intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=westeri@kernel.org \
    /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®