[PATCH v3 1/2] gpiolib: acpi: Add robust bounds-checking for GPIO pin resources
From: Marco Scardovi (scardracs)
Date: Wed May 20 2026 - 03:57:51 EST
Ensure that the GPIO pin resource arrays are safely bounded before
accessing indices. Add bounds checking in acpi_request_own_gpiod(),
acpi_gpio_irq_is_wake(), and acpi_gpiochip_alloc_event() to prevent
out-of-bounds array reads if the ACPI namespace provides malformed or
empty pin tables.
Assisted-by: Antigravity:gemini-3-flash
Signed-off-by: Marco Scardovi <mscardovi95@xxxxxxxxx>
---
drivers/gpio/gpiolib-acpi-core.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c
index eb8a40cfb7a9..a6d78dad299e 100644
--- a/drivers/gpio/gpiolib-acpi-core.c
+++ b/drivers/gpio/gpiolib-acpi-core.c
@@ -320,10 +320,18 @@ static struct gpio_desc *acpi_request_own_gpiod(struct gpio_chip *chip,
unsigned int index,
const char *label)
{
- int polarity = GPIO_ACTIVE_HIGH;
- enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio, polarity);
- unsigned int pin = agpio->pin_table[index];
struct gpio_desc *desc;
+ enum gpiod_flags flags;
+ unsigned int pin;
+ int polarity;
+
+ polarity = GPIO_ACTIVE_HIGH;
+ flags = acpi_gpio_to_gpiod_flags(agpio, polarity);
+
+ if (index >= agpio->pin_table_length)
+ return ERR_PTR(-EINVAL);
+
+ pin = agpio->pin_table[index];
desc = gpiochip_request_own_desc(chip, pin, label, polarity, flags);
if (IS_ERR(desc))
@@ -337,11 +345,16 @@ static struct gpio_desc *acpi_request_own_gpiod(struct gpio_chip *chip,
static bool acpi_gpio_irq_is_wake(struct device *parent,
const struct acpi_resource_gpio *agpio)
{
- unsigned int pin = agpio->pin_table[0];
+ unsigned int pin;
if (agpio->wake_capable != ACPI_WAKE_CAPABLE)
return false;
+ if (agpio->pin_table_length == 0)
+ return false;
+
+ pin = agpio->pin_table[0];
+
if (acpi_gpio_in_ignore_list(ACPI_GPIO_IGNORE_WAKE, dev_name(parent), pin)) {
dev_info(parent, "Ignoring wakeup on pin %u\n", pin);
return false;
@@ -368,6 +381,9 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares,
return AE_OK;
handle = ACPI_HANDLE(chip->parent);
+ if (agpio->pin_table_length == 0)
+ return AE_OK;
+
pin = agpio->pin_table[0];
if (pin <= 255) {
--
2.54.0