All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vikash Garodia" <vikash.garodia@oss.qualcomm.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v3 06/13] media: iris: Route buffers to the matching context bank device
Date: Wed, 09 Sep 2026 15:13:54 +0000	[thread overview]
Message-ID: <20260909151355.3A2FE1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260909-vpu_iommu_iova_handling-v3-6-2fe43ae45495@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

New issues:
- [Critical] Context bank devices (np_dev and p_dev) are unregistered and freed during driver removal while V4L2 queues and internal buffers still hold references to them, leading to a Use-After-Free and IOMMU faults in dma_free_attrs().

Pre-existing issues:
- [Critical] V4L2 instances access devres-managed `iris_core` structure after it has been freed during module removal.
--

commit 0b3161aa43cd126ba013789330d51a653b78bf3a
Author: Vikash Garodia <vikash.garodia@oss.qualcomm.com>
Subject: media: iris: Route buffers to the matching context bank device

The VPU issues direct memory accesses through several stream units, requiring
non-pixel streams to use a specific context bank device due to address range
differences. This commit updates the buffer and queue allocation routines
to fetch and use the matching context bank device based on the buffer type.

> diff --git a/drivers/media/platform/qcom/iris/iris_buffer.c b/drivers/media/platform/qcom/iris/iris_buffer.c
> index eb8de60c1177f..6e03d13ac1a79 100644
> --- a/drivers/media/platform/qcom/iris/iris_buffer.c
> +++ b/drivers/media/platform/qcom/iris/iris_buffer.c
[ ... ]
> @@ -650,10 +650,10 @@ int iris_queue_internal_buffers(struct iris_inst *inst, u32 plane)
>  
>  void 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);
>  
>  	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: Critical]
Does this code introduce a use-after-free regression for the context bank
device?

If userspace keeps the device node open during driver unbind, the context
bank devices might be unregistered and freed. When the file descriptor is
subsequently closed by userspace, tearing down the internal buffers will
invoke dma_free_attrs() with the freed device. 

Since we are using these devices for memory tracking without taking a
reference, can this lead to memory corruption?

> diff --git a/drivers/media/platform/qcom/iris/iris_resources.c b/drivers/media/platform/qcom/iris/iris_resources.c
> index 2c4d34c7bd77d..a6c3df892ca98 100644
> --- a/drivers/media/platform/qcom/iris/iris_resources.c
> +++ b/drivers/media/platform/qcom/iris/iris_resources.c
[ ... ]
> @@ -138,3 +139,43 @@ int iris_disable_unprepare_clock(struct iris_core *core, enum platform_clk_type 
>  
>  	return 0;
>  }
> +
> +struct device *iris_get_cb_dev(struct iris_inst *inst, enum iris_buffer_type buffer_type)
> +{
> +	struct iris_core *core = inst->core;

[Severity: Critical]
This is a pre-existing issue, but can this dereference of inst->core lead
to a use-after-free?

The iris_core structure is devres-managed. If the driver is unbound while
userspace still has the file descriptor open, devres will free the core
structure immediately. 

When the file is closed later, teardown paths that call into functions like
iris_get_cb_dev() will access the freed inst->core structure.

> diff --git a/drivers/media/platform/qcom/iris/iris_vidc.c b/drivers/media/platform/qcom/iris/iris_vidc.c
> index fcbc60016beec..064cf0a80748d 100644
> --- a/drivers/media/platform/qcom/iris/iris_vidc.c
> +++ b/drivers/media/platform/qcom/iris/iris_vidc.c
> @@ -108,7 +108,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;

[Severity: Critical]
Can assigning this dynamically unregistered context bank device to the
queue cause a similar regression?

Like the internal buffers, if the driver unbinds while userspace
holds a file descriptor open, the queue teardown during the deferred
file close might dereference the freed context bank device.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909-vpu_iommu_iova_handling-v3-0-2fe43ae45495@oss.qualcomm.com?part=6

  reply	other threads:[~2026-09-09 15:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 14:57 [PATCH v3 00/13] media: iris: Migrate iommus to iris sub nodes Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 01/13] dt-bindings: media: qcom,venus: Add context bank subnodes to common schema Vikash Garodia
2026-09-10  6:59   ` Krzysztof Kozlowski
2026-09-11 17:43     ` Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 02/13] dt-bindings: media: qcom,sm8550-iris: Add context bank subnodes Vikash Garodia
2026-09-09 15:09   ` sashiko-bot
2026-09-09 20:57   ` Dmitry Baryshkov
2026-09-10  7:00   ` Krzysztof Kozlowski
2026-09-11 17:46     ` Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 03/13] dt-bindings: media: qcom,sm8750-iris: " Vikash Garodia
2026-09-09 21:32   ` Dmitry Baryshkov
2026-09-09 14:57 ` [PATCH v3 04/13] iommu: of_iommu: Add support for "iommu-ranges" on a device node Vikash Garodia
2026-09-09 15:12   ` sashiko-bot
2026-09-09 14:57 ` [PATCH v3 05/13] media: iris: Add non-pixel and pixel context bank devices Vikash Garodia
2026-09-09 15:16   ` sashiko-bot
2026-09-09 14:57 ` [PATCH v3 06/13] media: iris: Route buffers to the matching context bank device Vikash Garodia
2026-09-09 15:13   ` sashiko-bot [this message]
2026-09-09 14:57 ` [PATCH v3 07/13] media: iris: Skip DMA mask setup when the core device has no IOMMU Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 08/13] arm64: dts: qcom: hamoa: Add Iris context bank subnodes Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 09/13] arm64: dts: qcom: sm8550: " Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 10/13] arm64: dts: qcom: lemans: " Vikash Garodia
2026-09-09 15:22   ` sashiko-bot
2026-09-10  7:01   ` Krzysztof Kozlowski
2026-09-09 14:57 ` [PATCH v3 11/13] arm64: dts: qcom: monaco: " Vikash Garodia
2026-09-09 15:21   ` sashiko-bot
2026-09-10  7:03   ` Krzysztof Kozlowski
2026-09-11 17:53     ` Vikash Garodia
2026-09-09 14:57 ` [PATCH v3 12/13] arm64: dts: qcom: sm8650: " Vikash Garodia
2026-09-09 15:26   ` sashiko-bot
2026-09-09 14:57 ` [PATCH v3 13/13] arm64: dts: qcom: sm8750: " Vikash Garodia
2026-09-09 15:24   ` sashiko-bot

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=20260909151355.3A2FE1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=vikash.garodia@oss.qualcomm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.