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 5AC94C25B0C for ; Thu, 11 Aug 2022 16:10:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9435112B78B; Thu, 11 Aug 2022 16:10:37 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3CA1E14B21F; Thu, 11 Aug 2022 16:09:58 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AA09EB821A0; Thu, 11 Aug 2022 16:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D07C433C1; Thu, 11 Aug 2022 16:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234195; bh=yl0xHkcESV7NTyfRvJaAPC4xYMup5ytE1fDcH4xEmw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ongw9yAQVb5u0jTBYLcngSFPOZWOT/deZl8HLRfmURamJ2LnTxD5GBA0xpzZveHHy oSBMYfpb26DmKkdaquKfmJM7wbwo+S50nZqf3eynlG7rBLeowV4TrgtJHGmsuGMnLa 9DBR9XiAZNYiAa4s6TFtGdfc9IMQP1fBhQ37tHMZBbL6Bkr+rAyeGqhW2TdRjdFdpe LWnozOTUHya85nVW1p/npOQy1Dfv7mAUmdFBGn3sl+tdzxwDi7u78hh48BuJf2O1an qRRgz8BT/vdxuNZF9BQnRefzRd/bREX72bAyNsFSq4gtR/qDRcWwNK5H9tdPUOPhYN 7ToW733VzgFBg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 03/14] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Date: Thu, 11 Aug 2022 12:09:31 -0400 Message-Id: <20220811160948.1542842-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811160948.1542842-1-sashal@kernel.org> References: <20220811160948.1542842-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 , airlied@linux.ie, Xinhui.Pan@amd.com, amd-gfx@lists.freedesktop.org, Xiaohui Zhang , dri-devel@lists.freedesktop.org, daniel@ffwll.ch, Alex Deucher , christian.koenig@amd.com Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" From: Xiaohui Zhang [ Upstream commit 0381ac3ca2e727d4dfb7264d9416a8ba6bb6c18b ] Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8 ("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"), we thought a patch might be needed here as well. The entries were only initialized once in radeon_sa_bo_new. If a fence wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then got signalled before a later radeon_sa_bo_next_hole call, it could destroy the fence but leave its pointer in the array, resulting in use-after-free in radeon_sa_bo_new. Signed-off-by: Xiaohui Zhang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/radeon/radeon_sa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c index 197b157b73d0..0cb6eeb77b5f 100644 --- a/drivers/gpu/drm/radeon/radeon_sa.c +++ b/drivers/gpu/drm/radeon/radeon_sa.c @@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager, for (i = 0; i < RADEON_NUM_RINGS; ++i) { struct radeon_sa_bo *sa_bo; + fences[i] = NULL; + if (list_empty(&sa_manager->flist[i])) { continue; } @@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev, spin_lock(&sa_manager->wq.lock); do { - for (i = 0; i < RADEON_NUM_RINGS; ++i) { - fences[i] = NULL; + for (i = 0; i < RADEON_NUM_RINGS; ++i) tries[i] = 0; - } do { radeon_sa_bo_try_free(sa_manager); -- 2.35.1 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 74F1DC19F2A for ; Thu, 11 Aug 2022 16:32:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238492AbiHKQce (ORCPT ); Thu, 11 Aug 2022 12:32:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238792AbiHKQbN (ORCPT ); Thu, 11 Aug 2022 12:31:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FCA5B81F8; Thu, 11 Aug 2022 09:09:56 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 128A66141C; Thu, 11 Aug 2022 16:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D07C433C1; Thu, 11 Aug 2022 16:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234195; bh=yl0xHkcESV7NTyfRvJaAPC4xYMup5ytE1fDcH4xEmw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ongw9yAQVb5u0jTBYLcngSFPOZWOT/deZl8HLRfmURamJ2LnTxD5GBA0xpzZveHHy oSBMYfpb26DmKkdaquKfmJM7wbwo+S50nZqf3eynlG7rBLeowV4TrgtJHGmsuGMnLa 9DBR9XiAZNYiAa4s6TFtGdfc9IMQP1fBhQ37tHMZBbL6Bkr+rAyeGqhW2TdRjdFdpe LWnozOTUHya85nVW1p/npOQy1Dfv7mAUmdFBGn3sl+tdzxwDi7u78hh48BuJf2O1an qRRgz8BT/vdxuNZF9BQnRefzRd/bREX72bAyNsFSq4gtR/qDRcWwNK5H9tdPUOPhYN 7ToW733VzgFBg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Xiaohui Zhang , Alex Deucher , Sasha Levin , christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@linux.ie, daniel@ffwll.ch, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.19 03/14] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Date: Thu, 11 Aug 2022 12:09:31 -0400 Message-Id: <20220811160948.1542842-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811160948.1542842-1-sashal@kernel.org> References: <20220811160948.1542842-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiaohui Zhang [ Upstream commit 0381ac3ca2e727d4dfb7264d9416a8ba6bb6c18b ] Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8 ("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"), we thought a patch might be needed here as well. The entries were only initialized once in radeon_sa_bo_new. If a fence wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then got signalled before a later radeon_sa_bo_next_hole call, it could destroy the fence but leave its pointer in the array, resulting in use-after-free in radeon_sa_bo_new. Signed-off-by: Xiaohui Zhang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/radeon/radeon_sa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c index 197b157b73d0..0cb6eeb77b5f 100644 --- a/drivers/gpu/drm/radeon/radeon_sa.c +++ b/drivers/gpu/drm/radeon/radeon_sa.c @@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager, for (i = 0; i < RADEON_NUM_RINGS; ++i) { struct radeon_sa_bo *sa_bo; + fences[i] = NULL; + if (list_empty(&sa_manager->flist[i])) { continue; } @@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev, spin_lock(&sa_manager->wq.lock); do { - for (i = 0; i < RADEON_NUM_RINGS; ++i) { - fences[i] = NULL; + for (i = 0; i < RADEON_NUM_RINGS; ++i) tries[i] = 0; - } do { radeon_sa_bo_try_free(sa_manager); -- 2.35.1 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 5FEFEC19F2A for ; Thu, 11 Aug 2022 16:10:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E62C14B21F; Thu, 11 Aug 2022 16:10:34 +0000 (UTC) Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3CA1E14B21F; Thu, 11 Aug 2022 16:09:58 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id AA09EB821A0; Thu, 11 Aug 2022 16:09:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66D07C433C1; Thu, 11 Aug 2022 16:09:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234195; bh=yl0xHkcESV7NTyfRvJaAPC4xYMup5ytE1fDcH4xEmw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ongw9yAQVb5u0jTBYLcngSFPOZWOT/deZl8HLRfmURamJ2LnTxD5GBA0xpzZveHHy oSBMYfpb26DmKkdaquKfmJM7wbwo+S50nZqf3eynlG7rBLeowV4TrgtJHGmsuGMnLa 9DBR9XiAZNYiAa4s6TFtGdfc9IMQP1fBhQ37tHMZBbL6Bkr+rAyeGqhW2TdRjdFdpe LWnozOTUHya85nVW1p/npOQy1Dfv7mAUmdFBGn3sl+tdzxwDi7u78hh48BuJf2O1an qRRgz8BT/vdxuNZF9BQnRefzRd/bREX72bAyNsFSq4gtR/qDRcWwNK5H9tdPUOPhYN 7ToW733VzgFBg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 03/14] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Date: Thu, 11 Aug 2022 12:09:31 -0400 Message-Id: <20220811160948.1542842-3-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811160948.1542842-1-sashal@kernel.org> References: <20220811160948.1542842-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 , airlied@linux.ie, Xinhui.Pan@amd.com, amd-gfx@lists.freedesktop.org, Xiaohui Zhang , dri-devel@lists.freedesktop.org, Alex Deucher , christian.koenig@amd.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Xiaohui Zhang [ Upstream commit 0381ac3ca2e727d4dfb7264d9416a8ba6bb6c18b ] Similar to the handling of amdgpu_sa_bo_next_hole in commit 6a15f3ff19a8 ("drm/amdgpu: Initialize fences array entries in amdgpu_sa_bo_next_hole"), we thought a patch might be needed here as well. The entries were only initialized once in radeon_sa_bo_new. If a fence wasn't signalled yet in the first radeon_sa_bo_next_hole call, but then got signalled before a later radeon_sa_bo_next_hole call, it could destroy the fence but leave its pointer in the array, resulting in use-after-free in radeon_sa_bo_new. Signed-off-by: Xiaohui Zhang Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/radeon/radeon_sa.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_sa.c b/drivers/gpu/drm/radeon/radeon_sa.c index 197b157b73d0..0cb6eeb77b5f 100644 --- a/drivers/gpu/drm/radeon/radeon_sa.c +++ b/drivers/gpu/drm/radeon/radeon_sa.c @@ -267,6 +267,8 @@ static bool radeon_sa_bo_next_hole(struct radeon_sa_manager *sa_manager, for (i = 0; i < RADEON_NUM_RINGS; ++i) { struct radeon_sa_bo *sa_bo; + fences[i] = NULL; + if (list_empty(&sa_manager->flist[i])) { continue; } @@ -332,10 +334,8 @@ int radeon_sa_bo_new(struct radeon_device *rdev, spin_lock(&sa_manager->wq.lock); do { - for (i = 0; i < RADEON_NUM_RINGS; ++i) { - fences[i] = NULL; + for (i = 0; i < RADEON_NUM_RINGS; ++i) tries[i] = 0; - } do { radeon_sa_bo_try_free(sa_manager); -- 2.35.1