From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1E04C001B0 for ; Mon, 24 Jul 2023 01:35:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6631D10E260; Mon, 24 Jul 2023 01:35:42 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC9E010E260; Mon, 24 Jul 2023 01:35:40 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C14560DFE; Mon, 24 Jul 2023 01:35:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3CBBC433C7; Mon, 24 Jul 2023 01:35:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162539; bh=3b5m24aNDedcg8G6NTX+DMnLf9Y2l++WmDBaV7lwolk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i6qXjPz3GL85YHGazFej+LQUucxKZ+N7/t2B6OTRo+R+TfgQ91FalsiyNJA8GqJqZ Tk1ywWh16SqGqglciE+SUzU5NeXf8HnUFRu1ZHKrcaFDP1GCkEP10kUm1+YErfGynr E3/wFMi2Wql5YIcz59DBblw6YB6BPzim+RA/Ld8zMz24ikEpED3ufrJ31w+l436mNV lS++bHfgE3SQb4JB8IqXhi4MsQrh4P4pntSVxtbIDs+ShFy6mPU696g+vRtyFE4AO0 bjR/LUuC8ZZI6Xwf4ck1rG/QTQCdgk9dTm7sYWwiCGDScSNxmKrPqLdXz2BDefhbdm 7CtmDgt0rbvpg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 9/9] drm/amdgpu: Fix potential fence use-after-free v2 Date: Sun, 23 Jul 2023 21:34:45 -0400 Message-Id: <20230724013445.2334326-9-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013445.2334326-1-sashal@kernel.org> References: <20230724013445.2334326-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.288 Content-Transfer-Encoding: 8bit X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , shanzhulig , airlied@linux.ie, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Alex Deucher , =?UTF-8?q?Christian=20K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: shanzhulig [ Upstream commit 2e54154b9f27262efd0cb4f903cc7d5ad1fe9628 ] fence Decrements the reference count before exiting. Avoid Race Vulnerabilities for fence use-after-free. v2 (chk): actually fix the use after free and not just move it. Signed-off-by: shanzhulig Signed-off-by: Christian König Reviewed-by: Alex Deucher Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index e667bcf64bc7f..70e446c2acf82 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1502,15 +1502,15 @@ static int amdgpu_cs_wait_all_fences(struct amdgpu_device *adev, continue; r = dma_fence_wait_timeout(fence, true, timeout); + if (r > 0 && fence->error) + r = fence->error; + dma_fence_put(fence); if (r < 0) return r; if (r == 0) break; - - if (fence->error) - return fence->error; } memset(wait, 0, sizeof(*wait)); -- 2.39.2