dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] accel/habanalabs: fix use-after-free of decoder array on removal
@ 2026-09-09  4:23 Fan Wu
  2026-09-09  4:38 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Fan Wu @ 2026-09-09  4:23 UTC (permalink / raw)
  To: ogabbay
  Cc: dri-devel, linux-kernel, stable, koby.elbaz, konstantin.sinyuk,
	Fan Wu

The abnormal decoder interrupt queues the decoder's abnrm_intr_work
work item on the system workqueue, and the work callback uses the
decoder entry it is embedded in.

hl_device_fini() releases the decoder interrupts through
cleanup_resources() -> halt_engines() before it calls hl_dec_fini(),
which frees the decoder array without waiting for these work items.
A work item queued by one of the last interrupts can still be pending
and run after the array has been freed.

Fix this by waiting for each decoder's work item in hl_dec_fini()
before the array is freed. The error path of hl_dec_init() keeps
freeing the array directly: no interrupt has been requested yet, and
the entries past the failing one have never been initialized.

This issue was found by an in-house static analysis tool.

Fixes: d7bb1ac89b2f ("habanalabs: add gaudi2 asic-specific code")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.6
Co-developed-by: Song Li <songl@zju.edu.cn>
Signed-off-by: Song Li <songl@zju.edu.cn>
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
 drivers/accel/habanalabs/common/decoder.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/accel/habanalabs/common/decoder.c b/drivers/accel/habanalabs/common/decoder.c
index e4802f30c08a..ed0c25934206 100644
--- a/drivers/accel/habanalabs/common/decoder.c
+++ b/drivers/accel/habanalabs/common/decoder.c
@@ -85,6 +85,16 @@ static void dec_abnrm_intr_work(struct work_struct *work)
 
 void hl_dec_fini(struct hl_device *hdev)
 {
+	struct asic_fixed_properties *prop = &hdev->asic_prop;
+	int i;
+
+	if (!hdev->dec)
+		return;
+
+	/* interrupts are gone, but a queued work item may still be pending */
+	for (i = 0; i < prop->max_dec; i++)
+		cancel_work_sync(&hdev->dec[i].abnrm_intr_work);
+
 	kfree(hdev->dec);
 }
 
@@ -119,7 +129,8 @@ int hl_dec_init(struct hl_device *hdev)
 	return 0;
 
 err_dec_fini:
-	hl_dec_fini(hdev);
+	/* No interrupt was requested yet, so no work could be queued. */
+	kfree(hdev->dec);
 
 	return rc;
 }


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

end of thread, other threads:[~2026-09-09  4:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-09  4:23 [PATCH] accel/habanalabs: fix use-after-free of decoder array on removal Fan Wu
2026-09-09  4:38 ` sashiko-bot

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