Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2384167lqp; Sun, 24 Mar 2024 17:02:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWq1FVlR3isgacooVB3yO4NbGEeCHI9PJM0iRjgWgr2g9lXIPZcc8l7cYjh/8C4X62UYFiN1CdvNbNA9PXYPJNynFu2BXM9CVHNO2CM2w== X-Google-Smtp-Source: AGHT+IHzwi51IqXTmiX3hBT+Bnad/x1ShLDRdIQFiZlyIZtRRqklmdtQG6njVKUOCwxgDklonyME X-Received: by 2002:a50:c059:0:b0:568:9d31:2a75 with SMTP id u25-20020a50c059000000b005689d312a75mr4506118edd.4.1711324979322; Sun, 24 Mar 2024 17:02:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711324979; cv=pass; d=google.com; s=arc-20160816; b=ytZDGgRhlEBO9YwPbUA8VAWN3ZOKVUiogyywGl+J2AyjLzWaSzBOrFXG1EH6ai+Z04 /6fqxHJ+EK2iiLDZFnr0jvpHZ+ksNWKD0vUca7HN+v7PO4Sq6I+BjCnlwBZT1Dhzz0DP TH5Oh8Ylg53PXHZKq5ZQMWEOb849NETZ0CO2UXE/IXt87NY6rEGFDKylRMBLVxPdnfNe piNOmMKvmr+chokG5YOysxne2ToxdQup94eZW5vDSyh3zkvyPA+430YytpVttyzU1ZPr nBaOqo/CfXc+YTWoskqBuWq4Cie+gd1jdFyS2IQwZvcp40NUmExUJaCUlM5s5Kl13daV uOyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UjMJt3PDUv+9FQj3cGOAFe9iU6V86LkliqOPBT5opFg=; fh=Km9DkpWp5D2ROgr2VePmvEKzZ7SqvsYSbsrugXJonpY=; b=xMX3p5s2oWM85iebHKrC1jT99aW1zgDmrmenCvWDRi/3U/P9b8+9gF83iqSHvRUvZ+ 229Wc/O3OM0mgcUKovWVttZbCX49A5xaiv2I5zZc22ZuyXeOUMiCnK+WefR/4OVHkf9R rBxiS+YT66XtK16kqaoDXtC4HdbUU8FMCxTVwcByFDjgLa90cPiz90JYEqBhnN/B7/Yn N+YKiZBcByMcFsG0f7irDen4PHVB3FXIpSvsjaJIsCHlGtNT9fMhWNwLWKZA07NyY5Pt a5bZXW7i0w8CMZeQ23U/R91h24q31g61C6bMcygLsT74KEEDRlZHDKolmtJRn/q0gZnN oUPg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IRyxv8lW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113293-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113293-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w14-20020a056402268e00b0056bfca9a659si1572913edd.295.2024.03.24.17.02.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 17:02:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-113293-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=IRyxv8lW; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-113293-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-113293-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 13AA81F2220D for ; Mon, 25 Mar 2024 00:02:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D1BA26BFA9; Sun, 24 Mar 2024 22:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="IRyxv8lW" 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 E1CDE18EFA6; Sun, 24 Mar 2024 22:41:33 +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=1711320094; cv=none; b=DmwKD12U/vdQYXwQ/+buUuBF3YjBOgtIZF/sVpeYm2X4rVYVlmkjKpy8fU6lVgRto2Wrce08RQWbGe+fCJoPYkOrHqvMcINNfs8fi5T4t66WVkZWDQJm5y0dgMZnQ9IUdnjSHGvWQO045r5JO4r6iOxoWNkoLzRJIiO+7caei6c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711320094; c=relaxed/simple; bh=FeJ7rRD6Pl0PL3JQV059ZhHkAnbDL0udLtd1lvou/3w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G8xVZYaSAE9s1ZRzS0yrkujF21tqlnpFXaCEqclY+ESz37gfzX3iT5ys0wCIbvVmouLIi1ygG1kgBb2Zd9dlNdL+0/EuBa+5n2WWwACy1iYJTP8LC9ndEXs5vqkYz05Nt0SOyyuCt1SrX9B0D2REMmmgsrPvNPTrpP3LJvQ6xUw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IRyxv8lW; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED3EDC433C7; Sun, 24 Mar 2024 22:41:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1711320093; bh=FeJ7rRD6Pl0PL3JQV059ZhHkAnbDL0udLtd1lvou/3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IRyxv8lWTraWrzizgJSp2x2af/I01cMFYA0j3UZNsT0LOq+cN8MEC1fFE/JvXCyY/ 5HKM1yHf0SoxWacsmdVE4cXN85vRUX4XMYfGspvHmr8HcivUmX5Krde+WRgEoeoZXE A9dABchx8AluYJUrcq2b0iBOPfW2mNOFfNz5jEYILWUsNviV++FsZIL3lWlCce8ZX0 bjRG4Glau1kNNqaNOpJ7lfGU9h/KIuXnRFs8lmTGlgMyeZCEQ3J9pva0g9gFsrBfG2 90rmaV1F7k7KMz/6YAlDk3xW20KWx2C+mbU/KL2SZUBLWbKtJ/MZlNWUyR9i5FvpmT X7mjMYHUP7/dA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Srinivasan Shanmugam , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher , Sasha Levin Subject: [PATCH 6.8 402/715] drm/amdgpu: Fix potential out-of-bounds access in 'amdgpu_discovery_reg_base_init()' Date: Sun, 24 Mar 2024 18:29:41 -0400 Message-ID: <20240324223455.1342824-403-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240324223455.1342824-1-sashal@kernel.org> References: <20240324223455.1342824-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit From: Srinivasan Shanmugam [ Upstream commit cdb637d339572398821204a1142d8d615668f1e9 ] The issue arises when the array 'adev->vcn.vcn_config' is accessed before checking if the index 'adev->vcn.num_vcn_inst' is within the bounds of the array. The fix involves moving the bounds check before the array access. This ensures that 'adev->vcn.num_vcn_inst' is within the bounds of the array before it is used as an index. Fixes the below: drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1289 amdgpu_discovery_reg_base_init() error: testing array offset 'adev->vcn.num_vcn_inst' after use. Fixes: a0ccc717c4ab ("drm/amdgpu/discovery: validate VCN and SDMA instances") Cc: Christian König Cc: Alex Deucher Signed-off-by: Srinivasan Shanmugam Reviewed-by: Alex Deucher Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c index c7d60dd0fb975..4f9900779ef9e 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c @@ -1278,11 +1278,10 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) * 0b10 : encode is disabled * 0b01 : decode is disabled */ - adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = - ip->revision & 0xc0; - ip->revision &= ~0xc0; if (adev->vcn.num_vcn_inst < AMDGPU_MAX_VCN_INSTANCES) { + adev->vcn.vcn_config[adev->vcn.num_vcn_inst] = + ip->revision & 0xc0; adev->vcn.num_vcn_inst++; adev->vcn.inst_mask |= (1U << ip->instance_number); @@ -1293,6 +1292,7 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev) adev->vcn.num_vcn_inst + 1, AMDGPU_MAX_VCN_INSTANCES); } + ip->revision &= ~0xc0; } if (le16_to_cpu(ip->hw_id) == SDMA0_HWID || le16_to_cpu(ip->hw_id) == SDMA1_HWID || -- 2.43.0