From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A7E13E1684 for ; Mon, 18 May 2026 07:54:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779090857; cv=none; b=mJNsGgAZQXQmf2ZWUMxKqnBFXJWu+PXEyo8Btx5biF9VIfpiSZPn1f+fJkPK3+s+ZXiuLuQF2PFYhM+BUNQfjO1ekJgW+7OlDwgnzlPwR0yl89Ive7t0RGRLxTFrdh1GdiVatGhWzyaM7u6s6opswCV6xM0Mt45R4lXBOrAxJTs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779090857; c=relaxed/simple; bh=dRrJpo/RFBlXKEJiWCWaT5Y8j+cfkW+t5EzYx2I3Jmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jv/nEAaMc3NSV1v5HnGeiybkRU+PUijqYgGDWYE19Elou3p9rspj/K49ipUK/wDFOjPmp0c+WASDmE2XzsHOjzseoxhrHb/oWxvd2cbK6LIZUrEzvtHcHvaQZljSJeLVZNWzM8vL5uumvQWZPKry5tp9FdA2rwZDD2bYxMZcqB8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tn8D4q2j; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tn8D4q2j" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-48a7fe4f40bso24326745e9.0 for ; Mon, 18 May 2026 00:54:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779090844; x=1779695644; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9i+l+TnhrZLaF02FWG+gAPSZUlHwak2ucKtwF5XZOc0=; b=Tn8D4q2jqPgE4EZ5gygR+L6CaAbdXKFUcHGG/hysH0xJtyBuGu9t18KN0oPiRdjfal MIgR+fqyexVR9cEPwveWuhmvhdej/Owe8yl+iFoBxgTBZkVc83QbYvjBMuja0f+1pzcY VoMS+d24YKOd3By4eybhilnxofTcVdSXbv3FpsnY3ze+dbshVG5sDv3lc510SHmnSz9W cmi3bKvIVXI8inmmnNE6PpPansQUkOMgs9fELnS9oCXoBn2jdxq7JUGW9mCrqVundyWK znCe8nFQ0367Kzf98EX6m3v1kLU4lXZAbW5U89Mvi5qWZj43CbvjUR0bOQpJeEe9wmuZ 8+vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779090844; x=1779695644; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9i+l+TnhrZLaF02FWG+gAPSZUlHwak2ucKtwF5XZOc0=; b=D4+631zi0z+L6LLXVPxyHScdKNaBbzOOtfamfAsNBlUdVvq/4kDHAs7OymNyDJwPua y5tIBPk4VHV9J4j2NnBArj5fYR1WPAgRO/scqHwb4tRqb1Waeg1jeS0TmwYEmq6k81X5 o7BsTSf3hHGPz30jzlpKbBXb/bvHDiOSoi6GQui4gb8f4+mElx+oLtJWkp4DtpegmB3K pXY+5WDMinuKoDZywXW6nxH5HTkFjOYqz2gDmWiYGTfnlp4KUc74vyfog+snDF0p6hj5 GSjKWcooC/Txi/pjVJTU4QFMKPLYswDc8hEOdYVXLvbrxo8Xq4Dgvwm8TDhrmD5hKtXj zSyw== X-Forwarded-Encrypted: i=1; AFNElJ/X7AAxXs3USodAtdDKW0S/ldBhyRExij4iZxrSKVTHd7Wbl07+xsvtkcinLnhPGb8E9Svh/gM+NZmoi4Q=@vger.kernel.org X-Gm-Message-State: AOJu0YxADc5MYfyR9UqTMWC87HnRBMXdpywKG9PpaLiTq+6FK89f+S0Y e5Vqb9jl9OOfEWFczd5lBCfDETm0k4JhaUXIozxCqCDom24nMzXGASa+ X-Gm-Gg: Acq92OEkew3VQ6ZjiP7PhsuXf99vXCdK+OGK6jR/LrBvOJxhgmkvvCyBNovJ2BfNRHJ cmqiD4HV71ZEJnnZQnF3vATrNuQ2mIDOdc6f/unQs4uqWgmvW+E0QsUZntg63FO4SOL68cb9znY IKYVtnOEllCZDzKo856G6+wR/oFRbjNw+y1gX4fvDlf37kwhTZOklm/Zn9XwBt2boCOqc3qC2CD aM5XFpeVlu7laAnjyIpe5tzBVSunVyJ+Zgij55V0zaMLkh1nx/35MaTASq6R/PX6g13Lv+m2j50 JPGX9in4x5tYoAvDVdaK2oYM8DI8uveLog+6U7GAiZj7wx3R61UY5phbEYqczCB8aJGxEX4k4dt i2QZkuBdQMRavYToB5xlV7BHgqeFhg2MtM7yYQjRk5yk2DsA71ahV7O/k8gdEJiNEhOry7dyY4l 1tcbI9BDwlQ81jxyg= X-Received: by 2002:a05:600c:4692:b0:48f:d5e8:758c with SMTP id 5b1f17b1804b1-48fe6325792mr216525115e9.16.1779090844437; Mon, 18 May 2026 00:54:04 -0700 (PDT) Received: from ROG ([2a01:e11:202b:40:328e:213e:a3da:580f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48feaf14d22sm102788835e9.3.2026.05.18.00.54.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2026 00:54:03 -0700 (PDT) From: "Marco Scardovi (scardracs)" To: Linus Walleij , Bartosz Golaszewski Cc: Mika Westerberg , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, "Marco Scardovi (scardracs)" Subject: [PATCH 03/12] gpiolib: acpi: Add robust bounds-checking for GPIO pin resources Date: Mon, 18 May 2026 09:53:48 +0200 Message-ID: <20260518075357.112584-4-mscardovi95@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260518075357.112584-1-mscardovi95@gmail.com> References: <20260518075357.112584-1-mscardovi95@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Assisted-by: Antigravity:gemini-3-flash Signed-off-by: Marco Scardovi --- drivers/gpio/gpiolib-acpi-core.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-acpi-core.c b/drivers/gpio/gpiolib-acpi-core.c index 64040b098e91..90bda2d7da57 100644 --- a/drivers/gpio/gpiolib-acpi-core.c +++ b/drivers/gpio/gpiolib-acpi-core.c @@ -322,9 +322,14 @@ static struct gpio_desc *acpi_request_own_gpiod(struct gpio_chip *chip, { int polarity = GPIO_ACTIVE_HIGH; enum gpiod_flags flags = acpi_gpio_to_gpiod_flags(agpio, polarity); - unsigned int pin = agpio->pin_table[index]; + unsigned int pin; struct gpio_desc *desc; + 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)) return desc; @@ -337,7 +342,12 @@ 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->pin_table_length == 0) + return false; + + pin = agpio->pin_table[0]; if (agpio->wake_capable != ACPI_WAKE_CAPABLE) return false; @@ -367,6 +377,9 @@ static acpi_status acpi_gpiochip_alloc_event(struct acpi_resource *ares, if (!acpi_gpio_get_irq_resource(ares, &agpio)) return AE_OK; + if (agpio->pin_table_length == 0) + return AE_OK; + handle = ACPI_HANDLE(chip->parent); pin = agpio->pin_table[0]; @@ -1111,6 +1124,11 @@ acpi_gpio_adr_space_handler(u32 function, acpi_physical_address address, return AE_BAD_PARAMETER; } + if (pin_index >= agpio->pin_table_length) { + ACPI_FREE(ares); + return AE_BAD_PARAMETER; + } + length = min(agpio->pin_table_length, pin_index + bits); for (i = pin_index; i < length; ++i) { unsigned int pin = agpio->pin_table[i]; -- 2.54.0