From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796331381; b=c0e3T01PPsduFWobKYksECHtWT7+N+6o790KoxaAwx8FIszSgWi6nbjx90EVX+9aZRPF N22KjUBAzxRGNUdiyYKKeIblQxlNmT83mvskh7XOA9HXHApkS6Tg1MJb1JeqQ9z075Ko4 uafc46OVyWDbtXsDQWXm0xoMBlXWKSnTSC5xAGWgxMmaKhWPaH1ulPFBLZE/pDnrR3sP4 GSV+QCvO2fV9tWpm+Q9+hu0aQcKWz8wGJrUJEQ0fwpkbM4p7a6a7FuZk0d458xHhLglMA p305poI+gfqJRqt5qYrfQqCAL9sfyptMq/WjQ3NXOVpKWf5fM7L0KNjVBdC8DOnEXDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331381; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=ZvlYECuToP2OMDIcx4z7k0pOwOcT10MIAVQLFkNp3qw=; b=yIWclE+kAkh3/Pd5L/MkHK7sBtH1usGdPelEYO3BfHGHAc2s/yLWiefs4mvOTpX1xy8Z DrQT8LlSnvX5BJ/WB+InqQiirLpjPDBrfR4ViNZYKn0yu71RQWlY8Ua3o3ZJ2d2pZh+X7 iM9ZKtKrVwUgs8byI4jewscJ8YC63nxVT/F23yhPyJjjLAcnjsV7NrY1aRVaXfTadDbbI zphozSvpZCULXZV0Ur0uecRxuMVmsRyRxwvBqnzvnZhX4ZW1ELezwmeV4wemXYQULa5en sR/Vxr14gaunuv7KnoQb/9NWNMSxfLGV/3rVN4i1o2OVlUY2Bd2n7pw22bpiVIpyEMw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BA88PzwG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 568CE606A32F; Thu, 3 Dec 2026 20:56:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BA88PzwG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3FF101F00939; Thu, 3 Dec 2026 20:56:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796331380; bh=ZvlYECuToP2OMDIcx4z7k0pOwOcT10MIAVQLFkNp3qw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BA88PzwGgrukvvKYSh+DjmIBUK6ykcyRLjpGRpAzs9TuyNIS1S41+eaaO0E3gj+xL ImaLNL8RT/xRy8b6iNXtTPDPuthhaQxaRslaEwcp54Meqyl6CUbuSlZTg00c76ZJ8m HqRJKBl568NTCo6dkj2kfnLfdQVPjBaQiiQO5NLxznHJVTnNmJ4DF6Bv1WLUP92OcD HkHEe4guVKiKoDPnVa5HIe/4nhSS4lUEAwAYlkc1J1NSxsisd4GJjatO6b9YkJ4t01 FP0tPcgxNI1SBp0GbcI89J6vm8Zp1sCM+/oZUyYr4D9YtzyA+NUcVg+tYwrPf/7isN 5B3BTLN8Gs8SQ== From: Lee Jones To: lee@kernel.org, Keerthy , Linus Walleij , Bartosz Golaszewski , "Software, Inc" , Jan Kotas , Grygorii Strashko , linux-gpio@vger.kernel.org Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH 01/10] gpio: davinci: Validate ngpio against MAX_REGS_BANKS in davinci_gpio_probe() Date: Thu, 3 Dec 2026 20:54:59 +0000 Message-ID: <20261203205606.3905705-2-lee@kernel.org> X-Mailer: git-send-email 2.56.1.915.g69d5ec7298-goog In-Reply-To: <20261203205606.3905705-1-lee@kernel.org> References: <20261203205606.3905705-1-lee@kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit davinci_gpio_probe() validates nirq against MAX_INT_PER_BANK (32) but never bounds ngpio against MAX_REGS_BANKS (5, supporting at most 160 GPIOs). A larger ti,ngpio value causes out-of-bounds reads past offset_array[] and out-of-bounds writes past chips->regs[] and chips->context[]. Reject ngpio values greater than MAX_REGS_BANKS * 32 with -EINVAL and size offset_array with MAX_REGS_BANKS. Fixes: 8f7cf8c65746 ("gpio: davinci: Remove gpio2regs function") Closes: https://sashiko.dev/#/bug/linux-59cf1b6f-2241-467c-a82a-93a3d1bf5d16 Cc: stable@vger.kernel.org Signed-off-by: Lee Jones --- drivers/gpio/gpio-davinci.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c index 5f24367ad9af..f1f2b8f75761 100644 --- a/drivers/gpio/gpio-davinci.c +++ b/drivers/gpio/gpio-davinci.c @@ -43,7 +43,9 @@ typedef struct irq_chip *(*gpio_get_irq_chip_cb_t)(unsigned int irq); #define BINTEN 0x8 /* GPIO Interrupt Per-Bank Enable Register */ -static unsigned int offset_array[5] = {0x10, 0x38, 0x60, 0x88, 0xb0}; +static unsigned int offset_array[MAX_REGS_BANKS] = { + 0x10, 0x38, 0x60, 0x88, 0xb0, +}; struct davinci_gpio_irq_data { void __iomem *regs; @@ -179,6 +181,8 @@ static int davinci_gpio_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "Failed to get the number of GPIOs\n"); if (ngpio == 0) return dev_err_probe(dev, -EINVAL, "How many GPIOs?\n"); + if (ngpio > MAX_REGS_BANKS * 32) + return dev_err_probe(dev, -EINVAL, "Too many GPIOs\n"); /* * If there are unbanked interrupts then the number of -- 2.56.1.911.g883d8bcb20-goog