From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DF5F6420876 for ; Wed, 8 Jul 2026 06:18:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783491537; cv=none; b=P4oHN7nt+nTV+joQhO8KA1lsUlUWroFUCyBOGHV6X8cEr8NOOJ0U8h2BykgrIIYVT/i++lSLOzehHXDk2Bb9WbcdW1JPo8L7FsJSW+vZhlr7Djb5DmFqd2AqHxO4nFIYnz5L761GInefm7vF4pi5TnMikSO0SGefmuMSIJXsEJ8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783491537; c=relaxed/simple; bh=DDVqik3g024djbtq8wKsjUTyoUV/gR/76I31qdIO8Gs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jwBvCQ89RqaDMNiIlh1qmGdKlQbw4kPXK3Fc7oYnPmVlWBi1OJSglu02uCxfOLYyGl/giCcm827vcna+NsVxlYWMZuKJY1r5dHpiYOImK3J//3LJROSyJFev4fUot4RUEJsU52hAoQd7wCasHvVKnecfKTW0x5FR/5NBVd29wFI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ncm56dnO; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ncm56dnO" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-3856d4015e0so20728a91.2 for ; Tue, 07 Jul 2026 23:18:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783491534; x=1784096334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=IeKjljjW0rbzKqDo5+JHTj1l65dd8fRajYjS5rdVpUg=; b=Ncm56dnOmxWEZqFw+UiCfm7QHIwmrAZCmFkSHZE1YNvpuwT9phCGNFjyjicDT7SiSf iEaw1X0RC8vlGdq7QqVr6mWOZNRfDUaGF2nzwq5EOchTcE5NY0o/3J2PRDWA4NJxj6yP 8w/ZvoercZ7Wb8crVq9pLG/eFT5LiYwYrEU1He7L+0rGeeLnIV2zQ+d4BOggVJIfGSM1 h7dqWB5168hFOTHBuAMhnZ7hhV3DGCuGoWJb6Tg9Nc9BkLx5bGFv/Ey7dYGjTZhZZ+B4 wok78O9Q6IrrDMbaFs9xZLc/+U832lB9c/vghiQlSWx4wQNFbqQ2kDQaBY8UVy+1vVzV RsNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783491534; x=1784096334; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=IeKjljjW0rbzKqDo5+JHTj1l65dd8fRajYjS5rdVpUg=; b=U3pDwtNfPWjvdJAQOba+bdEB2qLieCNROGTXj4CTxloEf2ZV9K+UjbXD66ZtZjQAig R9oP98T1fZR2o7QWZFvtCfa5RFWuejtt3POqZlJty0vvm8vdd2wSOE4kGyqt4JRRveuj +Xz+AMg8iwbhlAZLWaQL8Wvfl0dpOcQDBXIMXsrenOSV10kiM7ziZO2Y1lt/IDxcbAxu +ap86LkxoRU4ecl53l+MJwvqXlvau4HgkH+vUlATtguaDncCdjyDYIvFUe8+covPl5ND U9IACCf/EKc0GwzFMrSPFSJYNhL0vDo9zjys1pjIvZqFqXv/cTIfytarUg1aSttOvG/S QRDg== X-Forwarded-Encrypted: i=1; AHgh+RpSnBmUl04NpqVH5fEe4azMZ/vPME6XLXxsIZY2zlo/SWLEBGOaG4AF3ULgGcqZjpaXG6i0Lif/uyQiV0M=@vger.kernel.org X-Gm-Message-State: AOJu0YwPmeh1DYM/Q2yBlhRY9ycTG1i1fv4o89EX69K3soO4Ye8FiOBb xH1g9eJdewheTnLYCYS3bu8vzCowTRb6jNdFB9zaMXcB28VyeyHfZjl6 X-Gm-Gg: AfdE7clQlXOyYkkVes0soNuiNeviuy4R7Kjg2bg41dCNQrevH8A7dTneZA9w10TF5cC itHQC6s9f/ZoUJzopDajxnhCM3ttLfY1RL/5e8D/PLjQG9y8nd0e5IU0ugCalNSGWaexRukg3+m 7foG+nxY/88LaMe5YifivwU2EOTTXBCsULm/0kBzik/iFGgmm4agNcP53TZE9wRQn9SN18fWcI7 69FS+w4WJJnyeV3LJmX97+K/UwSDj+Far8jDuhWBGBbDbJvXWVx2PlsmNExxr3Ts5/E8othLXtq 6dOESx/GFWzphptvWUFVHXMz3aJNlLO1YRoBHcijizAK7BQJTs0KHJsGJDJzhFhtTvJDB/sqBDf 7xFcJFIfsp/Trd7Zv0LmjHrjw5kyLZ6TwwauBo3ykvDuIAomuJdNFkpVrtAwVd6TtV1MiU+Is1C 6bHkCS7JvRFdFJUOaGtQ== X-Received: by 2002:a17:90b:57cd:b0:381:77cd:38ca with SMTP id 98e67ed59e1d1-389417e432fmr977538a91.4.1783491534182; Tue, 07 Jul 2026 23:18:54 -0700 (PDT) Received: from kali ([122.162.146.188]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3117d847e17sm12888463eec.18.2026.07.07.23.18.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2026 23:18:53 -0700 (PDT) From: Pavitra Jha To: alexander.deucher@amd.com, christian.koenig@amd.com, airlied@gmail.com, simona@ffwll.ch Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Pavitra Jha Subject: [PATCH v2] drm/amdgpu/discovery: validate table offset before IP discovery header cast Date: Wed, 8 Jul 2026 02:18:34 -0400 Message-ID: <20260708061835.111986-1-jhapavitra98@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260624184444.D4A401F000E9@smtp.kernel.org> References: <20260624184444.D4A401F000E9@smtp.kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sashiko AI review of the previous fix flagged three remaining gaps in the discovery blob parser, all stemming from the same root cause: the ip_discovery_header pointer itself is constructed from a firmware- controlled offset with no validation before the cast. ihdr = (struct ip_discovery_header *)(discovery_bin + le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset)); This offset is a firmware-controlled u16 read directly from the discovery blob's table_list, with no bounds check against adev->discovery.size before being used to construct ihdr. Every subsequent read from ihdr, including num_dies and die_info[], is downstream of this unchecked pointer. The other two items in that review (unbounded ip_offset advancement via num_base_address, and num_dies exceeding die_info[]'s capacity) were already addressed in the previous fix. Fix by validating the table offset in amdgpu_discovery_get_table_info(), which is the common path used by all callers except amdgpu_discovery_read_harvest_bit_per_ip() (which reads table_list[IP_DISCOVERY].offset directly rather than going through get_table_info()). Add the equivalent check at that direct access site as well, so all paths that construct an ip_discovery_header pointer from a table offset are covered. The check validates the offset itself against adev->discovery.size, independent of any specific downstream struct size, since get_table_info() is shared across ten different table types (IP_DISCOVERY, HARVEST_INFO, GC, MALL_INFO, VCN_INFO, NPS_INFO, and others) each with differently-sized table structures. Fixes: d0c647a6aae2 ("drm/amdgpu/discovery: support new discovery binary header") Cc: stable@vger.kernel.org Signed-off-by: Pavitra Jha --- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c index b4ee5fc8e..9b55c56cb 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c @@ -564,6 +564,12 @@ static int amdgpu_discovery_get_table_info(struct amdgpu_device *adev, return -EINVAL; } + if (le16_to_cpu((*info)->offset) >= adev->discovery.size) { + dev_err(adev->dev, "invalid table offset %u for table_id %u\n", + le16_to_cpu((*info)->offset), table_id); + return -EINVAL; + } + return 0; } @@ -766,6 +772,14 @@ static void amdgpu_discovery_read_harvest_bit_per_ip(struct amdgpu_device *adev, int i, j; bhdr = (struct binary_header *)discovery_bin; + + if (le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset) >= + adev->discovery.size) { + dev_err(adev->dev, "invalid IP_DISCOVERY table offset %u\n", + le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset)); + return; + } + ihdr = (struct ip_discovery_header *)(discovery_bin + le16_to_cpu(bhdr->table_list[IP_DISCOVERY].offset)); -- 2.53.0