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=1795029712; b=ACagcQqko2cB+M7XqoaZerPDWgAi/njoPwvtGsMXoFvDfQN0gwreu/u7kv+eY1WNPik1 DJMwv3uQCh6NIzoJ98o16hyQqp+NEFB0FkAt6TeMnytD+PL0X8h3ygDFC7TIAtUvdYUf5 c7mFo9sjx3nAWlL1HB5GJJIbImpi/ytMK/m3HmFWjGR1fXRKzVQoVyhVF3GVNUlUPmd65 7j+Y0xt/c68xCWDHM5jB+bswz/UbbvtyD9O82plcBzd5FaCCr+8bPyYry/hR35p17C5jG S4xzWgw1CJMKkHvvmZuKOExHD1j0SB8jHj3J1qQgyFHCZZ0sqEd0sMjcvBFogVtw86w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795029712; 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=2gPfW6ehiJ+KGouPz4oJTYcFxZltFz7WKzxdY53FJs0=; b=oXTX6M/t9/mri+07wazhHmD4YIqyqtVx842C2XJlIrJlVuaq2X4q3INQ0Ur4kVhbzW/n 2Vo8cnLdb28vTDPyhiaPUHTDM2iGcCFAzkeShVmNumEZ56Ux5Dhr+UYq7q3REvf8VWh5G p1mOqWLPMEGo24IPtd0S1w1N9X/HOrYGt3Fav/HnPj8wM5TfQYBncUpGRsNwKngCH07MD ksJ7YDYNvaYUlD1IAZuqB2pPokudeUDf7TwtWSmsbVp8v5TdAsErobSfHAtWeTMeJBd6P i45I+qCoKa5VVkwktidt9OJnNzrEb3kaioX8y3NSME4uQkGHfjfx4QZZBYXBBBAPRwQ== 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=1ZcND7DB; 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 4F1A3606A31C; Wed, 18 Nov 2026 19:21:52 +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=1ZcND7DB Received: by smtp.kernel.org (Postfix) with ESMTPSA id A96281F000C4; Wed, 18 Nov 2026 19:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795029712; bh=2gPfW6ehiJ+KGouPz4oJTYcFxZltFz7WKzxdY53FJs0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1ZcND7DBO5c2gvCxZF2gLIoDI8Vlm3BU8qko3ZkfEAbsh0btIAxkZhvyR4VRcJt0e LZChNIwliRFUvDJYGJGKvS3OEu6C7TgJx88o9bqeD00OEKKFm8eh4DlSBQWAyyp1r8 s+B85vkkP2YWViCMIk7X/Iye2w7dX+KBSlPOV39s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Hari Mishal , Alex Deucher , Sasha Levin Subject: [PATCH 6.12 0447/1756] drm/amdgpu/atom: bound the VBIOS date, part number, version and build getters Date: Wed, 18 Nov 2026 15:42:54 +0100 Message-ID: <20261118150026.508686230@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150007.957976754@linuxfoundation.org> References: <20261118150007.957976754@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hari Mishal [ Upstream commit aee05c455ad3e72df9a0591baf0b60da518800f3 ] atom_get_vbios_date(), atom_get_vbios_pn(), atom_get_vbios_version() and atom_get_vbios_build() all walk the BIOS image using offsets and counts taken from the image itself, checked only against each other and never against ctx->bios_size: - atom_get_vbios_date() reads 14 bytes at a fixed offset that check_atom_bios()'s minimum size (0x49) does not cover. - atom_get_vbios_pn() dereferences an image-supplied u16 string offset unchecked, then walks and copies from it with only a length cap, not an image cap. - atom_get_vbios_version() takes its search bounds from image u16s; atom_find_str_in_rom() already clamps the search itself, but the match is then advanced by a fixed 18 bytes and STRLEN_NORMAL bytes are copied from there with no check that this still lands inside the image. - atom_get_vbios_build() walks from an image-supplied config-string offset toward the ROM header; a config offset at or past the header makes the pointer difference negative, wrapping through the u16 'len' and passing strscpy() a bound far larger than the 32-byte destination. Bound each getter's reads, walks and copies to ctx->bios_size, falling back to an empty string on a malformed image. Fixes: 29b4c589b43d ("drm/amdgpu: Add vbios info ioctl interface") Fixes: d6fa80266178 ("drm/amdgpu: Add vbios build number interface") Assisted-by: gkh_clanker_t1000 Signed-off-by: Hari Mishal Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/atom.c | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/atom.c b/drivers/gpu/drm/amd/amdgpu/atom.c index 6405d6e9f1f36..ceb132998fe60 100644 --- a/drivers/gpu/drm/amd/amdgpu/atom.c +++ b/drivers/gpu/drm/amd/amdgpu/atom.c @@ -1394,6 +1394,11 @@ static void atom_get_vbios_date(struct atom_context *ctx) p_rom = ctx->bios; + if (ctx->bios_size < OFFSET_TO_VBIOS_DATE + 14) { + ctx->date[0] = '\0'; + return; + } + date_in_rom = p_rom + OFFSET_TO_VBIOS_DATE; ctx->date[0] = '2'; @@ -1457,17 +1462,24 @@ static void atom_get_vbios_pn(struct atom_context *ctx) vbios_str = p_rom + OFFSET_TO_VBIOS_PART_NUMBER; } - if (*vbios_str == 0) { + if (vbios_str >= p_rom + ctx->bios_size) + vbios_str = NULL; + + if (vbios_str == NULL || *vbios_str == 0) { vbios_str = atom_find_str_in_rom(ctx, BIOS_ATOM_PREFIX, 3, 1024, 64); if (vbios_str == NULL) vbios_str += sizeof(BIOS_ATOM_PREFIX) - 1; + if (vbios_str >= p_rom + ctx->bios_size) + vbios_str = NULL; } if (vbios_str != NULL && *vbios_str == 0) vbios_str++; if (vbios_str != NULL) { count = 0; - while ((count < BIOS_STRING_LENGTH) && vbios_str[count] >= ' ' && + while ((count < BIOS_STRING_LENGTH) && + vbios_str + count < p_rom + ctx->bios_size && + vbios_str[count] >= ' ' && vbios_str[count] <= 'z') { ctx->vbios_pn[count] = vbios_str[count]; count++; @@ -1500,9 +1512,10 @@ static void atom_get_vbios_version(struct atom_context *ctx) /* find anchor ATOMBIOSBK-AMD */ vbios_ver = atom_find_str_in_rom(ctx, BIOS_VERSION_PREFIX, start, end, 64); - if (vbios_ver != NULL) { - /* skip ATOMBIOSBK-AMD VER */ - vbios_ver += 18; + if (vbios_ver != NULL) + vbios_ver += 18; /* skip ATOMBIOSBK-AMD VER */ + + if (vbios_ver != NULL && vbios_ver + STRLEN_NORMAL <= p_rom + ctx->bios_size) { memcpy(ctx->vbios_ver_str, vbios_ver, STRLEN_NORMAL); } else { ctx->vbios_ver_str[0] = '\0'; @@ -1518,7 +1531,13 @@ static void atom_get_vbios_build(struct atom_context *ctx) base = CU16(ATOM_ROM_TABLE_PTR); atom_rom_hdr = CSTR(base); + if ((uint32_t)base + ATOM_ROM_CFG_PTR + sizeof(uint16_t) > ctx->bios_size) + return; + str = CSTR(CU16(base + ATOM_ROM_CFG_PTR)); + if (str >= atom_rom_hdr) + return; + /* Skip config string */ while (str < atom_rom_hdr && *str++) ; -- 2.53.0