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=1796383723; b=CuKk1d8MRED9BE8qBf/C6p6KGY43lPpZDTyp5JKZphHJuk5eR1z2mlEprXRJ/eie5dSz Cr6xdw8boRJqVboNAalgE21/Kl2kvxLfjItMfcDTdYyKTXE5Mw92OezYTvDl5gFa8YB6g 28SI6W4qGkoTUjNBN0W5JZmRTWkN2arr2RT48WlWfsggobKprcZSWj11DqF1mST/FmiD3 9ZtUzWfNXP+0TwpQNBmyqRvjX0uWMROaWbb07IBHH8vsdXn/m1k8nKkqGvERm8A4S4mLX L85mvTykeBCiaIhl1FGpVg8J+mLdr2uY3O20/0XQkEXpB5hG17W0ceU2z62uLwAOj/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383723; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=VZCByrtRjOeLdCb1VS4fckKn21PLeweI+KOuXgeuGuk=; b=dSmejC0fPYyAoaankSleaRk/u29VX0CU6kyVfqrZNrCYWSBAwgvOm1My9SjhXdKgkZGy 22KjfCsAsP2nnGyYAJELM4NnsWPEQ84C57x5AlJ3OUNKU731zU7lBIVYRE7KeSR+NIexg dmL7luMIF7+VnpUX6otlO2EFV8W1kImMI4PsVXO7xNUeTtwIEMvfTm18qhF/BdX63kBzc kJtKJw9bJoqpMduVC+pvUklRomLXBhetGbQtf3Jkddvw1/0iP+LwTc7ub7lAiJsgMNRZ/ uZgt8zQ5K9uTQDIPx5J9+Jc+nmoUJUPEXn95DpKssY9HnMY5ZrScxCO61zZObAtS3qg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=D8Q8ljKd; 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 90C51606A69A; Fri, 4 Dec 2026 11:28:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=D8Q8ljKd Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9BE501F0093A; Fri, 4 Dec 2026 11:28:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383723; bh=VZCByrtRjOeLdCb1VS4fckKn21PLeweI+KOuXgeuGuk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=D8Q8ljKd+32UnatYitJYHK+mLhz374yKNdSh7+waygj9y420FsQefi7bVpZ8MTiga eDkNc+eeakXmNZVi2Uts2EfpOWSbDC+viXcfihSxWRziRORNs5ciBXa1EiIeSK3Akd f/rXPZfCXiaaUGiqz60TzdVf8VWUv8aDXT6KV3WA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Andrey Misiurov Subject: [PATCH 6.12 326/555] drm/radeon: Bound GPIO I2C table entry count from VBIOS Date: Fri, 4 Dec 2026 19:06:09 +0900 Message-ID: <20261204100622.322000351@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrey Misiurov commit 7345797c8652c976d18dc4be4bae632557c3bc38 upstream. radeon_atombios_i2c_init() derives the number of GPIO I2C entries from the size field of the VBIOS GPIO_I2C_Info table and stores a bus for every valid entry in rdev->i2c_bus[i], which has RADEON_MAX_I2C_BUS (16) slots. A table that claims more than 16 entries makes it write past the end of the array into the rest of struct radeon_device. A size smaller than the common header wraps the subtraction and the loop walks far past the table. radeon_lookup_i2c_gpio() uses the same calculation. Reject undersized tables and cap the entry count at RADEON_MAX_I2C_BUS. Fixes: f376b94fbc0a ("drm/radeon/kms: unify i2c handling") Reviewed-by: Alex Deucher Signed-off-by: Andrey Misiurov Signed-off-by: Alex Deucher (cherry picked from commit ad5ddb2f77ff5e80b3c793f062dc1cad9907a2b9) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/radeon/radeon_atombios.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/radeon/radeon_atombios.c +++ b/drivers/gpu/drm/radeon/radeon_atombios.c @@ -125,6 +125,22 @@ static struct radeon_i2c_bus_rec radeon_ return i2c; } +/* + * The VBIOS table size is not checked against the image; cap the + * entry count to RADEON_MAX_I2C_BUS, the size of rdev->i2c_bus[]. + */ +static int radeon_atombios_gpio_i2c_num_entries(uint16_t size) +{ + u32 bytes; + + if (size < sizeof(ATOM_COMMON_TABLE_HEADER)) + return 0; + + bytes = size - sizeof(ATOM_COMMON_TABLE_HEADER); + return min_t(u32, bytes / sizeof(ATOM_GPIO_I2C_ASSIGMENT), + RADEON_MAX_I2C_BUS); +} + static struct radeon_i2c_bus_rec radeon_lookup_i2c_gpio(struct radeon_device *rdev, uint8_t id) { @@ -142,8 +158,7 @@ static struct radeon_i2c_bus_rec radeon_ if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) { i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); - num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / - sizeof(ATOM_GPIO_I2C_ASSIGMENT); + num_indices = radeon_atombios_gpio_i2c_num_entries(size); gpio = &i2c_info->asGPIO_Info[0]; for (i = 0; i < num_indices; i++) { @@ -176,8 +191,7 @@ void radeon_atombios_i2c_init(struct rad if (atom_parse_data_header(ctx, index, &size, NULL, NULL, &data_offset)) { i2c_info = (struct _ATOM_GPIO_I2C_INFO *)(ctx->bios + data_offset); - num_indices = (size - sizeof(ATOM_COMMON_TABLE_HEADER)) / - sizeof(ATOM_GPIO_I2C_ASSIGMENT); + num_indices = radeon_atombios_gpio_i2c_num_entries(size); gpio = &i2c_info->asGPIO_Info[0]; for (i = 0; i < num_indices; i++) {