mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: hyunjungg <hj351016@gmail.com>
To: Martin Tuma <martin.tuma@digiteqautomotive.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Hyunjung Ko <hj351016@gmail.com>
Subject: [PATCH] media: mgb4: cancel err_work before freeing the vin device
Date: Fri,  6 Nov 2026 13:35:41 +0900	[thread overview]
Message-ID: <20261106043541.1902730-1-hj351016@gmail.com> (raw)

From: Hyunjung Ko <hj351016@gmail.com>

The input (vin) device schedules err_work (signal_change) from its error
interrupt handler err_handler(). On device removal, mgb4_vin_free() masks
and frees the error IRQ, but never drains err_work before kfree(vindev):

	xdma_disable_user_irq(vindev->mgbdev->xdev, err_irq);
	free_irq(vin_irq, vindev);
	free_irq(err_irq, vindev);
	...
	kfree(vindev);

free_irq() only synchronises against the IRQ handler itself; it does not
wait for a work item the handler has already queued on the system
workqueue. If an error interrupt fires shortly before removal, the queued
signal_change() work can run after vindev has been freed and dereferences
it (vindev->mgbdev->video, vindev->vdev, vindev->queue, vindev->timings),
causing a use-after-free.

Note the dma_work counterpart is already drained via cancel_work_sync() in
stop_streaming(); err_work has no corresponding cancel on any path. Add a
cancel_work_sync() for err_work in mgb4_vin_free(), placed after both IRQs
are freed so the handler can no longer re-queue the work.

Found by code review; not reproduced (requires the Digiteq MGB4 frame
grabber and an error interrupt racing device removal).

Signed-off-by: Hyunjung Ko <hj351016@gmail.com>
---
 drivers/media/pci/mgb4/mgb4_vin.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/media/pci/mgb4/mgb4_vin.c b/drivers/media/pci/mgb4/mgb4_vin.c
--- a/drivers/media/pci/mgb4/mgb4_vin.c
+++ b/drivers/media/pci/mgb4/mgb4_vin.c
@@ -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);

             reply	other threads:[~2026-11-06  4:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-06  4:35 hyunjungg [this message]
2026-11-06 14:54 ` Martin Tůma

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261106043541.1902730-1-hj351016@gmail.com \
    --to=hj351016@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=martin.tuma@digiteqautomotive.com \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®