media: mgb4: cancel err_work on teardown to avoid use-after-free
Subsystems (3)
PATCH 1/1 media: mgb4: cancel err_work on teardown to avoid use-after-free
From: Hyunjung Ko <[email protected]>
The err IRQ handler (err_handler) schedules vindev->err_work (signal_change), which dereferences vindev (vindev->mgbdev, vindev->vdev, vindev->queue). mgb4_vin_free() disables and frees the err IRQ, so no new err_work is scheduled, but it never cancels an err_work that was already queued by the last interrupt before kfree(vindev). As err_work runs on the system workqueue with no timing bound, it can execute after vindev is freed, dereferencing freed memory -- a use-after-free.
Cancel err_work after the interrupts are freed (so it cannot be re-queued) and before vindev is freed, mirroring the existing cancel_work_sync(&vindev->dma_work) in stop_streaming().
--- drivers/media/pci/mgb4/mgb4_vin.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/pci/mgb4/mgb4_vin.c +2 -0
@@ -1068,6 +1068,8 @@ void mgb4_vin_free(struct mgb4_vin_dev *vindev)free_irq (vin_irq, vindev);free_irq (err_irq, vindev); +cancel_work_sync (&vindev->err_work); +device_remove_groups (&vindev->vdev.dev,module_groups (vindev->mgbdev));mgb4_i2c_free (&vindev->deser);
Signature · 1 line
2.43.0
Please disregard this patch -- it is an accidental duplicate of
[PATCH] media: mgb4: cancel err_work before freeing the vin device
https://lore.kernel.org/linux-media/[email protected]/
which is the same one-line fix and already carries
Please apply that reviewed version instead; sorry for the noise.
Thanks,
Hyunjung
2026년 11월 9일 (월) 오후 1:53, hyunjungg <[email protected]>님이 작성:
Quoted 38 lines
From: Hyunjung Ko <[email protected]>
The err IRQ handler (
err_handler) schedulesvindev->err_work(signal_change), which dereferences vindev (vindev->mgbdev,vindev->vdev,vindev->queue).mgb4_vin_free()disables and frees the err IRQ, so no newerr_workis scheduled, but it never cancels anerr_workthat was already queued by the last interrupt before kfree(vindev). Aserr_workruns on the system workqueue with no timing bound, it can execute after vindev is freed, dereferencing freed memory -- a use-after-free.Cancel
err_workafter the interrupts are freed (so it cannot be re-queued) and before vindev is freed, mirroring the existingcancel_work_sync(&vindev->dma_work)instop_streaming().Fixes 0ab13674a9bd ("media: pci: mgb4: Added Digiteq Automotive MGB4 driver")Signed-off-by Hyunjung Ko <[email protected]>--- drivers/media/pci/mgb4/mgb4_vin.c | 2 ++ 1 file changed, 2 insertions(+)drivers/media/pci/mgb4/mgb4_vin.c +2
-1@@ -1068,6 +1068,8 @@ void mgb4_vin_free(struct mgb4_vin_dev *vindev)free_irq (vin_irq, vindev);free_irq (err_irq, vindev); +cancel_work_sync (&vindev->err_work); +device_remove_groups (&vindev->vdev.dev,module_groups (vindev->mgbdev));mgb4_i2c_free (&vindev->deser); --2.43.0