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=1796389183; b=qXJfU9vu1WdNW1vUuLDrmD22sY/Ow9I26mWmdV4kPlnYpTAnc1iD0OMkNDcIckZjkayM 7iOi61OMde2YzjdRNner0JdEuckXzGNwpBez4ft+1ARJ0bOysVYiNKXRw03bpHXgemOWB icIfA06uyn3zpsKX4GIiN7ZOg7bEKdL27lwNC7Sy7NXot/IczwRpL47+iI0RWVLhZI4JT M4I6QfiXds9HFTYgMT6vfwVSdcieR4DJO38utzAy8ExBwnn2IhZy4bcG+b/O0RY1kdSWY B+ViIUJYNAqEClg2wqhiVO8jRFiAbJxn51whFCDCvU1hLuoykJ9MtQVLgAGnTjRVuDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389183; 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=4W9f/mk927/VaXVSTkcUShcpMzBBa+OqMrip5lrJpQE=; b=J7u17TvSCFDRN3htG2wfJzTohRAD2iTHi616ZHt0fLKfizvAKoVJqyp8TsIb0PTbuiBC fy1OSrpdOHspeO5Ft0FYtzIw4od2P0izoVEvO1tPDuiovDfTcCESggWu/Ri1BUevPIWQj CatcoHa1prtStu5ywptokqAg8UZMOkxP+bhLIhGclPHdj76sIB9WbBT42tD/Sj48P0bhY m8pgr3EQ0S7rpFtsYor/oO95QFYjutIKtPYB3nChWySdLa87mEc2IvRfINKcE9fGN//xZ W67xAjRYkcdR1Ix+N2/30iWO+xBshMU5GA7fOMMPDmULDwXDTkua70OIdoTPl7sE+tw== 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=DzklZgo4; 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 8CF37606A322; Fri, 4 Dec 2026 12:59: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=DzklZgo4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 809AE1F00931; Fri, 4 Dec 2026 12:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389182; bh=4W9f/mk927/VaXVSTkcUShcpMzBBa+OqMrip5lrJpQE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=DzklZgo49AxygWHSn6uTZVGMHFgTanwlqDDqI8o1ASm99BTL6ZWU+e0F8PF9XmpSw YgtBUnKjpCugf+TPVNyg6/kVz5EA8utj+2HtYh52pfCAEk0tD9UB4qgUkULmnpKwz8 15ukBM+/Y7iXHndK378ytHjmnrUOjXvmKik3Ae6Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Andrey Misiurov Subject: [PATCH 6.1 0896/1059] drm/radeon: Bound GPIO I2C table entry count from VBIOS Date: Fri, 4 Dec 2026 19:07:07 +0900 Message-ID: <20261204100707.219995100@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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.1-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 @@ -124,6 +124,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) { @@ -141,8 +157,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++) { @@ -175,8 +190,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++) {