media: coda: link to the VDOA to fix use-after-free on unbind
Subsystems (2)
PATCH 1/1 media: coda: link to the VDOA to fix use-after-free on unbind
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 <[email protected]>
---
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(-)
drivers/media/platform/chips-media/coda/coda-common.c +8 -3
@@ -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 ;
Signature · 1 line
2.34.1