Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 487792848BA; Mon, 23 Mar 2026 15:13:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278825; cv=none; b=iRkGbWdYbjoFD8KALFTvx988sgaMtxQ/x3FnJBwAmXsSCopyIMZVFBV8Fv1wpvDn9p6xU2h4/NflqgwcAnrcDBcfGTYVzbBITknggJAzAKVDeRWGmO+SgdL6+pRYW9UKuoYvtSVat/cBF8PdJGWAdHV7VClDrEu+ExRRkCERVqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774278825; c=relaxed/simple; bh=HP7lbw++zTOvjOIJXtNewzK1Lduss2z9DIbCMeFS4eU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mNnnlOUe/a1ICt1Oh9Xj67p2rl0Z6sz0Zxhk64BcaLbCqaDCNblIWKOrfZ8bOWqn90Ttvsr5o1q+7gN8xJ7xkjf3pWjkhEttBFgcJSSmLvq+4yN9NexF6r3G4tmBhHExyi/ibPdU7DQZtmFrEGI5KaNjXniIjCidILo76LHsYZ4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NlAz/K9I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="NlAz/K9I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5B4CC4CEF7; Mon, 23 Mar 2026 15:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1774278825; bh=HP7lbw++zTOvjOIJXtNewzK1Lduss2z9DIbCMeFS4eU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NlAz/K9IHVcsu8l5p8EMDfidMUbJy7kzYVBG4nwsRiiNs3pb7iBpzxFlH15PCma2I UuAWt5bY6mW8AmBWxEH84UyAekryN+TpR3eUYSahKBDc6XukjGCLkKqtm3+nBHojji DSEZUkFHknh3uj6PwtBfbu+fuROYYrhfWevr1iSA= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Lijo Lazar , Hawking Zhang , Alex Deucher , Alva Lan Subject: [PATCH 6.6 432/567] drm/amdgpu: Add basic validation for RAS header Date: Mon, 23 Mar 2026 14:45:52 +0100 Message-ID: <20260323134544.618277614@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260323134533.749096647@linuxfoundation.org> References: <20260323134533.749096647@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Lijo Lazar commit 5df0d6addb7e9b6f71f7162d1253762a5be9138e upstream. If RAS header read from EEPROM is corrupted, it could result in trying to allocate huge memory for reading the records. Add some validation to header fields. Signed-off-by: Lijo Lazar Reviewed-by: Hawking Zhang Signed-off-by: Alex Deucher [ RAS_TABLE_VER_V3 is not supported in v6.6.y. ] Signed-off-by: Alva Lan Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c @@ -1338,15 +1338,31 @@ int amdgpu_ras_eeprom_init(struct amdgpu __decode_table_header_from_buf(hdr, buf); - if (hdr->version == RAS_TABLE_VER_V2_1) { + switch (hdr->version) { + case RAS_TABLE_VER_V2_1: control->ras_num_recs = RAS_NUM_RECS_V2_1(hdr); control->ras_record_offset = RAS_RECORD_START_V2_1; control->ras_max_record_count = RAS_MAX_RECORD_COUNT_V2_1; - } else { + break; + case RAS_TABLE_VER_V1: control->ras_num_recs = RAS_NUM_RECS(hdr); control->ras_record_offset = RAS_RECORD_START; control->ras_max_record_count = RAS_MAX_RECORD_COUNT; + break; + default: + dev_err(adev->dev, + "RAS header invalid, unsupported version: %u", + hdr->version); + return -EINVAL; } + + if (control->ras_num_recs > control->ras_max_record_count) { + dev_err(adev->dev, + "RAS header invalid, records in header: %u max allowed :%u", + control->ras_num_recs, control->ras_max_record_count); + return -EINVAL; + } + control->ras_fri = RAS_OFFSET_TO_INDEX(control, hdr->first_rec_offset); if (hdr->header == RAS_TABLE_HDR_VAL) {