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 DF651C10F1E for ; Sun, 18 Dec 2022 16:15:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231635AbiLRQPR (ORCPT ); Sun, 18 Dec 2022 11:15:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbiLRQOl (ORCPT ); Sun, 18 Dec 2022 11:14:41 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A27C1BC15; Sun, 18 Dec 2022 08:06:27 -0800 (PST) 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 238D9B80B4D; Sun, 18 Dec 2022 16:06:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9BBFC433D2; Sun, 18 Dec 2022 16:06:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671379573; bh=1aIuIkEBkra234fdZs9njiL/A7ZhiKe0gzh1gZzzi3g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GZ2aGppMPLLMRzkfWNB/JvBvNbNxChjYU1GzLHZvoHvLEo4Ja4ogcwWkdx9aH1LT/ XJVQM57ghIqlr9qgffF1KCbt8rxmHvEElGTOtLeyOrYwwPH7PjTBTyT+qdQKOQZ+lj 8LA+a1Wu5fBJ/0xVXu1vTgpFUThTaIDvTSzvMgBDOvHQEzxGm9OvLSHIB9ryajxcLk r2t8NPnIS3g16gAywn3eWNOtYGCvnUPw1ru2OqNPpFbUM+4c3n9l0HBne1Bp/fDXds vMGpDl6iKGHHtv8X+TiSw7+Dr4Vo8/g1lpBvOyZ5qQRn9ddQcdmcXLwIauKCu6TfeJ SUHfYt9IBN4MQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Liang He , Luben Tuikov , Alex Deucher , Sasha Levin , christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, andrey.grodzovsky@amd.com, Hawking.Zhang@amd.com, evan.quan@amd.com, YiPeng.Chai@amd.com, Amaranath.Somalapuram@amd.com, Bokun.Zhang@amd.com, tao.zhou1@amd.com, shaoyun.liu@amd.com, yang.lee@linux.alibaba.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.1 64/85] drm/amdgpu: Fix potential double free and null pointer dereference Date: Sun, 18 Dec 2022 11:01:21 -0500 Message-Id: <20221218160142.925394-64-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221218160142.925394-1-sashal@kernel.org> References: <20221218160142.925394-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: linux-kernel@vger.kernel.org From: Liang He [ Upstream commit dfd0287bd3920e132a8dae2a0ec3d92eaff5f2dd ] In amdgpu_get_xgmi_hive(), we should not call kfree() after kobject_put() as the PUT will call kfree(). In amdgpu_device_ip_init(), we need to check the returned *hive* which can be NULL before we dereference it. Signed-off-by: Liang He Reviewed-by: Luben Tuikov Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 5 +++++ drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c index f1e9663b4051..00976e15b698 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c @@ -2462,6 +2462,11 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev) if (!amdgpu_sriov_vf(adev)) { struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev); + if (WARN_ON(!hive)) { + r = -ENOENT; + goto init_failed; + } + if (!hive->reset_domain || !amdgpu_reset_get_reset_domain(hive->reset_domain)) { r = -ENOENT; diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c index 47159e9a0884..4b9e7b050ccd 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c @@ -386,7 +386,6 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) if (ret) { dev_err(adev->dev, "XGMI: failed initializing kobject for xgmi hive\n"); kobject_put(&hive->kobj); - kfree(hive); hive = NULL; goto pro_end; } @@ -410,7 +409,6 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev) dev_err(adev->dev, "XGMI: failed initializing reset domain for xgmi hive\n"); ret = -ENOMEM; kobject_put(&hive->kobj); - kfree(hive); hive = NULL; goto pro_end; } -- 2.35.1