* [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase
@ 2026-10-07 18:12 Osama Abdelkader
2026-10-08 7:55 ` Boris Brezillon
2026-10-08 8:53 ` Liviu Dudau
0 siblings, 2 replies; 4+ messages in thread
From: Osama Abdelkader @ 2026-10-07 18:12 UTC (permalink / raw)
To: Boris Brezillon, Steven Price, Liviu Dudau, Maarten Lankhorst,
Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
Akash Goel, Chia-I Wu, dri-devel, linux-kernel
Cc: Osama Abdelkader, stable
panthor_group_destroy() checks the GROUP_REGISTERED mark and then calls
xa_erase() without holding the xarray lock across both. If the handle is
destroyed by another thread in between, and a concurrent GROUP_CREATE
reuses the freed ID, the first destroy erases and releases the new,
still-initializing group, leading to a use-after-free in
panthor_group_create().
Do the mark check and erase atomically under xa_lock().
Fixes: eec7e23d848d ("drm/panthor: Prevent potential UAF in group creation")
Cc: stable@vger.kernel.org
Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
---
drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
index 0493858e55d7..a343c5180e01 100644
--- a/drivers/gpu/drm/panthor/panthor_sched.c
+++ b/drivers/gpu/drm/panthor/panthor_sched.c
@@ -3770,12 +3770,18 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
struct panthor_group_pool *gpool = pfile->groups;
struct panthor_device *ptdev = pfile->ptdev;
struct panthor_scheduler *sched = ptdev->scheduler;
- struct panthor_group *group;
+ struct panthor_group *group = NULL;
- if (!xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
- return -EINVAL;
+ /*
+ * Check the mark and erase the entry atomically, so a concurrent
+ * destroy + create can't make us erase a group that's still being
+ * initialized and happens to reuse the same handle.
+ */
+ xa_lock(&gpool->xa);
+ if (xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
+ group = __xa_erase(&gpool->xa, group_handle);
+ xa_unlock(&gpool->xa);
- group = xa_erase(&gpool->xa, group_handle);
if (!group)
return -EINVAL;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase
2026-10-07 18:12 [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase Osama Abdelkader
@ 2026-10-08 7:55 ` Boris Brezillon
2026-10-08 8:53 ` Liviu Dudau
1 sibling, 0 replies; 4+ messages in thread
From: Boris Brezillon @ 2026-10-08 7:55 UTC (permalink / raw)
To: Osama Abdelkader
Cc: Steven Price, Liviu Dudau, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Akash Goel,
Chia-I Wu, dri-devel, linux-kernel, stable
On Wed, 7 Oct 2026 20:12:19 +0200
Osama Abdelkader <osama.abdelkader@gmail.com> wrote:
> panthor_group_destroy() checks the GROUP_REGISTERED mark and then calls
> xa_erase() without holding the xarray lock across both. If the handle is
> destroyed by another thread in between, and a concurrent GROUP_CREATE
> reuses the freed ID, the first destroy erases and releases the new,
> still-initializing group, leading to a use-after-free in
> panthor_group_create().
>
> Do the mark check and erase atomically under xa_lock().
>
> Fixes: eec7e23d848d ("drm/panthor: Prevent potential UAF in group creation")
The fix looks legit, but I wonder how the bug was found. If this was
found with the help of a tool (AI or static code analyzer), this should
be reflected with an `Assisted-by` tag (see [1]).
With the relevant Assisted-by tag, this is
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
[1]https://docs.kernel.org/process/coding-assistants.html
> Cc: stable@vger.kernel.org
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 0493858e55d7..a343c5180e01 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -3770,12 +3770,18 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
> struct panthor_group_pool *gpool = pfile->groups;
> struct panthor_device *ptdev = pfile->ptdev;
> struct panthor_scheduler *sched = ptdev->scheduler;
> - struct panthor_group *group;
> + struct panthor_group *group = NULL;
>
> - if (!xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
> - return -EINVAL;
> + /*
> + * Check the mark and erase the entry atomically, so a concurrent
> + * destroy + create can't make us erase a group that's still being
> + * initialized and happens to reuse the same handle.
> + */
> + xa_lock(&gpool->xa);
> + if (xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
> + group = __xa_erase(&gpool->xa, group_handle);
> + xa_unlock(&gpool->xa);
>
> - group = xa_erase(&gpool->xa, group_handle);
> if (!group)
> return -EINVAL;
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase
2026-10-07 18:12 [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase Osama Abdelkader
2026-10-08 7:55 ` Boris Brezillon
@ 2026-10-08 8:53 ` Liviu Dudau
2026-10-08 10:03 ` Osama Abdelkader
1 sibling, 1 reply; 4+ messages in thread
From: Liviu Dudau @ 2026-10-08 8:53 UTC (permalink / raw)
To: Osama Abdelkader
Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Akash Goel,
Chia-I Wu, dri-devel, linux-kernel, stable
On Wed, Oct 07, 2026 at 08:12:19PM +0200, Osama Abdelkader wrote:
> panthor_group_destroy() checks the GROUP_REGISTERED mark and then calls
> xa_erase() without holding the xarray lock across both. If the handle is
> destroyed by another thread in between, and a concurrent GROUP_CREATE
> reuses the freed ID, the first destroy erases and releases the new,
> still-initializing group, leading to a use-after-free in
> panthor_group_create().
>
> Do the mark check and erase atomically under xa_lock().
>
> Fixes: eec7e23d848d ("drm/panthor: Prevent potential UAF in group creation")
> Cc: stable@vger.kernel.org
> Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
As Boris mentioned, please let us know if LLM has assisted in finding the bug or in
the creation of the patch before we can merge the fix.
Best regards,
Liviu
> ---
> drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> index 0493858e55d7..a343c5180e01 100644
> --- a/drivers/gpu/drm/panthor/panthor_sched.c
> +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> @@ -3770,12 +3770,18 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
> struct panthor_group_pool *gpool = pfile->groups;
> struct panthor_device *ptdev = pfile->ptdev;
> struct panthor_scheduler *sched = ptdev->scheduler;
> - struct panthor_group *group;
> + struct panthor_group *group = NULL;
>
> - if (!xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
> - return -EINVAL;
> + /*
> + * Check the mark and erase the entry atomically, so a concurrent
> + * destroy + create can't make us erase a group that's still being
> + * initialized and happens to reuse the same handle.
> + */
> + xa_lock(&gpool->xa);
> + if (xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
> + group = __xa_erase(&gpool->xa, group_handle);
> + xa_unlock(&gpool->xa);
>
> - group = xa_erase(&gpool->xa, group_handle);
> if (!group)
> return -EINVAL;
>
> --
> 2.53.0
>
--
====================
| I would like to |
| fix the world, |
| but they're not |
| giving me the |
\ source code! /
---------------
¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase
2026-10-08 8:53 ` Liviu Dudau
@ 2026-10-08 10:03 ` Osama Abdelkader
0 siblings, 0 replies; 4+ messages in thread
From: Osama Abdelkader @ 2026-10-08 10:03 UTC (permalink / raw)
To: Liviu Dudau
Cc: Boris Brezillon, Steven Price, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Akash Goel,
Chia-I Wu, dri-devel, linux-kernel, stable
On Thu, Oct 08, 2026 at 09:53:50AM +0100, Liviu Dudau wrote:
> On Wed, Oct 07, 2026 at 08:12:19PM +0200, Osama Abdelkader wrote:
> > panthor_group_destroy() checks the GROUP_REGISTERED mark and then calls
> > xa_erase() without holding the xarray lock across both. If the handle is
> > destroyed by another thread in between, and a concurrent GROUP_CREATE
> > reuses the freed ID, the first destroy erases and releases the new,
> > still-initializing group, leading to a use-after-free in
> > panthor_group_create().
> >
> > Do the mark check and erase atomically under xa_lock().
> >
> > Fixes: eec7e23d848d ("drm/panthor: Prevent potential UAF in group creation")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Osama Abdelkader <osama.abdelkader@gmail.com>
>
> Reviewed-by: Liviu Dudau <liviu.dudau@arm.com>
>
> As Boris mentioned, please let us know if LLM has assisted in finding the bug or in
> the creation of the patch before we can merge the fix.
>
Hi Liviu and Boris,
Thanks for the review, an LLM has assisted to find the bug but I created the fix patch myself.
I think I have to add the tag nevertheless.
Thanks,
Osama
> Best regards,
> Liviu
>
> > ---
> > drivers/gpu/drm/panthor/panthor_sched.c | 14 ++++++++++----
> > 1 file changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/panthor/panthor_sched.c b/drivers/gpu/drm/panthor/panthor_sched.c
> > index 0493858e55d7..a343c5180e01 100644
> > --- a/drivers/gpu/drm/panthor/panthor_sched.c
> > +++ b/drivers/gpu/drm/panthor/panthor_sched.c
> > @@ -3770,12 +3770,18 @@ int panthor_group_destroy(struct panthor_file *pfile, u32 group_handle)
> > struct panthor_group_pool *gpool = pfile->groups;
> > struct panthor_device *ptdev = pfile->ptdev;
> > struct panthor_scheduler *sched = ptdev->scheduler;
> > - struct panthor_group *group;
> > + struct panthor_group *group = NULL;
> >
> > - if (!xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
> > - return -EINVAL;
> > + /*
> > + * Check the mark and erase the entry atomically, so a concurrent
> > + * destroy + create can't make us erase a group that's still being
> > + * initialized and happens to reuse the same handle.
> > + */
> > + xa_lock(&gpool->xa);
> > + if (xa_get_mark(&gpool->xa, group_handle, GROUP_REGISTERED))
> > + group = __xa_erase(&gpool->xa, group_handle);
> > + xa_unlock(&gpool->xa);
> >
> > - group = xa_erase(&gpool->xa, group_handle);
> > if (!group)
> > return -EINVAL;
> >
> > --
> > 2.53.0
> >
>
> --
> ====================
> | I would like to |
> | fix the world, |
> | but they're not |
> | giving me the |
> \ source code! /
> ---------------
> ¯\_(ツ)_/¯
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-10-08 10:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-07 18:12 [PATCH] drm/panthor: Fix TOCTOU race between GROUP_REGISTERED check and erase Osama Abdelkader
2026-10-08 7:55 ` Boris Brezillon
2026-10-08 8:53 ` Liviu Dudau
2026-10-08 10:03 ` Osama Abdelkader
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®