From: sashiko-bot@kernel.org
To: "Vishnu Reddy" <busanna.reddy@oss.qualcomm.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v9 04/14] media: iris: Add helper to select relevant context bank device
Date: Wed, 15 Jul 2026 14:29:28 +0000 [thread overview]
Message-ID: <20260715142929.1E59D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260715-glymur-v9-4-8cf2cbe12a07@oss.qualcomm.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Using dynamically created context bank devices without taking a reference via get_device() creates a Use-After-Free risk when file descriptors outlive device unbind.
Pre-existing issues:
- [High] The `struct iris_core` is allocated via devres but is accessed in V4L2 deferred release paths, causing a Use-After-Free if a file descriptor is closed after driver unbind.
--
--- Patch [4]: [PATCH v9 04/14] media: iris: Add helper to select relevant context bank device ---
commit ff67c19893e13d3ddb40ea541f363dbf54e13228
Author: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
media: iris: Add helper to select relevant context bank device
This commit introduces a helper to associate the appropriate context bank
device with different buffer types. It updates the internal buffer allocation
and queue initialization to use this dynamically selected device instead of
always defaulting to the main core device.
> diff --git a/drivers/media/platform/qcom/iris/iris_buffer.c b/drivers/media/platform/qcom/iris/iris_buffer.c
> index 246ad0abbac35..249c9f1d0d5da 100644
> --- a/drivers/media/platform/qcom/iris/iris_buffer.c
> +++ b/drivers/media/platform/qcom/iris/iris_buffer.c
> @@ -545,7 +545,7 @@ static int iris_create_internal_buffer(struct iris_inst *inst,
> buffer->buffer_size = buffers->size;
> buffer->dma_attrs = DMA_ATTR_WRITE_COMBINE | DMA_ATTR_NO_KERNEL_MAPPING;
>
> - buffer->kvaddr = dma_alloc_attrs(core->dev, buffer->buffer_size,
> + buffer->kvaddr = dma_alloc_attrs(dev, buffer->buffer_size,
> &buffer->device_addr, GFP_KERNEL, buffer->dma_attrs);
[Severity: High]
Could this lead to a Use-After-Free of the context bank device?
When a userspace application opens the video device file descriptor,
iris_create_internal_buffer() allocates internal buffers using the context
bank device. If the driver is subsequently unbound (e.g., via sysfs) and the
context bank devices are unregistered and freed, the application could later
close the file descriptor.
Should a reference be taken on the context bank device pointer via
get_device() to ensure it outlives deferred file operations cleanup?
> if (!buffer->kvaddr) {
> kfree(buffer);
[ ... ]
> @@ -682,10 +682,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
>
> int iris_destroy_internal_buffer(struct iris_inst *inst, struct iris_buffer *buffer)
> {
> - struct iris_core *core = inst->core;
> + struct device *dev = iris_get_cb_dev(inst, buffer->type);
[Severity: High]
This is a pre-existing issue, but is it possible for inst->core to be freed
before this deferred cleanup is called?
In drivers/media/platform/qcom/iris/iris_probe.c, the core structure is
allocated via devm_kzalloc(). If the driver is unbound while a file
descriptor is open, devres will free the iris_core structure. When the file
descriptor is later closed, deferred release paths (such as
iris_check_num_queued_internal_buffers() in iris_vidc.c, or here calling
iris_get_cb_dev()) will dereference inst->core, resulting in a Use-After-Free.
>
> list_del(&buffer->list);
> - dma_free_attrs(core->dev, buffer->buffer_size, buffer->kvaddr,
> + dma_free_attrs(dev, buffer->buffer_size, buffer->kvaddr,
> buffer->device_addr, buffer->dma_attrs);
[Severity: High]
If the context bank device was freed during driver unbind, will passing the
unpinned device pointer to dma_free_attrs() during deferred fops release
cause a Use-After-Free?
> kfree(buffer);
>
> diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
> index 14d63dc76c9ba..26df872fb4fa1 100644
> --- a/drivers/media/platform/qcom/iris/iris_vidc.c
> +++ b/drivers/media/platform/qcom/iris/iris_vidc.c
> @@ -107,7 +107,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
> src_vq->drv_priv = inst;
> src_vq->buf_struct_size = sizeof(struct iris_buffer);
> src_vq->min_reqbufs_allocation = MIN_BUFFERS;
> - src_vq->dev = inst->core->dev;
> + src_vq->dev = iris_get_cb_dev(inst, BUF_INPUT);
> src_vq->lock = &inst->ctx_q_lock;
> ret = vb2_queue_init(src_vq);
> if (ret)
> @@ -121,7 +121,7 @@ iris_m2m_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_
> dst_vq->drv_priv = inst;
> dst_vq->buf_struct_size = sizeof(struct iris_buffer);
> dst_vq->min_reqbufs_allocation = MIN_BUFFERS;
> - dst_vq->dev = inst->core->dev;
> + dst_vq->dev = iris_get_cb_dev(inst, BUF_OUTPUT);
> dst_vq->lock = &inst->ctx_q_lock;
[Severity: High]
Does assigning the dynamically created context bank device to the vb2_queue
without taking a reference create a Use-After-Free risk?
If the driver unbinds and the device is freed, the vb2_queue could still be
accessed during deferred cleanup when the file descriptor is finally closed.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260715-glymur-v9-0-8cf2cbe12a07@oss.qualcomm.com?part=4
next prev parent reply other threads:[~2026-07-15 14:29 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-15 14:09 [PATCH v9 00/14] media: iris: Add support for glymur platform Vishnu Reddy
2026-07-15 14:09 ` [PATCH v9 01/14] dt-bindings: media: qcom,glymur-iris: Add glymur video codec Vishnu Reddy
2026-07-15 14:22 ` sashiko-bot
2026-07-15 14:09 ` [PATCH v9 02/14] media: iris: Add hooks to initialize and tear down context banks Vishnu Reddy
2026-07-15 14:23 ` sashiko-bot
2026-07-15 14:09 ` [PATCH v9 03/14] media: iris: Add helper to create a context bank device Vishnu Reddy
2026-07-15 14:09 ` [PATCH v9 04/14] media: iris: Add helper to select relevant " Vishnu Reddy
2026-07-15 14:29 ` sashiko-bot [this message]
2026-07-15 14:09 ` [PATCH v9 05/14] media: iris: Skip DMA mask setting to core device when IOMMU is not mapped Vishnu Reddy
2026-07-15 14:22 ` sashiko-bot
2026-07-15 14:10 ` [PATCH v9 06/14] media: iris: Enable Secure PAS support with IOMMU managed by Linux Vishnu Reddy
2026-07-15 14:37 ` sashiko-bot
2026-07-15 14:10 ` [PATCH v9 07/14] media: iris: Replace enum-indexed clock and power domain tables with per-block structures Vishnu Reddy
2026-07-15 14:39 ` sashiko-bot
2026-07-15 14:10 ` [PATCH v9 08/14] media: iris: Add power sequence for glymur Vishnu Reddy
2026-07-15 14:36 ` sashiko-bot
2026-07-15 14:10 ` [PATCH v9 09/14] media: iris: Handle CPU_CS_SCIACMDARG3 register write via program bootup registers hook Vishnu Reddy
2026-07-15 14:10 ` [PATCH v9 10/14] media: iris: Add support to select core for dual core platforms Vishnu Reddy
2026-07-15 14:42 ` sashiko-bot
2026-07-15 14:10 ` [PATCH v9 11/14] media: iris: Add hooks for pixel and non-pixel context banks Vishnu Reddy
2026-07-15 14:52 ` sashiko-bot
2026-07-15 15:27 ` Bryan O'Donoghue
2026-07-15 14:10 ` [PATCH v9 12/14] media: iris: Add platform data for glymur Vishnu Reddy
2026-07-15 14:10 ` [PATCH v9 13/14] arm64: dts: qcom: glymur: Add iris video node Vishnu Reddy
2026-07-15 15:18 ` sashiko-bot
2026-07-15 14:10 ` [PATCH v9 14/14] arm64: dts: qcom: glymur-crd: Enable iris video codec node Vishnu Reddy
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=20260715142929.1E59D1F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=busanna.reddy@oss.qualcomm.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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