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 3BE81C001B0 for ; Mon, 24 Jul 2023 01:33:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 787B610E25D; Mon, 24 Jul 2023 01:33:54 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0D1CB10E25C; Mon, 24 Jul 2023 01:33:52 +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 8528B61003; Mon, 24 Jul 2023 01:33:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F331FC433C7; Mon, 24 Jul 2023 01:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162430; bh=j/inPhAJbq/AI9Jk+HeW4401HKZVfSwN8Xb4vFhq9iE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=huobI+SKnPLd3MoBsytz8XNvljnOQmfQt4FZJp6uBZWZO3Ej1zV5AfOtc3XAPevkv ldZ7yrYK/cLLoLV7r80qtjCjwH8fNcKMqia0e3cRiZQe+DoUETxPXrPRfME24fJcV4 3zMwm5bSmVk45N4VwZ+bMvChucbnL0wKXmmbY5rAf9kcc69G8oAnqWvj0Ej4E/LO3a ALMTKXz8Ogwz9vhg59cO8M1yCR37yXG/O8T2U4rJx1JwAV6nkF3vKfhpBdl64Z0el+ +S8PBEjArhk7PUtl2WklN+VZ66N2znBPr8y2pqw+EF7VI85gvVIFEo30QHyxAFEMz+ PUWax3jsH2Dqw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.15 17/24] drm/amdgpu: Fix potential fence use-after-free v2 Date: Sun, 23 Jul 2023 21:33:18 -0400 Message-Id: <20230724013325.2332084-17-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013325.2332084-1-sashal@kernel.org> References: <20230724013325.2332084-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 5.15.121 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 2fd4d8ad7e40d..4b01188385b28 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1541,15 +1541,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