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=1796380690; b=r/Ervs2F3gxDB2BDI0kw8RQoKQpE00HewJEJstCrezgztikYhWQ0kdxrqu4LIoFzdSt/ f7Jyszdv7p3vxaIYqF3G6Xeau/mfRpNmDV31hdoAO9lzf5HSZjzoIgIgfM0lHPQWmP5Jf 4fstpoE7AzZY0J6GYKD2II8MlKkjUZNyQtTH68UNjFKSeKa9jbYD/7EXYcdU3ARmh0FcQ 7HSrBndBQ6i/LVI3BOKJfSVkjDhVDPD8Ms+RFTOAmGq4Z8AFRnrCMu2jOVmXt0HBAKZhl ke8oKueAAjxoRnNd/SWwXAdqpC6dgZ7uLqSfQ8Kx1Dp+bEd7mwxHlTqofiKIQxdHPpw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380690; 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=p4v3CrxPcqaB1elbcVyPk2tlyVNkHa4WDf6Og9RHpvs=; b=VtOXxl6MrK5TBI3mipzXLzoes4rht020fYPd2EiJnK+mvjQm6gy9RrWcjhbt1rXYKTI4 dNKA5dNHrbSNl+OkbV0XdzoK5A7G4WWx9w8tAZbv9+BYDckMqq94MJ8+cFO3A+Pkv3Jee +EsM4ohoWLCk2eL3pbo+j7HP53OE4lTGQVTrvAlft9sgIddkhIi06s4fv1dhjJToXurYj 3uLDKntFnBV26QEVupSklTinM3t9xGMWSgg9g9UUkmXlIvC+seeK56vx94Z/Dw55rOcNU NnfdTNgJNZfC10lZmNNj4WCN8moXwkdUACj7iBXcf9+vG+0wuvgVbGiiscaqjws13WQ== 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=TBtRpOkt; 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 3CBB6606A322; Fri, 4 Dec 2026 10:38:09 +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=TBtRpOkt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 676CF1F000C2; Fri, 4 Dec 2026 10:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380689; bh=p4v3CrxPcqaB1elbcVyPk2tlyVNkHa4WDf6Og9RHpvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=TBtRpOktU0iSTbZXrkyrfmLxhzyLy5sMqyFJq8tvSbRUQOWX+rVplHuzbR864tx3b 0ue2v40zhfnV4sWBTu6tQpYDOR5gS3lFw0zFBtuR+0kxB9LwnLc+HLCQXO1KFK4N18 KkoQo03yecQr5Bl2OhWdp0s1zXNLsz+DCQkA5mxE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Andrey Misiurov Subject: [PATCH 7.3 355/742] drm/radeon: Bound GPIO I2C table entry count from VBIOS Date: Fri, 4 Dec 2026 19:03:39 +0900 Message-ID: <20261204100644.508584075@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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++) {