mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Prasanth R <ragaprasanth@gmail.com>
To: Philipp Zabel <p.zabel@pengutronix.de>,
	Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: Michael Tretter <m.tretter@pengutronix.de>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	Prasanth R <ragaprasanth@gmail.com>
Subject: [PATCH] media: coda: link to the VDOA to fix use-after-free on unbind
Date: Wed,  2 Dec 2026 17:28:34 +0900	[thread overview]
Message-ID: <20261202082834.3764337-1-ragaprasanth@gmail.com> (raw)

coda keeps a pointer to the VDOA driver data from probe, but nothing
keeps the VDOA bound. After the VDOA is unbound, its devres data is
freed, and the next open of a coda video node uses it. On the i.MX6Q
SABRE-SD:

  echo 21e4000.vdoa > /sys/bus/platform/drivers/imx-vdoa/unbind
  : < /dev/video10

  BUG: KASAN: slab-use-after-free in vdoa_context_create+0x34/0xbc
  Read of size 4 at addr c9bd9448

Add a device link from coda to the VDOA, so unbinding the VDOA unbinds
coda first.

Fixes: e7f3c5481035 ("[media] coda: use VDOA for un-tiling custom macroblock format")

Signed-off-by: Prasanth R <prasanth.r@lineo.co.jp>
---
Tested on the i.MX6Q SABRE-SD with KASAN: no crash after the fix,
and coda binds again after the VDOA is bound again.
Suspend to RAM and resume still work.

I used an AI assistant (Claude) to find this and write the change.

 drivers/media/platform/chips-media/coda/coda-common.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/chips-media/coda/coda-common.c b/drivers/media/platform/chips-media/coda/coda-common.c
index be37ea568..48c18533e 100644
--- a/drivers/media/platform/chips-media/coda/coda-common.c
+++ b/drivers/media/platform/chips-media/coda/coda-common.c
@@ -396,7 +396,7 @@ const char *coda_product_name(int product)
 	}
 }
 
-static struct vdoa_data *coda_get_vdoa_data(void)
+static struct vdoa_data *coda_get_vdoa_data(struct device *dev)
 {
 	struct device_node *vdoa_node;
 	struct platform_device *vdoa_pdev;
@@ -411,8 +411,13 @@ static struct vdoa_data *coda_get_vdoa_data(void)
 		goto out;
 
 	vdoa_data = platform_get_drvdata(vdoa_pdev);
-	if (!vdoa_data)
+	if (!vdoa_data) {
 		vdoa_data = ERR_PTR(-EPROBE_DEFER);
+	} else if (!device_link_add(dev, &vdoa_pdev->dev,
+				    DL_FLAG_AUTOREMOVE_CONSUMER)) {
+		dev_warn(dev, "failed to link to VDOA, not using it\n");
+		vdoa_data = NULL;
+	}
 
 	put_device(&vdoa_pdev->dev);
 out:
@@ -3220,7 +3225,7 @@ static int coda_probe(struct platform_device *pdev)
 	dev->iram_pool = pool;
 
 	/* Get vdoa_data if supported by the platform */
-	dev->vdoa = coda_get_vdoa_data();
+	dev->vdoa = coda_get_vdoa_data(&pdev->dev);
 	if (PTR_ERR(dev->vdoa) == -EPROBE_DEFER)
 		return -EPROBE_DEFER;
 
-- 
2.34.1


                 reply	other threads:[~2026-12-02  8:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261202082834.3764337-1-ragaprasanth@gmail.com \
    --to=ragaprasanth@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.tretter@pengutronix.de \
    --cc=mchehab@kernel.org \
    --cc=p.zabel@pengutronix.de \
    /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®