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=1796382191; b=f2F7hYfny2fU/m9soni5Y4hr1IDdp4L9rEUzLIpufNn+PiTNlVRoNzi90aW4qtyDJZ5C W7OB571KDcTKSwspqQQ/kvyrszX5xtayKwUsjia+o7ZdFsZfvXzzYOZNn6csepEbR44JR YzTjU0OzuaqEg7JwcfUC42yZyl1aSqKq12496keuY9YK0ykHL3VrgL+GRvNIvRodXrpAS Zo6F+0qctYoskOxGaTEtQodzIgBd100qS2EPiM5CqbI4DmGtRCvRd4H7YUZAAH4Zam3kW niIJAdyIyBaBIUnlONYQKVyTtzMGdOFH6/xgnc8GFRv2r84NM+oGioPofr+bctLJbPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382191; 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=0UrEYOkRNhgFN/vkWf+T8L/2OSIOxS5iduuzZMD+HsY=; b=sC4eMPN8B0vkHlzSEGD3OJXlIQrLXY4CRhzZMqfpY87FFGCfAi+PANqjWLMvpvMgaUf6 ME8+20MKI6CVhm+cFh+stIC0LomdwhYVPef8AuayI2hYJmFSpN/gq5/3R0a4eAQEflo3W fI4pRdk7oWKcJ1hpaI0y/1uTaeNG1ywcK9D5r2c0kGigtLZtvUUpy2IxvEBrzaUFN+cBr 26Boh1cgaoWZb9HkxfcGqhYnlBJLzfP+NAfSpyOKYgZRbf47jRPJJivq1FtyNBiOeMvDR m9ZT5lflEr8bwIy8S5Z5pNL5GjXb1morc3SLoDN4B6vofpaKpcLTKpfm9wd+FcUvV7Q== 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=hzgCndSQ; 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 99C2A606A322; Fri, 4 Dec 2026 11:03:11 +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=hzgCndSQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 12E831F000CE; Fri, 4 Dec 2026 11:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382191; bh=0UrEYOkRNhgFN/vkWf+T8L/2OSIOxS5iduuzZMD+HsY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=hzgCndSQnHxav1o5Ig6/Z3aVI+ZgvOC5FPkCiW8HPb3/5MVJnOWDSF1jeCFPNpcM2 hfaS/VrSZzkF7qHY164Mym9tOzXoBFgm+2wT+McGKlxTO7+bg5QLl6tU/6rRYSkPoP IoGa/C9i2asW1EKbuTGIVjNR8Obho75qLZeRk5ME= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alex Deucher , Andrey Misiurov Subject: [PATCH 6.18 347/703] drm/radeon: Bound GPIO I2C table entry count from VBIOS Date: Fri, 4 Dec 2026 19:04:06 +0900 Message-ID: <20261204100637.023743723@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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++) {