mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH V1] accel/amdxdna: Fix potential amdxdna_umap lifetime race
@ 2026-07-06 22:12 Lizhi Hou
  2026-07-07 15:35 ` Max Zhen
  0 siblings, 1 reply; 3+ messages in thread
From: Lizhi Hou @ 2026-07-06 22:12 UTC (permalink / raw)
  To: ogabbay, quic_jhugo, dri-devel, mario.limonciello, karol.wachowski
  Cc: Lizhi Hou, linux-kernel, max.zhen, sonal.santan

amdxdna_umap_release() calls the blocking mmu_interval_notifier_remove()
before removing the object from abo->mem.umap_list. If
aie2_populate_range() runs concurrently, it may obtain a reference to an
amdxdna_umap that is being released, leading to a potential use-after-free.

Use refcount_inc_not_zero() in aie2_populate_range() when acquiring a
reference. If the reference count has already dropped to zero, release
is in progress and the entry is skipped.

Fixes: e486147c912f ("accel/amdxdna: Add BO import and export")
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
---
 drivers/accel/amdxdna/aie2_ctx.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
index 408ff7e2a272..7bf635634e64 100644
--- a/drivers/accel/amdxdna/aie2_ctx.c
+++ b/drivers/accel/amdxdna/aie2_ctx.c
@@ -1039,7 +1039,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo)
 	found = false;
 	down_write(&xdna->notifier_lock);
 	list_for_each_entry(mapp, &abo->mem.umap_list, node) {
-		if (mapp->invalid) {
+		if (mapp->invalid && kref_get_unless_zero(&mapp->refcnt)) {
 			found = true;
 			break;
 		}
@@ -1050,7 +1050,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo)
 		up_write(&xdna->notifier_lock);
 		return 0;
 	}
-	kref_get(&mapp->refcnt);
+
 	up_write(&xdna->notifier_lock);
 
 	mm = mapp->notifier.mm;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V1] accel/amdxdna: Fix potential amdxdna_umap lifetime race
  2026-07-06 22:12 [PATCH V1] accel/amdxdna: Fix potential amdxdna_umap lifetime race Lizhi Hou
@ 2026-07-07 15:35 ` Max Zhen
  2026-07-07 17:13   ` Lizhi Hou
  0 siblings, 1 reply; 3+ messages in thread
From: Max Zhen @ 2026-07-07 15:35 UTC (permalink / raw)
  To: Lizhi Hou, ogabbay, quic_jhugo, dri-devel, mario.limonciello,
	karol.wachowski
  Cc: linux-kernel, sonal.santan



On 7/6/2026 Mon 15:12, Lizhi Hou wrote:
> amdxdna_umap_release() calls the blocking mmu_interval_notifier_remove()
> before removing the object from abo->mem.umap_list. If
> aie2_populate_range() runs concurrently, it may obtain a reference to an
> amdxdna_umap that is being released, leading to a potential use-after-free.
> 
> Use refcount_inc_not_zero() in aie2_populate_range() when acquiring a
> reference. If the reference count has already dropped to zero, release
> is in progress and the entry is skipped.
> 
> Fixes: e486147c912f ("accel/amdxdna: Add BO import and export")
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Max Zhen <max.zhen@amd.com>

The patch description mentioned refcount_inc_not_zero(), but the real 
fix calls kref_get_unless_zero() which is a wrapper of 
refcount_inc_not_zero(). It might be better to fix the description to 
match the fix in the code.

Thanks,
Max
> ---
>   drivers/accel/amdxdna/aie2_ctx.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/accel/amdxdna/aie2_ctx.c b/drivers/accel/amdxdna/aie2_ctx.c
> index 408ff7e2a272..7bf635634e64 100644
> --- a/drivers/accel/amdxdna/aie2_ctx.c
> +++ b/drivers/accel/amdxdna/aie2_ctx.c
> @@ -1039,7 +1039,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo)
>   	found = false;
>   	down_write(&xdna->notifier_lock);
>   	list_for_each_entry(mapp, &abo->mem.umap_list, node) {
> -		if (mapp->invalid) {
> +		if (mapp->invalid && kref_get_unless_zero(&mapp->refcnt)) {
>   			found = true;
>   			break;
>   		}
> @@ -1050,7 +1050,7 @@ static int aie2_populate_range(struct amdxdna_gem_obj *abo)
>   		up_write(&xdna->notifier_lock);
>   		return 0;
>   	}
> -	kref_get(&mapp->refcnt);
> +
>   	up_write(&xdna->notifier_lock);
>   
>   	mm = mapp->notifier.mm;


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH V1] accel/amdxdna: Fix potential amdxdna_umap lifetime race
  2026-07-07 15:35 ` Max Zhen
@ 2026-07-07 17:13   ` Lizhi Hou
  0 siblings, 0 replies; 3+ messages in thread
From: Lizhi Hou @ 2026-07-07 17:13 UTC (permalink / raw)
  To: Max Zhen, ogabbay, quic_jhugo, dri-devel, mario.limonciello,
	karol.wachowski
  Cc: linux-kernel, sonal.santan

Applied to drm-misc-fixes

On 7/7/26 08:35, Max Zhen wrote:
>
>
> On 7/6/2026 Mon 15:12, Lizhi Hou wrote:
>> amdxdna_umap_release() calls the blocking mmu_interval_notifier_remove()
>> before removing the object from abo->mem.umap_list. If
>> aie2_populate_range() runs concurrently, it may obtain a reference to an
>> amdxdna_umap that is being released, leading to a potential 
>> use-after-free.
>>
>> Use refcount_inc_not_zero() in aie2_populate_range() when acquiring a
>> reference. If the reference count has already dropped to zero, release
>> is in progress and the entry is skipped.
>>
>> Fixes: e486147c912f ("accel/amdxdna: Add BO import and export")
>> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
> Reviewed-by: Max Zhen <max.zhen@amd.com>
>
> The patch description mentioned refcount_inc_not_zero(), but the real 
> fix calls kref_get_unless_zero() which is a wrapper of 
> refcount_inc_not_zero(). It might be better to fix the description to 
> match the fix in the code.
>
> Thanks,
> Max
>> ---
>>   drivers/accel/amdxdna/aie2_ctx.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/accel/amdxdna/aie2_ctx.c 
>> b/drivers/accel/amdxdna/aie2_ctx.c
>> index 408ff7e2a272..7bf635634e64 100644
>> --- a/drivers/accel/amdxdna/aie2_ctx.c
>> +++ b/drivers/accel/amdxdna/aie2_ctx.c
>> @@ -1039,7 +1039,7 @@ static int aie2_populate_range(struct 
>> amdxdna_gem_obj *abo)
>>       found = false;
>>       down_write(&xdna->notifier_lock);
>>       list_for_each_entry(mapp, &abo->mem.umap_list, node) {
>> -        if (mapp->invalid) {
>> +        if (mapp->invalid && kref_get_unless_zero(&mapp->refcnt)) {
>>               found = true;
>>               break;
>>           }
>> @@ -1050,7 +1050,7 @@ static int aie2_populate_range(struct 
>> amdxdna_gem_obj *abo)
>>           up_write(&xdna->notifier_lock);
>>           return 0;
>>       }
>> -    kref_get(&mapp->refcnt);
>> +
>>       up_write(&xdna->notifier_lock);
>>         mm = mapp->notifier.mm;
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-07 17:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-06 22:12 [PATCH V1] accel/amdxdna: Fix potential amdxdna_umap lifetime race Lizhi Hou
2026-07-07 15:35 ` Max Zhen
2026-07-07 17:13   ` Lizhi Hou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®