* [PATCH] accel/rocket: Fix up sched array handling on open and close
@ 2026-11-18 10:18 Tomeu Vizoso
2026-11-18 10:25 ` sashiko-bot
2026-11-18 10:51 ` Heiko Stübner
0 siblings, 2 replies; 3+ messages in thread
From: Tomeu Vizoso @ 2026-11-18 10:18 UTC (permalink / raw)
To: Heiko Stuebner, Oded Gabbay, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann
Cc: David Airlie, Simona Vetter, Triet Hoang, Sidong Yang,
Igor Paunovic, dri-devel, linux-kernel
Don't WARN when drm_sched_entity_init() fails in rocket_job_open().
It can return -ENOMEM, which is an allocation failure and not a
driver bug, so it doesn't deserve a stack trace.
Also free the scheduler array in rocket_job_close() only after the entity
has been destroyed, so that entity->sched_list never points to freed
memory.
Fixes: d341ef030f3c ("accel/rocket: Check allocations before use")
Fixes: 9bca2b5f1a4f ("accel/rocket: Keep scheduler allocation in rocket_file_priv")
Suggested-by: Sidong Yang <sidong.yang@furiosa.ai>
Signed-off-by: Tomeu Vizoso <tomeu@tomeuvizoso.net>
Link: https://lore.kernel.org/all/20260826113538.42111-1-sidong.yang@furiosa.ai/
Link: https://lore.kernel.org/all/20260826113538.42111-2-sidong.yang@furiosa.ai/
---
This addresses a mistake I made when I missed the v6 of the
"accel/rocket: Fix allocation handling and scheduler array leak" series
and pushed v5 to drm-misc-fixes.
With these changes, both drm-misc-fixes and drm-misc-next contain the
same code in these functions and there should be no conflict when the
two are merged.
This is to apply to drm-misc-fixes only.
---
drivers/accel/rocket/rocket_job.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
index 7b798a90bc49..454d465a39e3 100644
--- a/drivers/accel/rocket/rocket_job.c
+++ b/drivers/accel/rocket/rocket_job.c
@@ -572,7 +572,7 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
DRM_SCHED_PRIORITY_NORMAL,
scheds,
rdev->num_cores, NULL);
- if (WARN_ON(ret))
+ if (ret)
kfree(scheds);
else
rocket_priv->scheds = scheds;
@@ -584,8 +584,8 @@ void rocket_job_close(struct rocket_file_priv *rocket_priv)
{
struct drm_sched_entity *entity = &rocket_priv->sched_entity;
- kfree(rocket_priv->scheds);
drm_sched_entity_destroy(entity);
+ kfree(rocket_priv->scheds);
}
int rocket_job_is_idle(struct rocket_core *core)
base-commit: f9fc6da01a290609428d308033143f1d96ab658f
--
2.54.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] accel/rocket: Fix up sched array handling on open and close
2026-11-18 10:18 [PATCH] accel/rocket: Fix up sched array handling on open and close Tomeu Vizoso
@ 2026-11-18 10:25 ` sashiko-bot
2026-11-18 10:51 ` Heiko Stübner
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-11-18 10:25 UTC (permalink / raw)
To: Tomeu Vizoso; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [Critical] accel/rocket: use-after-free of DRM scheduler in
rocket_remove() [1]
--
commit 60150dc55a394b4ae585de44cc1ea51f813c0a96
Author: Tomeu Vizoso <tomeu@tomeuvizoso.net>
accel/rocket: Fix up sched array handling on open and close
This commit drops the WARN_ON() when drm_sched_entity_init() fails in
rocket_job_open(), and reorders rocket_job_close() to destroy the scheduler
entity before freeing the scheduler array.
Link: https://lore.kernel.org/all/20260826113538.42111-1-sidong.yang@furiosa.ai/
Link: https://lore.kernel.org/all/20260826113538.42111-2-sidong.yang@furiosa.ai/
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index 7b798a90bc492..454d465a39e37 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c
> @@ -572,7 +572,7 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
> DRM_SCHED_PRIORITY_NORMAL,
> scheds,
> rdev->num_cores, NULL);
> - if (WARN_ON(ret))
> + if (ret)
> kfree(scheds);
> else
> rocket_priv->scheds = scheds;
[Severity: Critical]
This problem wasn't introduced by this patch, but can unbinding a Rocket NPU
core while a file descriptor is open cause a use-after-free of the DRM
scheduler [1]?
rocket_job_open() initializes rocket_priv->sched_entity with pointers to
rdev->cores[core].sched. If a core is unbound while the file descriptor
remains open, rocket_remove() calls rocket_core_fini() -> drm_sched_fini()
without synchronizing against open file descriptors or active entities. A
subsequent job submission then dereferences the torn-down scheduler in
drm_sched_job_arm():
CPU0 CPU1
rocket_job_open()
scheds[i] = &rdev->cores[i].sched
drm_sched_entity_init(..., scheds, ...)
rocket_remove()
rocket_core_fini()
drm_sched_fini()
rocket_ioctl_submit()
...
drm_sched_job_arm()
drm_sched_entity_select_rq()
sched = entity->rq->sched <-- use-after-free
[1] https://sashiko.dev/#/bug/linux-57e50ba5-1b02-4d94-b63e-d7208e41bab0
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261118101901.253550-1-tomeu@tomeuvizoso.net?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] accel/rocket: Fix up sched array handling on open and close
2026-11-18 10:18 [PATCH] accel/rocket: Fix up sched array handling on open and close Tomeu Vizoso
2026-11-18 10:25 ` sashiko-bot
@ 2026-11-18 10:51 ` Heiko Stübner
1 sibling, 0 replies; 3+ messages in thread
From: Heiko Stübner @ 2026-11-18 10:51 UTC (permalink / raw)
To: Oded Gabbay, Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
Tomeu Vizoso
Cc: David Airlie, Simona Vetter, Triet Hoang, Sidong Yang,
Igor Paunovic, dri-devel, linux-kernel
Am Mittwoch, 18. November 2026, 11:18:58 Mitteleuropäische Normalzeit schrieb Tomeu Vizoso:
> Don't WARN when drm_sched_entity_init() fails in rocket_job_open().
> It can return -ENOMEM, which is an allocation failure and not a
> driver bug, so it doesn't deserve a stack trace.
>
> Also free the scheduler array in rocket_job_close() only after the entity
> has been destroyed, so that entity->sched_list never points to freed
> memory.
>
> Fixes: d341ef030f3c ("accel/rocket: Check allocations before use")
> Fixes: 9bca2b5f1a4f ("accel/rocket: Keep scheduler allocation in rocket_file_priv")
> Suggested-by: Sidong Yang <sidong.yang@furiosa.ai>
> Signed-off-by: Tomeu Vizoso <tomeu@tomeuvizoso.net>
> Link: https://lore.kernel.org/all/20260826113538.42111-1-sidong.yang@furiosa.ai/
> Link: https://lore.kernel.org/all/20260826113538.42111-2-sidong.yang@furiosa.ai/
> ---
>
> This addresses a mistake I made when I missed the v6 of the
> "accel/rocket: Fix allocation handling and scheduler array leak" series
> and pushed v5 to drm-misc-fixes.
>
> With these changes, both drm-misc-fixes and drm-misc-next contain the
> same code in these functions and there should be no conflict when the
> two are merged.
>
> This is to apply to drm-misc-fixes only.
>
> ---
> drivers/accel/rocket/rocket_job.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/accel/rocket/rocket_job.c b/drivers/accel/rocket/rocket_job.c
> index 7b798a90bc49..454d465a39e3 100644
> --- a/drivers/accel/rocket/rocket_job.c
> +++ b/drivers/accel/rocket/rocket_job.c
> @@ -572,7 +572,7 @@ int rocket_job_open(struct rocket_file_priv *rocket_priv)
> DRM_SCHED_PRIORITY_NORMAL,
> scheds,
> rdev->num_cores, NULL);
> - if (WARN_ON(ret))
> + if (ret)
> kfree(scheds);
> else
> rocket_priv->scheds = scheds;
> @@ -584,8 +584,8 @@ void rocket_job_close(struct rocket_file_priv *rocket_priv)
> {
> struct drm_sched_entity *entity = &rocket_priv->sched_entity;
>
> - kfree(rocket_priv->scheds);
> drm_sched_entity_destroy(entity);
> + kfree(rocket_priv->scheds);
> }
Reviewed-by: Heiko Stuebner <heiko@sntech.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 10:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-18 10:18 [PATCH] accel/rocket: Fix up sched array handling on open and close Tomeu Vizoso
2026-11-18 10:25 ` sashiko-bot
2026-11-18 10:51 ` Heiko Stübner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.