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 1ADAAC001DC for ; Mon, 24 Jul 2023 01:34:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2D95210E25F; Mon, 24 Jul 2023 01:34:24 +0000 (UTC) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by gabe.freedesktop.org (Postfix) with ESMTPS id CA4D010E25E; Mon, 24 Jul 2023 01:34:21 +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 4D44361022; Mon, 24 Jul 2023 01:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 254D6C433CA; Mon, 24 Jul 2023 01:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162461; bh=iZ093k6Yg0oFMHjViAgdjD2YR5rBaGNxrm1Yb6Czur4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyzNZ0WLKtHgSd9bsowY//n6w6XOv6+ar35LICdmGBeeGDfYAaPtSWV/sfWXRwEaE fmRsLdzVvSO8rmrEEFDbr8eCVilRHB3YRQ7U4Efak552JxsteOpBL4lnbnoKXepEh9 g3bXhNTmZWV20viWQGi5SwapeAy9xbDHEWllNvOF4kc0IljM1WXiB9X8nAWaTAaIeX xAzQKiRNOJjPBNhTRspOdVS726yrmI7zFIpNYj0Zgo2LrsySrhsEev+3iSX3JGKVsf YBGf5lcO9tbjv3eM9lz6CYhzoneJ08kHRIIJG+cZWzJaED9DRLJpzNVrw5Mftah/zH iGsjJQ0W8J6sw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 13/16] drm/amdgpu: Fix potential fence use-after-free v2 Date: Sun, 23 Jul 2023 21:33:57 -0400 Message-Id: <20230724013401.2333159-13-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013401.2333159-1-sashal@kernel.org> References: <20230724013401.2333159-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.10.186 Content-Transfer-Encoding: 8bit X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx 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: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" 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 ffd8f5601e28a..e25c3387bcf87 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1517,15 +1517,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 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 230F3C001DC for ; Mon, 24 Jul 2023 01:46:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232664AbjGXBqg (ORCPT ); Sun, 23 Jul 2023 21:46:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232456AbjGXBot (ORCPT ); Sun, 23 Jul 2023 21:44:49 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39D065FC2; Sun, 23 Jul 2023 18:39:08 -0700 (PDT) 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 AE9E761040; Mon, 24 Jul 2023 01:34:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 254D6C433CA; Mon, 24 Jul 2023 01:34:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1690162461; bh=iZ093k6Yg0oFMHjViAgdjD2YR5rBaGNxrm1Yb6Czur4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UyzNZ0WLKtHgSd9bsowY//n6w6XOv6+ar35LICdmGBeeGDfYAaPtSWV/sfWXRwEaE fmRsLdzVvSO8rmrEEFDbr8eCVilRHB3YRQ7U4Efak552JxsteOpBL4lnbnoKXepEh9 g3bXhNTmZWV20viWQGi5SwapeAy9xbDHEWllNvOF4kc0IljM1WXiB9X8nAWaTAaIeX xAzQKiRNOJjPBNhTRspOdVS726yrmI7zFIpNYj0Zgo2LrsySrhsEev+3iSX3JGKVsf YBGf5lcO9tbjv3eM9lz6CYhzoneJ08kHRIIJG+cZWzJaED9DRLJpzNVrw5Mftah/zH iGsjJQ0W8J6sw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: shanzhulig , =?UTF-8?q?Christian=20K=C3=B6nig?= , Alex Deucher , Sasha Levin , airlied@linux.ie, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 5.10 13/16] drm/amdgpu: Fix potential fence use-after-free v2 Date: Sun, 23 Jul 2023 21:33:57 -0400 Message-Id: <20230724013401.2333159-13-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230724013401.2333159-1-sashal@kernel.org> References: <20230724013401.2333159-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.10.186 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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 ffd8f5601e28a..e25c3387bcf87 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c @@ -1517,15 +1517,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