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 57259C001DC for ; Mon, 24 Jul 2023 01:37:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CD3B010E263; Mon, 24 Jul 2023 01:37:12 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id D4B8B10E263; Mon, 24 Jul 2023 01:37:11 +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 5CA5F60FC8; Mon, 24 Jul 2023 01:37:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04AE7C433CB; Mon, 24 Jul 2023 01:37:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162631; bh=UJvsFIkKAOURJ83ZQboQ8+scf1xnUpxiqgB4HHDgtHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IMgtGyrlrxQCZgL3BGD2BzQlSn2/MX0BYcx05tKwyjGRcoik7kn378X3lm5bIQa28 Rgk2C2Z6L+SAHWabOxyYDnFqG5n14LrQ/ynksNnWNMZE8JZrgJ72/OKBmcXBnQCmBG yc+4lrSLL7mWpu3mpoBNRNai0g9Ov4xCy+a3HUXv62X2pZgRxbRNYhwWOJEgdp7W1o Xs+5l9IkBESulnvzUcni07RYwKLLtwSWYqpYgR3pydd6zh8OlCZ1JKnu71uGCAd8jK 0qUL/AJ3Qk0wQpKsb5S3jf5M7DjkSD8MoM43wVjac22S0604ssu0xm5Ht9fzbb0ZZI TO5XGtqVgDpFQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 9/9] drm/amdgpu: Fix potential fence use-after-free v2 Date: Sun, 23 Jul 2023 21:35:51 -0400 Message-Id: <20230724013554.2334965-9-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013554.2334965-1-sashal@kernel.org> References: <20230724013554.2334965-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.14.320 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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c index 8a8b65b1b5a9a..7bad519aaae08 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1343,6 +1343,9 @@ 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; -- 2.39.2