From mboxrd@z Thu Jan 1 00:00:00 1970 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 C62F83FBB42; Fri, 15 May 2026 16:22:55 +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=1778862175; cv=none; b=dO3CwOQ+2yJWH+nXi/ubcsYm1nU9+4bZRUIjqPSQiDgC7j/e7/8Qt2P33BvBdZgswOqupGaxortMmOO0z0PcKb8+uGpPt54yL24+T4fzw5XePmq/xz3Vgc4NYlTLpJTH4yPBZ3pGqihlt9dw8BFYODghztbLMNAwDZjbsBDUHTY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778862175; c=relaxed/simple; bh=RAFVEUbxjhCJbMEWRreHx/A/AdPSBbQ1556TNF/QHuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VOP8YBqRoNoB4rIC58OJFUFZZYZ41Yyda1Dkm8T+VhBkzqicQtW9pk4Avb1u5WuNcrudayFB2eRl72LGf6itPr9LXlJVH1zWOom/Ec9SIoFS6Xd3eVEgqlFLljVJ+YNVb1/C6OIgTbiD0IZ08Qjv+rkBkBtVCk56kwBIuhBlBk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=KJ2tFCc1; 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="KJ2tFCc1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51F92C2BCB0; Fri, 15 May 2026 16:22:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778862175; bh=RAFVEUbxjhCJbMEWRreHx/A/AdPSBbQ1556TNF/QHuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJ2tFCc1kstEd6WM8ek6Fc0BvzyQNg9PNKkwKUv7VQxhPN+qONa48yWhxjLMiaEXS /dXLOZLM7FDq8Vsl7PEUBCbK9X9feJp17kEkP0MG6KzRRjl2QAt5Zs2W8VWuQkbSQO V36Cgwag1m2LfzvejyHcslR8V3Pk2malHrrwNGqw= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Benjamin Cheng , =?UTF-8?q?Christian=20K=C3=B6nig?= , Ruijing Dong , Alex Deucher Subject: [PATCH 6.18 110/188] drm/amdgpu/vcn3: Prevent OOB reads when parsing dec msg Date: Fri, 15 May 2026 17:48:47 +0200 Message-ID: <20260515154659.715401207@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260515154657.309489048@linuxfoundation.org> References: <20260515154657.309489048@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Cheng commit b193019860d61e92da395eae2011f2f6716b182f upstream. Check bounds against the end of the BO whenever we access the msg. Signed-off-by: Benjamin Cheng Reviewed-by: Christian König Reviewed-by: Ruijing Dong Signed-off-by: Alex Deucher Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) --- a/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c +++ b/drivers/gpu/drm/amd/amdgpu/vcn_v3_0.c @@ -1908,7 +1908,7 @@ static int vcn_v3_0_dec_msg(struct amdgp { struct ttm_operation_ctx ctx = { false, false }; struct amdgpu_bo_va_mapping *map; - uint32_t *msg, num_buffers; + uint32_t *msg, num_buffers, len_dw; struct amdgpu_bo *bo; uint64_t start, end; unsigned int i; @@ -1929,6 +1929,11 @@ static int vcn_v3_0_dec_msg(struct amdgp return -EINVAL; } + if (end - addr < 16) { + DRM_ERROR("VCN messages must be at least 4 DWORDs!\n"); + return -EINVAL; + } + bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; amdgpu_bo_placement_from_domain(bo, bo->allowed_domains); r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx); @@ -1945,8 +1950,8 @@ static int vcn_v3_0_dec_msg(struct amdgp msg = ptr + addr - start; - /* Check length */ if (msg[1] > end - addr) { + DRM_ERROR("VCN message header does not fit in BO!\n"); r = -EINVAL; goto out; } @@ -1954,7 +1959,16 @@ static int vcn_v3_0_dec_msg(struct amdgp if (msg[3] != RDECODE_MSG_CREATE) goto out; + len_dw = msg[1] / 4; num_buffers = msg[2]; + + /* Verify that all indices fit within the claimed length. Each index is 4 DWORDs */ + if (num_buffers > len_dw || 6 + num_buffers * 4 > len_dw) { + DRM_ERROR("VCN message has too many buffers!\n"); + r = -EINVAL; + goto out; + } + for (i = 0, msg = &msg[6]; i < num_buffers; ++i, msg += 4) { uint32_t offset, size, *create; @@ -1964,14 +1978,15 @@ static int vcn_v3_0_dec_msg(struct amdgp offset = msg[1]; size = msg[2]; - if (offset + size > end) { + if (size < 4 || offset + size > end - addr) { + DRM_ERROR("VCN message buffer exceeds BO bounds!\n"); r = -EINVAL; goto out; } create = ptr + addr + offset - start; - /* H246, HEVC and VP9 can run on any instance */ + /* H264, HEVC and VP9 can run on any instance */ if (create[0] == 0x7 || create[0] == 0x10 || create[0] == 0x11) continue;