Skip to contentSkip to conversation

drm/amdgpu: Fix use-after-free race in VM acquire

PATCH In review [email protected] 4 participants 9 messages Feb 5 – Feb 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix use-after-free race in VM acquire

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
 		*process_info = info;
 	}
 
-	vm->process_info = *process_info;
+	if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+		ret = -EINVAL;
+		goto already_acquired;
+	}
 
 	/* Validate page directory and attach eviction fence */
 	ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1472,6 +1475,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
 	amdgpu_bo_unreserve(vm->root.bo);
 reserve_pd_fail:
 	vm->process_info = NULL;
+already_acquired:
 	if (info) {
 		dma_fence_put(&info->eviction_fence->base);
 		*process_info = NULL;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · On 2/5/2026 10:28 AM, [email protected] wrote:

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

I wonder how parent/child processes can share same drm file? The child process should close render node after fork/exec, then create its own gpu vm. Thunk open render node with O_CLOEXEC.

Regards

Xiaogang

Quoted 29 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
  		*process_info = info;
  	}
 
-	vm->process_info = *process_info;
+	if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+		ret = -EINVAL;
+		goto already_acquired;
+	}
 
  	/* Validate page directory and attach eviction fence */
  	ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1472,6 +1475,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
  	amdgpu_bo_unreserve(vm->root.bo);
  reserve_pd_fail:
  	vm->process_info = NULL;
+already_acquired:
  	if (info) {
  		dma_fence_put(&info->eviction_fence->base);
  		*process_info = NULL;
author
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Xiaogang,

I think this is a security vulnerability, the race could be intentionally triggered, so it doesn't matter how thunk opens render nodes, the kernel should handle this case safely.

Alysa

-----Original Message-----
From: Chen, Xiaogang <[email protected]>
Sent: Thursday, February 5, 2026 1:09 PM
To: Liu, Alysa <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Quoted 3 lines · On 2/5/2026 10:28 AM, [email protected] wrote:

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

I wonder how parent/child processes can share same drm file? The child process should close render node after fork/exec, then create its own gpu vm. Thunk open render node with O_CLOEXEC.

Regards

Xiaogang

Quoted 30 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
              *process_info = info;
      }
 
-     vm->process_info = *process_info;
+     if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+             ret = -EINVAL;
+             goto already_acquired;
+     }
 
      /* Validate page directory and attach eviction fence */
      ret = amdgpu_bo_reserve(vm->root.bo, true); @@ -1472,6 +1475,7 @@

static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,

      amdgpu_bo_unreserve(vm->root.bo);
  reserve_pd_fail:
      vm->process_info = NULL;
+already_acquired:
      if (info) {
              dma_fence_put(&info->eviction_fence->base);
              *process_info = NULL;
#3 lore raw

It is why I asked how it could happen. Is there real case? If there are two processes share context of a render node it is either intentionally or forbidden at user space.

Xiaogang

Quoted 56 lines · Alysa

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Xiaogang,

I think this is a security vulnerability, the race could be intentionally triggered, so it doesn't matter how thunk opens render nodes, the kernel should handle this case safely.

Alysa

-----Original Message-----
From: Chen, Xiaogang <[email protected]>
Sent: Thursday, February 5, 2026 1:09 PM
To: Liu, Alysa <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Quoted 3 lines · On 2/5/2026 10:28 AM, [email protected] wrote:

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

I wonder how parent/child processes can share same drm file? The child process should close render node after fork/exec, then create its own gpu vm. Thunk open render node with O_CLOEXEC.

Regards

Xiaogang

Quoted 30 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
               *process_info = info;
       }
 
-     vm->process_info = *process_info;
+     if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+             ret = -EINVAL;
+             goto already_acquired;
+     }
 
       /* Validate page directory and attach eviction fence */
       ret = amdgpu_bo_reserve(vm->root.bo, true); @@ -1472,6 +1475,7 @@

static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,

       amdgpu_bo_unreserve(vm->root.bo);
   reserve_pd_fail:
       vm->process_info = NULL;
+already_acquired:
       if (info) {
               dma_fence_put(&info->eviction_fence->base);
               *process_info = NULL;
author
#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Xiaogang, shared the proof-of-concept exploit in teams.

-----Original Message-----
From: Chen, Xiaogang <[email protected]>
Sent: Thursday, February 5, 2026 4:00 PM
To: Liu, Alysa <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

It is why I asked how it could happen. Is there real case? If there are two processes share context of a render node it is either intentionally or forbidden at user space.

Xiaogang

Quoted 57 lines · Alysa

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Xiaogang,

I think this is a security vulnerability, the race could be intentionally triggered, so it doesn't matter how thunk opens render nodes, the kernel should handle this case safely.

Alysa

-----Original Message-----
From: Chen, Xiaogang <[email protected]>
Sent: Thursday, February 5, 2026 1:09 PM
To: Liu, Alysa <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Quoted 3 lines · On 2/5/2026 10:28 AM, [email protected] wrote:

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

I wonder how parent/child processes can share same drm file? The child process should close render node after fork/exec, then create its own gpu vm. Thunk open render node with O_CLOEXEC.

Regards

Xiaogang

Quoted 30 lines
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
   1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +4 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
               *process_info = info;
       }
 
-     vm->process_info = *process_info;
+     if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+             ret = -EINVAL;
+             goto already_acquired;
+     }
 
       /* Validate page directory and attach eviction fence */
       ret = amdgpu_bo_reserve(vm->root.bo, true); @@ -1472,6 +1475,7

@@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,

       amdgpu_bo_unreserve(vm->root.bo);
   reserve_pd_fail:
       vm->process_info = NULL;
+already_acquired:
       if (info) {
               dma_fence_put(&info->eviction_fence->base);
               *process_info = NULL;
Reviewed-by on v1 1/1
#5 lore raw
In reply to [email protected]

[AMD Official Use Only - AMD Internal Distribution Only]

________________________________
From: Liu, Alysa <[email protected]>
Sent: Thursday, February 5, 2026 11:28 AM
To: [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Liu, Alysa <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
                 *process_info = info;
         }
 
-       vm->process_info = *process_info;
+       if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+               ret = -EINVAL;
+               goto already_acquired;
+       }
 
         /* Validate page directory and attach eviction fence */
         ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1472,6 +1475,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
         amdgpu_bo_unreserve(vm->root.bo);
 reserve_pd_fail:
         vm->process_info = NULL;
+already_acquired:
         if (info) {
                 dma_fence_put(&info->eviction_fence->base);
                 *process_info = NULL;

--
2.34.1

Reviewed-by Harish Kasiviswanathan
#6 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Let parent/child process share same vm will cause multiple issues. There is no use case or need for that. It should be prevented at uses space, not work around at this specific place in driver.

Regards
Xiaogang

From: amd-gfx <[email protected]> On Behalf Of Kasiviswanathan, Harish
Sent: Thursday, February 12, 2026 12:31 PM
To: Liu, Alysa <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

[AMD Official Use Only - AMD Internal Distribution Only]

________________________________
From: Liu, Alysa <[email protected]<mailto:[email protected]>>
Sent: Thursday, February 5, 2026 11:28 AM
To: [email protected]<mailto:[email protected]> <[email protected]<mailto:[email protected]>>
Cc: Deucher, Alexander <[email protected]<mailto:[email protected]>>; Kasiviswanathan, Harish <[email protected]<mailto:[email protected]>>; Liu, Alysa <[email protected]<mailto:[email protected]>>
Subject: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -1
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
                 *process_info = info;
         }
 
-       vm->process_info = *process_info;
+       if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+               ret = -EINVAL;
+               goto already_acquired;
+       }
 
         /* Validate page directory and attach eviction fence */
         ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1472,6 +1475,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
         amdgpu_bo_unreserve(vm->root.bo);
 reserve_pd_fail:
         vm->process_info = NULL;
+already_acquired:
         if (info) {
                 dma_fence_put(&info->eviction_fence->base);
                 *process_info = NULL;

--
2.34.1

#7 lore raw
Quoted 6 lines · Xiaogang

[AMD Official Use Only - AMD Internal Distribution Only]

Let parent/child process share same vm will cause multiple issues. There is no use case or need for that. It should be prevented at uses space, not work around at this specific place in driver.

I agree that userspace shouldn't to stupid things, but if it does, the kernel needs to gracefully handle it.

Alex

Quoted 67 lines

Regards

Xiaogang

From: amd-gfx <[email protected]> On Behalf Of Kasiviswanathan, Harish
Sent: Thursday, February 12, 2026 12:31 PM
To: Liu, Alysa <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

[AMD Official Use Only - AMD Internal Distribution Only]

________________________________

From: Liu, Alysa <[email protected]>
Sent: Thursday, February 5, 2026 11:28 AM
To: [email protected] <[email protected]>
Cc: Deucher, Alexander <[email protected]>; Kasiviswanathan, Harish <[email protected]>; Liu, Alysa <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -2
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
                 *process_info = info;
         }
 
-       vm->process_info = *process_info;
+       if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+               ret = -EINVAL;
+               goto already_acquired;
+       }
 
         /* Validate page directory and attach eviction fence */
         ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1472,6 +1475,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
         amdgpu_bo_unreserve(vm->root.bo);
 reserve_pd_fail:
         vm->process_info = NULL;
+already_acquired:
         if (info) {
                 dma_fence_put(&info->eviction_fence->base);
                 *process_info = NULL;
--

2.34.1

#8 lore raw
Quoted 8 lines · Alex Deucher
Quoted 5 lines · Xiaogang

[AMD Official Use Only - AMD Internal Distribution Only]

Let parent/child process share same vm will cause multiple issues. There is no use case or need for that. It should be prevented at uses space, not work around at this specific place in driver.

I agree that userspace shouldn't to stupid things, but if it does, the kernel needs to gracefully handle it.

Using same vm for multiple processes will cause multiple issues. Not only race on vm->process_info. This hacking does not reveal useful security issue. If parent process wants share its vm to another process kernel cannot do anything. This sharing just makes driver not work. People can see multiple errors from this sharing. If driver addresses every raised issue duo to vm sharing it would be endless.

Xiaogang

Quoted 69 lines

Alex

Quoted 66 lines

Regards

Xiaogang

From: amd-gfx<[email protected]> On Behalf Of Kasiviswanathan, Harish
Sent: Thursday, February 12, 2026 12:31 PM
To: Liu, Alysa<[email protected]>;[email protected]
Cc: Deucher, Alexander<[email protected]>
Subject: Re: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

[AMD Official Use Only - AMD Internal Distribution Only]

________________________________

From: Liu, Alysa<[email protected]>
Sent: Thursday, February 5, 2026 11:28 AM
To:[email protected] <[email protected]>
Cc: Deucher, Alexander<[email protected]>; Kasiviswanathan, Harish<[email protected]>; Liu, Alysa<[email protected]>
Subject: [PATCH] drm/amdgpu: Fix use-after-free race in VM acquire

Replace non-atomic vm->process_info assignment with cmpxchg() to prevent race when parent/child processes sharing a drm_file both try to acquire the same VM after fork().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +5 -2
index 00ea69baa126..f7b2358a0303 100644
@@ -1432,7 +1432,10 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
                  *process_info = info;
          }
 
-       vm->process_info = *process_info;
+       if (cmpxchg(&vm->process_info, NULL, *process_info) != NULL) {
+               ret = -EINVAL;
+               goto already_acquired;
+       }
 
          /* Validate page directory and attach eviction fence */
          ret = amdgpu_bo_reserve(vm->root.bo, true);
@@ -1472,6 +1475,7 @@ static int init_kfd_vm(struct amdgpu_vm *vm, void **process_info,
          amdgpu_bo_unreserve(vm->root.bo);
  reserve_pd_fail:
          vm->process_info = NULL;
+already_acquired:
          if (info) {
                  dma_fence_put(&info->eviction_fence->base);
                  *process_info = NULL;
--

2.34.1