* [PATCH] drm/panthor: Avoid potential UAF due to memory reclaim
@ 2026-04-10 19:50 Akash Goel
2026-04-13 7:39 ` Boris Brezillon
2026-04-13 14:52 ` Liviu Dudau
0 siblings, 2 replies; 3+ messages in thread
From: Akash Goel @ 2026-04-10 19:50 UTC (permalink / raw)
To: boris.brezillon, liviu.dudau, steven.price
Cc: dri-devel, linux-kernel, maarten.lankhorst, mripard, tzimmermann,
airlied, daniel, nd, Akash Goel
Recent changes to add shrinker support introduced a use after free
vulnerability.
When a BO is evicted from the shrinker callback, all its CPU and GPU
mappings are invalidated. It can happen that another GPU mapping is
created for the BO after the eviction. Because of the new GPU mapping,
BO will be added back to one of the reclaim list but the state of
corresponding vm_bo will not be changed.
If vm_bo remains in evicted state and shrinker callback is invoked
again then the new GPU mapping won't be invalidated. As a result the
backing pages, which were acquired on the creation of new GPU mapping,
can get reclaimed and reused whilst they are still mapped to the GPU.
To prevent the use after free possibility, this commit removes the
evicted check for vm_bo so that all GPU mappings are checked for
invalidation.
Fixes: fb42964e2a76 ("drm/panthor: Add a GEM shrinker")
Suggested-by: Boris Brezillon <boris.brezillon@collabora.com>
Signed-off-by: Akash Goel <akash.goel@arm.com>
---
drivers/gpu/drm/panthor/panthor_mmu.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
index fa8b31df85c9..8d0dfa93c45c 100644
--- a/drivers/gpu/drm/panthor/panthor_mmu.c
+++ b/drivers/gpu/drm/panthor/panthor_mmu.c
@@ -2350,14 +2350,19 @@ int panthor_vm_evict_bo_mappings_locked(struct panthor_gem_object *bo)
struct panthor_vm *vm = container_of(vm_bo->vm, struct panthor_vm, base);
struct drm_gpuva *va;
- /* Skip already evicted GPU mappings. */
- if (vm_bo->evicted)
- continue;
-
if (!mutex_trylock(&vm->op_lock))
return -EDEADLK;
- drm_gpuvm_bo_evict(vm_bo, true);
+ /* It can be that the vm_bo was already evicted, but a new
+ * mapping pointing to this BO got created in the meantime,
+ * turning the vm_bo in partially evicted state. In that case
+ * we don't call drm_gpuvm_bo_evict() again because this would
+ * mess up with the internal gpuvm lists, but we do walk the
+ * VAs on this vm_bo to make sure the non-evicted ones are
+ * torn down.
+ */
+ if (!vm_bo->evicted)
+ drm_gpuvm_bo_evict(vm_bo, true);
drm_gpuvm_bo_for_each_va(va, vm_bo) {
struct panthor_vma *vma = container_of(va, struct panthor_vma, base);
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] drm/panthor: Avoid potential UAF due to memory reclaim
2026-04-10 19:50 [PATCH] drm/panthor: Avoid potential UAF due to memory reclaim Akash Goel
@ 2026-04-13 7:39 ` Boris Brezillon
2026-04-13 14:52 ` Liviu Dudau
1 sibling, 0 replies; 3+ messages in thread
From: Boris Brezillon @ 2026-04-13 7:39 UTC (permalink / raw)
To: Akash Goel
Cc: liviu.dudau, steven.price, dri-devel, linux-kernel,
maarten.lankhorst, mripard, tzimmermann, airlied, daniel, nd
On Fri, 10 Apr 2026 20:50:50 +0100
Akash Goel <akash.goel@arm.com> wrote:
> Recent changes to add shrinker support introduced a use after free
> vulnerability.
> When a BO is evicted from the shrinker callback, all its CPU and GPU
> mappings are invalidated. It can happen that another GPU mapping is
> created for the BO after the eviction. Because of the new GPU mapping,
> BO will be added back to one of the reclaim list but the state of
> corresponding vm_bo will not be changed.
> If vm_bo remains in evicted state and shrinker callback is invoked
> again then the new GPU mapping won't be invalidated. As a result the
> backing pages, which were acquired on the creation of new GPU mapping,
> can get reclaimed and reused whilst they are still mapped to the GPU.
>
> To prevent the use after free possibility, this commit removes the
> evicted check for vm_bo so that all GPU mappings are checked for
> invalidation.
>
> Fixes: fb42964e2a76 ("drm/panthor: Add a GEM shrinker")
> Suggested-by: Boris Brezillon <boris.brezillon@collabora.com>
> Signed-off-by: Akash Goel <akash.goel@arm.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
A couple nits below.
> ---
> drivers/gpu/drm/panthor/panthor_mmu.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index fa8b31df85c9..8d0dfa93c45c 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -2350,14 +2350,19 @@ int panthor_vm_evict_bo_mappings_locked(struct panthor_gem_object *bo)
> struct panthor_vm *vm = container_of(vm_bo->vm, struct panthor_vm, base);
> struct drm_gpuva *va;
>
> - /* Skip already evicted GPU mappings. */
> - if (vm_bo->evicted)
> - continue;
> -
> if (!mutex_trylock(&vm->op_lock))
> return -EDEADLK;
>
> - drm_gpuvm_bo_evict(vm_bo, true);
> + /* It can be that the vm_bo was already evicted, but a new
evicted but a ...
> + * mapping pointing to this BO got created in the meantime,
> + * turning the vm_bo in partially evicted state. In that case
thus turning the vm_bo in a partially evicted state.
> + * we don't call drm_gpuvm_bo_evict() again because this would
> + * mess up with the internal gpuvm lists, but we do walk the
> + * VAs on this vm_bo to make sure the non-evicted ones are
> + * torn down.
> + */
> + if (!vm_bo->evicted)
> + drm_gpuvm_bo_evict(vm_bo, true);
Can we add a blank line here?
> drm_gpuvm_bo_for_each_va(va, vm_bo) {
> struct panthor_vma *vma = container_of(va, struct panthor_vma, base);
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] drm/panthor: Avoid potential UAF due to memory reclaim
2026-04-10 19:50 [PATCH] drm/panthor: Avoid potential UAF due to memory reclaim Akash Goel
2026-04-13 7:39 ` Boris Brezillon
@ 2026-04-13 14:52 ` Liviu Dudau
1 sibling, 0 replies; 3+ messages in thread
From: Liviu Dudau @ 2026-04-13 14:52 UTC (permalink / raw)
To: Akash Goel
Cc: boris.brezillon, steven.price, dri-devel, linux-kernel,
maarten.lankhorst, mripard, tzimmermann, airlied, daniel, nd
On Fri, Apr 10, 2026 at 08:50:50PM +0100, Akash Goel wrote:
> Recent changes to add shrinker support introduced a use after free
> vulnerability.
> When a BO is evicted from the shrinker callback, all its CPU and GPU
> mappings are invalidated. It can happen that another GPU mapping is
> created for the BO after the eviction. Because of the new GPU mapping,
> BO will be added back to one of the reclaim list but the state of
> corresponding vm_bo will not be changed.
> If vm_bo remains in evicted state and shrinker callback is invoked
> again then the new GPU mapping won't be invalidated. As a result the
> backing pages, which were acquired on the creation of new GPU mapping,
> can get reclaimed and reused whilst they are still mapped to the GPU.
>
> To prevent the use after free possibility, this commit removes the
> evicted check for vm_bo so that all GPU mappings are checked for
> invalidation.
>
> Fixes: fb42964e2a76 ("drm/panthor: Add a GEM shrinker")
> Suggested-by: Boris Brezillon <boris.brezillon@collabora.com>
> Signed-off-by: Akash Goel <akash.goel@arm.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_mmu.c | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c
> index fa8b31df85c9..8d0dfa93c45c 100644
> --- a/drivers/gpu/drm/panthor/panthor_mmu.c
> +++ b/drivers/gpu/drm/panthor/panthor_mmu.c
> @@ -2350,14 +2350,19 @@ int panthor_vm_evict_bo_mappings_locked(struct panthor_gem_object *bo)
> struct panthor_vm *vm = container_of(vm_bo->vm, struct panthor_vm, base);
> struct drm_gpuva *va;
>
> - /* Skip already evicted GPU mappings. */
> - if (vm_bo->evicted)
> - continue;
> -
> if (!mutex_trylock(&vm->op_lock))
> return -EDEADLK;
>
> - drm_gpuvm_bo_evict(vm_bo, true);
> + /* It can be that the vm_bo was already evicted, but a new
> + * mapping pointing to this BO got created in the meantime,
> + * turning the vm_bo in partially evicted state. In that case
> + * we don't call drm_gpuvm_bo_evict() again because this would
> + * mess up with the internal gpuvm lists, but we do walk the
> + * VAs on this vm_bo to make sure the non-evicted ones are
> + * torn down.
> + */
> + if (!vm_bo->evicted)
> + drm_gpuvm_bo_evict(vm_bo, true);
> drm_gpuvm_bo_for_each_va(va, vm_bo) {
> struct panthor_vma *vma = container_of(va, struct panthor_vma, base);
>
> --
> 2.25.1
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-13 14:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-10 19:50 [PATCH] drm/panthor: Avoid potential UAF due to memory reclaim Akash Goel
2026-04-13 7:39 ` Boris Brezillon
2026-04-13 14:52 ` Liviu Dudau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox