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 C91CFC19F2A for ; Thu, 11 Aug 2022 16:12:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3212C11A0A4; Thu, 11 Aug 2022 16:12:04 +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 EC78C14B181; Thu, 11 Aug 2022 16:11:51 +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 72611B821AC; Thu, 11 Aug 2022 16:11:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E156C433D7; Thu, 11 Aug 2022 16:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234309; bh=yl0xHkcESV7NTyfRvJaAPC4xYMup5ytE1fDcH4xEmw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4rR0LoC+AvxVYQLikjFdqDeSbDtu0PghQP+wXEIjWknEZcQUM/RweaGT3xjal0+x mlNKhEM+2ZYMiwhhhy1wmpi1mPHwUI+OSrQaXGA1fK87+KpWxEJKAKBSWthBI9oOc3 lv0X9QSS4zlH1085F9xalcAE/JqlngN+ZQymD5UotfyWXQtKZbtdI/QcR6F6Cu2zUN ++b8UYW1rxXk2zKNdBS2YqkmaQi8hwrZFo6TcFpGomcXLQtfemULJ+NrwwIAgo2pJg X/QNqsE1KYTJgFhfBsjk/FxIQfjqjKpDgt4Juv/S6gulEwLwMHIiN8qGA97lN9W+bm HCAuT7ABZib0Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 02/12] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Date: Thu, 11 Aug 2022 12:11:28 -0400 Message-Id: <20220811161144.1543598-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811161144.1543598-1-sashal@kernel.org> References: <20220811161144.1543598-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 9D232C19F2A for ; Thu, 11 Aug 2022 16:37:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238878AbiHKQhl (ORCPT ); Thu, 11 Aug 2022 12:37:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239199AbiHKQga (ORCPT ); Thu, 11 Aug 2022 12:36:30 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09F398981C; Thu, 11 Aug 2022 09:11:51 -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 ams.source.kernel.org (Postfix) with ESMTPS id 8A571B821AD; Thu, 11 Aug 2022 16:11:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E156C433D7; Thu, 11 Aug 2022 16:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234309; bh=yl0xHkcESV7NTyfRvJaAPC4xYMup5ytE1fDcH4xEmw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4rR0LoC+AvxVYQLikjFdqDeSbDtu0PghQP+wXEIjWknEZcQUM/RweaGT3xjal0+x mlNKhEM+2ZYMiwhhhy1wmpi1mPHwUI+OSrQaXGA1fK87+KpWxEJKAKBSWthBI9oOc3 lv0X9QSS4zlH1085F9xalcAE/JqlngN+ZQymD5UotfyWXQtKZbtdI/QcR6F6Cu2zUN ++b8UYW1rxXk2zKNdBS2YqkmaQi8hwrZFo6TcFpGomcXLQtfemULJ+NrwwIAgo2pJg X/QNqsE1KYTJgFhfBsjk/FxIQfjqjKpDgt4Juv/S6gulEwLwMHIiN8qGA97lN9W+bm HCAuT7ABZib0Q== 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.9 02/12] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Date: Thu, 11 Aug 2022 12:11:28 -0400 Message-Id: <20220811161144.1543598-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811161144.1543598-1-sashal@kernel.org> References: <20220811161144.1543598-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 79472C19F2A for ; Thu, 11 Aug 2022 16:12:36 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A673014AD18; Thu, 11 Aug 2022 16:12:16 +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 EC78C14B181; Thu, 11 Aug 2022 16:11:51 +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 72611B821AC; Thu, 11 Aug 2022 16:11:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E156C433D7; Thu, 11 Aug 2022 16:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660234309; bh=yl0xHkcESV7NTyfRvJaAPC4xYMup5ytE1fDcH4xEmw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m4rR0LoC+AvxVYQLikjFdqDeSbDtu0PghQP+wXEIjWknEZcQUM/RweaGT3xjal0+x mlNKhEM+2ZYMiwhhhy1wmpi1mPHwUI+OSrQaXGA1fK87+KpWxEJKAKBSWthBI9oOc3 lv0X9QSS4zlH1085F9xalcAE/JqlngN+ZQymD5UotfyWXQtKZbtdI/QcR6F6Cu2zUN ++b8UYW1rxXk2zKNdBS2YqkmaQi8hwrZFo6TcFpGomcXLQtfemULJ+NrwwIAgo2pJg X/QNqsE1KYTJgFhfBsjk/FxIQfjqjKpDgt4Juv/S6gulEwLwMHIiN8qGA97lN9W+bm HCAuT7ABZib0Q== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: [PATCH AUTOSEL 4.9 02/12] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Date: Thu, 11 Aug 2022 12:11:28 -0400 Message-Id: <20220811161144.1543598-2-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220811161144.1543598-1-sashal@kernel.org> References: <20220811161144.1543598-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