Skip to content

Commit

Permalink
drm/amdkfd: Correct mmu_notifier_get failure handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Philip Yang authored and Philip Yang committed Jul 27, 2022
1 parent c7b769b commit 09b42f2
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions drivers/gpu/drm/amd/amdkfd/kfd_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,12 @@ static struct kfd_process *create_process(const struct task_struct *thread)
(uintptr_t)process->mm);

#ifdef HAVE_MMU_NOTIFIER_PUT

/* 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
Expand All @@ -1492,6 +1498,8 @@ static struct kfd_process *create_process(const struct task_struct *thread)
goto err_register_notifier;
}
BUG_ON(mn != &process->mmu_notifier);

kfd_unref_process(process);
#else
/* Must be last, have to use release destruction after this */
process->mmu_notifier.ops = &kfd_process_mmu_notifier_ops;
Expand Down

0 comments on commit 09b42f2

Please sign in to comment.