Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Guoniu Zhou" <guoniu.zhou@oss.nxp.com>
Cc: media-ci@linuxtv.org, imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v2 1/6] media: nxp: imx8-isi: Fix stream ID validation bypass in crossbar routing
Date: Mon, 20 Jul 2026 03:43:08 +0000	[thread overview]
Message-ID: <20260720034309.2FD4E1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260720-isi-v2-1-45845bc5d4fa@oss.nxp.com>

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

Pre-existing issues:
- [High] Undefined behavior from bit shift overflow when using BIT() macro on user-controlled stream IDs on 32-bit architectures.
- [High] Missing V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX flag in routing validation allows stream mixing, violating driver assumptions and causing pipeline state corruption.
--

--- Patch [1]: [PATCH v2 1/6] media: nxp: imx8-isi: Fix stream ID validation bypass in crossbar routing ---
commit c48b83ab851ce7535e8d8249fb85d35c57bb63e1
Author: Guoniu Zhou <guoniu.zhou@oss.nxp.com>

media: nxp: imx8-isi: Fix stream ID validation bypass in crossbar routing

The crossbar routing validation has a bug where it validates the wrong
routing table, allowing userspace to bypass validation entirely. This
commit fixes it by validating the routing table that will actually be
applied.

> diff --git a/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c b/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
> index c580c831972ec..84871bceb31db 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
> @@ -107,7 +107,7 @@ static int __mxc_isi_crossbar_set_routing(struct v4l2_subdev *sd,
>  		return ret;

[Severity: High]
This isn't a bug introduced by this patch, but does the routing validation
here miss the V4L2_SUBDEV_ROUTING_NO_SOURCE_STREAM_MIX flag?

The validation in __mxc_isi_crossbar_set_routing() does not pass this
flag:

imx8-isi-crossbar.c:__mxc_isi_crossbar_set_routing() {
    ...
	ret = v4l2_subdev_routing_validate(sd, routing,
					   V4L2_SUBDEV_ROUTING_NO_N_TO_1);
    ...
}

This allows stream mixing, violating an explicit assumption in
mxc_isi_crossbar_xlate_streams(), where the driver silently overwrites
sink_pad for matching routes:

imx8-isi-crossbar.c:mxc_isi_crossbar_xlate_streams() {
    ...
	/*
	 * Translate the source pad and streams to the sink side. The routing
	 * validation forbids stream merging, so all matching entries in the
	 * routing table are guaranteed to have the same sink pad.
	 */
    ...
		sink_streams |= BIT(route->sink_stream);
		sink_pad = route->sink_pad;
    ...
}

If userspace configures a routing table via VIDIOC_SUBDEV_S_ROUTING with
multiple routes from different sink pads ending at the same source pad,
mxc_isi_crossbar_enable_streams() will only enable streams on the last
matched remote subdevice, leaving others disabled and leading to hardware
pipeline hangs.

>  
>  	/* The memory input can be routed to the first pipeline only. */
> -	for_each_active_route(&state->routing, route) {
> +	for_each_active_route(routing, route) {

[Severity: High]
This is a pre-existing issue, but can using the BIT() macro on
user-controlled stream IDs cause undefined behavior on 32-bit architectures?

The core framework limits stream IDs to 63 (V4L2_SUBDEV_MAX_STREAM_ID), but
the driver uses BIT() on these IDs in mxc_isi_crossbar_xlate_streams():

imx8-isi-crossbar.c:mxc_isi_crossbar_xlate_streams() {
    ...
		if (route->source_pad != source_pad ||
		    !(source_streams & BIT(route->source_stream)))
			continue;

		sink_streams |= BIT(route->sink_stream);
    ...
}

On 32-bit architectures, unsigned long is 32 bits. If userspace provides a
routing table via VIDIOC_SUBDEV_S_ROUTING with stream IDs >= 32, this
causes a shift out of bounds. This can result in incorrect bitmasks,
causing the driver to start or stop the wrong hardware streams and hang
the pipeline.

>  		if (route->sink_pad == xbar->num_sinks - 1 &&
>  		    route->source_pad != xbar->num_sinks) {
>  			dev_dbg(xbar->isi->dev,

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260720-isi-v2-0-45845bc5d4fa@oss.nxp.com?part=1

  reply	other threads:[~2026-07-20  3:43 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-20  3:34 [PATCH v2 0/6] imx8-isi: Bug fixes and format support enhancements Guoniu Zhou
2026-07-20  3:34 ` [PATCH v2 1/6] media: nxp: imx8-isi: Fix stream ID validation bypass in crossbar routing Guoniu Zhou
2026-07-20  3:43   ` sashiko-bot [this message]
2026-07-20 15:09   ` Frank Li
2026-07-20 17:30   ` Laurent Pinchart
2026-07-20  3:34 ` [PATCH v2 2/6] media: nxp: imx8-isi: Add stream ID validation for " Guoniu Zhou
2026-07-20  3:42   ` sashiko-bot
2026-07-20 15:11   ` Frank Li
2026-07-20 17:32     ` Laurent Pinchart
2026-07-20  3:34 ` [PATCH v2 3/6] media: nxp: imx8-isi: Fix per-stream reference counting for multiplexed streams Guoniu Zhou
2026-07-20  3:42   ` sashiko-bot
2026-07-20 15:34   ` Frank Li
2026-07-20 21:03   ` Laurent Pinchart
2026-07-20  3:34 ` [PATCH v2 4/6] media: nxp: imx8-isi: Add 16-bit raw Bayer format support guoniu.zhou
2026-07-20 21:15   ` Laurent Pinchart
2026-07-20  3:34 ` [PATCH v2 5/6] media: nxp: imx8-isi: Correct color map between V4L2 and ISI Guoniu Zhou
2026-07-20 15:37   ` Frank Li
2026-07-20 17:40   ` Laurent Pinchart
2026-07-20 23:18     ` Laurent Pinchart
2026-07-20  3:34 ` [PATCH v2 6/6] media: nxp: imx8-isi: Add additional 32-bit RGB format support Guoniu Zhou
2026-07-21  0:21   ` Laurent Pinchart
2026-07-21  0:32 ` [PATCH v2 0/6] imx8-isi: Bug fixes and format support enhancements Laurent Pinchart
2026-07-21  0:35   ` Laurent Pinchart

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=20260720034309.2FD4E1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=guoniu.zhou@oss.nxp.com \
    --cc=imx@lists.linux.dev \
    --cc=media-ci@linuxtv.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