AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Sasha Levin <sashal@kernel.org>,
	Philip Yang <Philip.Yang@amd.com>,
	airlied@linux.ie, Felix Kuehling <Felix.Kuehling@amd.com>,
	Xinhui.Pan@amd.com, amd-gfx@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org, daniel@ffwll.ch,
	Alex Deucher <alexander.deucher@amd.com>,
	christian.koenig@amd.com
Subject: [PATCH AUTOSEL 5.19 091/105] drm/amdkfd: Correct mmu_notifier_get failure handling
Date: Thu, 11 Aug 2022 11:28:15 -0400	[thread overview]
Message-ID: <20220811152851.1520029-91-sashal@kernel.org> (raw)
In-Reply-To: <20220811152851.1520029-1-sashal@kernel.org>

From: Philip Yang <Philip.Yang@amd.com>

[ Upstream commit 0593ad215359d51514c1e6c81ce28ea598efed6b ]

If process has signal pending, mmu_notifier_get_locked fails and calls
ops->free_notifier, kfd_process_free_notifier will schedule
kfd_process_wq_release as process refcount is 1, but process structure
is already freed. This use after free bug causes system crash with
different backtrace.

The fix is to increase process refcount and then decrease the refcount
after mmu_notifier_get success.

Signed-off-by: Philip Yang <Philip.Yang@amd.com>
Reviewed-by: Felix Kuehling <Felix.Kuehling@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/amd/amdkfd/kfd_process.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
index e3d64ec8c353..b8b185e242d3 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
@@ -1404,6 +1404,11 @@ static struct kfd_process *create_process(const struct task_struct *thread)
 	hash_add_rcu(kfd_processes_table, &process->kfd_processes,
 			(uintptr_t)process->mm);
 
+	/* Avoid free_notifier to start kfd_process_wq_release if
+	 * mmu_notifier_get failed because of pending signal.
+	 */
+	kref_get(&process->ref);
+
 	/* MMU notifier registration must be the last call that can fail
 	 * because after this point we cannot unwind the process creation.
 	 * After this point, mmu_notifier_put will trigger the cleanup by
@@ -1416,6 +1421,7 @@ static struct kfd_process *create_process(const struct task_struct *thread)
 	}
 	BUG_ON(mn != &process->mmu_notifier);
 
+	kfd_unref_process(process);
 	get_task_struct(process->lead_thread);
 
 	return process;
-- 
2.35.1


  parent reply	other threads:[~2022-08-11 15:41 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20220811152851.1520029-1-sashal@kernel.org>
2022-08-11 15:26 ` [PATCH AUTOSEL 5.19 011/105] drm/amd/display: fix system hang when PSR exits Sasha Levin
2022-08-11 15:26 ` [PATCH AUTOSEL 5.19 012/105] drm/amd/display: Detect dpcd_rev when hotplug mst monitor Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 016/105] drm/amd/display: Correct min comp buffer size Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 017/105] drm/amd/display: Fix dpp dto for disabled pipes Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 018/105] drm/amd/display: Reduce frame size in the bouding box for DCN20 Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 019/105] drm/radeon: integer overflow in radeon_mode_dumb_create() Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 020/105] drm/radeon: Initialize fences array entries in radeon_sa_bo_next_hole Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 025/105] drm/amd/display: Fix monitor flash issue Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 044/105] drm/amdkfd: Free queue after unmap queue success Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 045/105] amdgpu/pm: Fix possible array out-of-bounds if SCLK levels != 2 Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 052/105] drm/amdgpu/display/dc: Fix null pointer exception Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 057/105] drm/amdgpu: skip whole ras bad page framework on sriov Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 058/105] drm/amd/display: Guard against ddc_pin being NULL for AUX Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 059/105] drm/amd/display: Fix dmub soft hang for PSR 1 Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 060/105] drm/amd/display: disable otg toggle w/a on boot Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 064/105] drm/amdgpu: Fix one list corruption when create queue fails Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 070/105] drm/amdgpu: fix file permissions on some files Sasha Levin
2022-08-11 15:27 ` [PATCH AUTOSEL 5.19 075/105] drm/amdgpu: Call trace info was found in dmesg when loading amdgpu Sasha Levin
2022-08-11 15:28 ` Sasha Levin [this message]
2022-08-11 15:28 ` [PATCH AUTOSEL 5.19 092/105] drm/amdkfd: Process notifier release callback don't take mutex Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220811152851.1520029-91-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=Felix.Kuehling@amd.com \
    --cc=Philip.Yang@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@linux.ie \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox