From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA60D606A338 for ; Fri, 4 Dec 2026 15:15:00 +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=eKmUh6fQ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C53B10E23A; Fri, 4 Dec 2026 15:14:55 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 536C210EC0B for ; Fri, 4 Dec 2026 15:14:49 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 095CA40BA5; Fri, 4 Dec 2026 15:14:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CABAE1F00897; Fri, 4 Dec 2026 15:14:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796397288; bh=OU85nwRfBUfwKE+n6pr/ovADlOy/Hx9aLH2uf7WOd/4=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=eKmUh6fQiCHKqlakZ1ClKnPvL683/p/clNgC4dSqYrF/Z+5Nh2yzqvMyn/k8cxk8O FVYe9aePAJLKsK1XoCjPBn5w9RVzT1i+8FfvB4sG9UlEXrh3kR8QdxK+lCc6DVKB8J PZmyYxlpVL5+hkjFXN2bx59qfBAGZzPPLeyljie4uRzNIUnEolWOcQnQJ93r7NXRIM KgT6kj2p1xgEAHeFzWKmPhaVhEGTeMZALZJ33TXI5jocNlJxKagjsj4YGRPOJMrmNt 3RH9gjC1zSMdsLM2gmSxJ1XjOw0PZ+AAAsF2fYsQ4K9LUA0y1IyaBMgkH6+gZ9ebkM hkpMD0M7d/+Kw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/9] drm/amdgpu: update table info retrieval from discovery binary To: "Frank Min" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261204142408.988734-3-Frank.Min@amd.com> References: <20261204142408.988734-1-Frank.Min@amd.com> <20261204142408.988734-3-Frank.Min@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 15:14:48 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] drm/amdgpu: v0/v1 discovery lookup broken by table_id scan - [Medium] drm/amdgpu: amdgpu_discovery_table_check() ignores invalid headers - [Medium] drm/amdgpu: amdgpu_discovery_refresh_nps_info() misses v2 table_id lookup - [Medium] drm/amdgpu: OOB read in amdgpu_discovery_get_table_info_from_bin() - [Low] drm/amdgpu: commit message omits discovery table format and lookup rationale - [Low] drm/amdgpu: spurious dev_err() in amdgpu_discovery_get_table_info() -- commit 2a203845aec3dbcd54cbcfc1a749319c4ba689f3 Author: Frank Min > drm/amdgpu: update table info retrieval from discovery binary > > Update table info retrieval from discovery binary to align with > discovery table update. > > Signed-off-by: Frank Min > Reviewed-By: Hawking Zhang [Severity: Low] Can the commit message explain what changed in the discovery table format and why the lookup and error handling changed? It does not mention that v2 binaries populate table_info.table_id and may omit unused entries, why v0 and v1 are also changed, or why amdgpu_discovery_table_check() returns 0. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/= drm/amd/amdgpu/amdgpu_discovery.c > index c52b0d9ac00b7..5997946fb1171 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c > @@ -609,18 +609,36 @@ amdgpu_discovery_get_table_info_from_bin(uint8_t *d= iscovery_bin, > uint16_t table_id) > { > struct binary_header *bhdr =3D (struct binary_header *)discovery_bin; > - struct binary_header_v2 *bhdrv2; > - > - switch (bhdr->version_major) { > - case 2: > - bhdrv2 =3D (struct binary_header_v2 *)discovery_bin; > - return &bhdrv2->table_list[table_id]; > - case 1: > + struct binary_header_v2 *bhdrv2 =3D (struct binary_header_v2 *)discover= y_bin; > + uint16_t version =3D le16_to_cpu(bhdr->version_major); > + uint16_t binary_size =3D le16_to_cpu(bhdr->binary_size); > + struct table_info *table_list; > + uint16_t num_tables, i; > + size_t table_offset; > + > + switch (version) { > case 0: > - return &bhdr->table_list[table_id]; > + case 1: > + table_list =3D bhdr->table_list; > + num_tables =3D ARRAY_SIZE(bhdr->table_list); > + break; > + case 2: > + table_list =3D bhdrv2->table_list; > + num_tables =3D le16_to_cpu(bhdrv2->num_tables); > + break; > default: > return NULL; > } > + > + table_offset =3D (uint8_t *)table_list - discovery_bin; > + if (table_offset + num_tables * sizeof(*table_list) > binary_size) > + return NULL; [Severity: Medium] Can this bounds check still read past the end of discovery_bin? It compares against bhdr->binary_size from the binary itself (up to 65535 bytes) rather than the allocated buffer size. adev->discovery.bin defaults to DISCOVERY_TMR_SIZE (10 KiB), and amdgpu_discovery_sysfs_early_init() always copies DISCOVERY_TMR_SIZE bytes into ip_top->discovery_bin. A v2 header with a larger binary_size and num_tables passes this check and reads out of bounds during the scan. In addition, case 2 reads bhdrv2->num_tables before checking that the buffer is at least sizeof(*bhdrv2) bytes, while amdgpu_discovery_read_binary_from_file() only enforces a 12-byte minimum. Passing the allocated buffer size into this helper and checking both binary_size and sizeof(*bhdrv2) against it would close both over-reads. > + > + for (i =3D 0; i < num_tables; i++) > + if (le16_to_cpu(table_list[i].table_id) =3D=3D table_id) > + return &table_list[i]; > + > + return NULL; > } [Severity: High] Does routing v0 and v1 headers through this table_id scan break table lookups on every GPU with a v0 or v1 discovery binary? In drivers/gpu/drm/amd/include/discovery.h, table_info.table_id is padding for v1 (and v0) headers and is zero-filled, while bhdr->table_list is indexed directly by enum table. Every non-zero table_id (GC, HARVEST_INFO, VCN_INFO, MALL_INFO, NPS_INFO) will therefore return NULL, leaving harvest masks and GFX/MALL/VCN configuration unpopulated during probe because amdgpu_discovery_set_ip_blocks() ignores those lookup failures. Scanning all 8 entries of bhdr->table_list on older 6-slot v0/v1 binaries also reads 16 bytes past table_list into adjacent table data. Versions 0 and 1 should keep direct indexing (&bhdr->table_list[table_id]) with bounds checks, reserving the table_id scan for v2. [Severity: Medium] Should amdgpu_discovery_refresh_nps_info() also be updated for the v2 table_id lookup? It reads the discovery header directly from VRAM and still indexes bhdrv2.table_list[NPS_INFO] by fixed position under case 2, which will read the wrong entry or fail checksum verification during NPS refresh after reset on v2 binaries with sparse or reordered tables. It also switches on bhdr.version_major without le16_to_cpu() and omits case 0. [ ... ] > @@ -633,8 +651,8 @@ static int amdgpu_discovery_get_table_info(struct amd= gpu_device *adev, > *info =3D amdgpu_discovery_get_table_info_from_bin(adev->discovery.bin, > table_id); > if (!*info) { > - dev_err(adev->dev, "Invalid ip discovery table version %d\n", > - bhdr->version_major); > + dev_err(adev->dev, "Not found table for header version %d table id %d\= n", > + bhdr->version_major, table_id); > return -EINVAL; > } [Severity: Low] Will this emit spurious dev_err() messages during normal probe on v2 binaries that omit optional tables? Previously dev_err() only fired on unsupported header versions. Now amdgpu_discovery_init() probes the optional MEM_RESERVED_INFO table (whose caller logs absence at dev_dbg()) and amdgpu_discovery_set_ip_blocks() probes MALL_INFO and VCN_INFO, logging errors whenever they are absent. [ ... ] > @@ -645,15 +663,16 @@ static int amdgpu_discovery_table_check(struct amdg= pu_device *adev, > uint8_t *discovery_bin, > uint16_t table_id) > { > - int r, act_val, exp_val, table_size; > + int act_val, exp_val, table_size; > uint16_t offset, checksum; > struct table_info *info; > bool check_table =3D true; > char *table_name; > =20 > - r =3D amdgpu_discovery_get_table_info(adev, &info, table_id); > - if (r) > - return r; > + info =3D amdgpu_discovery_get_table_info_from_bin(discovery_bin, table_= id); > + if (!info) > + return 0; [Severity: Medium] Does returning 0 on NULL bypass header validation and mandatory IP_DISCOVERY checks in amdgpu_discovery_init()? amdgpu_discovery_get_table_info_from_bin() returns NULL for an unsupported version_major, an out-of-bounds num_tables, and a missing IP_DISCOVERY table, not just absent optional tables. Because amdgpu_discovery_init() has no other check on version_major or num_tables, it will return 0 on an invalid binary instead of freeing adev->discovery.bin and calling amdgpu_ras_query_boot_status(). That lets amdgpu_discovery_sysfs_early_init() copy the invalid binary in amdgpu_discovery_reg_base_init(), and on legacy ASICs leaves adev->discovery.bin non-NULL so amdgpu_discovery_sysfs_init() leaks ip_top and die_kset when amdgpu_discovery_sysfs_recurse() fails. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204142408.9887= 34-1-Frank.Min@amd.com?part=3D3