From: Marco Scardovi <scardracs@disroot.org>
To: Mika Westerberg <westeri@kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Linus Walleij <linusw@kernel.org>,
Bartosz Golaszewski <brgl@kernel.org>
Cc: linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v4 3/4] gpiolib: acpi: prevent address truncation in OperationRegion handler
Date: Sun, 31 May 2026 14:03:10 +0200 [thread overview]
Message-ID: <20260531120816.17255-4-scardracs@disroot.org> (raw)
In-Reply-To: <20260531120816.17255-1-scardracs@disroot.org>
The ACPI address space handler for GPIO OperationRegions receives the
pin offset as a 64-bit acpi_physical_address. However, the handler
truncates this address to a u16 pin_index before validating it.
If an ACPI table attempts to access a pin offset greater than 65535,
the truncation wraps the index around. This may result in accesses to
unintended GPIO pins.
Fix this by adding an explicit check to verify that the 64-bit address
is less than agpio->pin_table_length before assigning it to the u16
pin_index, returning AE_BAD_PARAMETER if it is out of bounds.
Additionally, make the length calculation overflow-safe and change the types
of length and loop counter to unsigned.
Assisted-by: Antigravity:gemini-3.5-flash
Signed-off-by: Marco Scardovi <scardracs@disroot.org>
---
drivers/gpio/gpiolib-acpi-core.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index e3bc4677b51d..d12dab42a096 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -1150,13 +1150,13 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
struct acpi_gpio_connection *conn;
struct acpi_resource_gpio *agpio;
struct acpi_resource *ares;
- u16 pin_index = address;
+ unsigned int length;
LIST_HEAD(new_conns);
acpi_status status;
- int length;
+ unsigned int i;
+ u16 pin_index;
u16 shift;
u16 word;
- int i;
status = acpi_buffer_to_resource(achip->conn_info.connection,
achip->conn_info.length, &ares);
@@ -1176,7 +1176,17 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address,
return AE_BAD_PARAMETER;
}
- length = min(agpio->pin_table_length, pin_index + bits);
+ if (address >= agpio->pin_table_length) {
+ ACPI_FREE(ares);
+ return AE_BAD_PARAMETER;
+ }
+
+ pin_index = address;
+ if (bits > agpio->pin_table_length - pin_index)
+ length = agpio->pin_table_length;
+ else
+ length = pin_index + bits;
+
for (i = pin_index; i < length; ++i) {
unsigned int pin = agpio->pin_table[i];
struct gpio_desc *desc;
--
2.54.0
next prev parent reply other threads:[~2026-05-31 12:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-31 12:03 [PATCH v4 0/4] gpiolib: acpi: Consolidated fixes and bounds checking Marco Scardovi
2026-05-31 12:03 ` [PATCH v4 1/4] gpiolib: acpi: Add robust bounds-checking for GPIO pin resources Marco Scardovi
2026-05-31 12:03 ` [PATCH v4 2/4] gpiolib: acpi: fix resource leak in OpRegion Marco Scardovi
2026-06-01 12:18 ` Mika Westerberg
2026-06-01 13:03 ` Marco Scardovi
2026-06-02 7:57 ` Andy Shevchenko
2026-06-02 9:53 ` Mika Westerberg
2026-06-02 10:04 ` Andy Shevchenko
2026-05-31 12:03 ` Marco Scardovi [this message]
2026-05-31 12:03 ` [PATCH v4 4/4] gpiolib: acpi: fix out-of-bounds pointer arithmetic in acpi_gpio_package_count Marco Scardovi
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=20260531120816.17255-4-scardracs@disroot.org \
--to=scardracs@disroot.org \
--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