Re: [PATCH v4 1/3] media: nxp: imx8-isi: Implement per-stream reference counting for multiplexed streams

[email protected]
Newsgroups dev.linux.lists.imx
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Pre-existing NULL pointer dereference in `mxc_isi_crossbar_xlate_streams` when no remote pad is linked.
- [Medium] Using `BIT()` macro on 64-bit stream masks causes undefined behavior on 32-bit architectures.
--

--- Patch [1]: [PATCH v4 1/3] media: nxp: imx8-isi: Implement per-stream reference counting for multiplexed streams ---
commit f312b9be3591414051fb03d9e8651437e1f95ef2
Author: Guoniu Zhou <[email protected]>

media: nxp: imx8-isi: Implement per-stream reference counting for multiplexed streams

The ISI crossbar needs to properly enable multiple streams from different
virtual channels on the same input pad. This commit implements per-stream
state tracking by storing the input index and stream mask in the mxc_isi_pipe
structure to properly manage hardware state on enable and disable operations.

> 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..d9146a361e7d7 100644
> --- a/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
> +++ b/drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c
> @@ -318,11 +318,26 @@ static int mxc_isi_crossbar_set_routing(struct v4l2_subdev *sd,

[ ... ]

>  static int mxc_isi_crossbar_enable_streams(struct v4l2_subdev *sd,
>  					   struct v4l2_subdev_state *state,
>  					   u32 pad, u64 streams_mask)
>  {
>  	struct mxc_isi_crossbar *xbar = to_isi_crossbar(sd);
> +	struct mxc_isi_pipe *pipe = &xbar->isi->pipes[pad - xbar->num_sinks];
>  	struct v4l2_subdev *remote_sd;
>  	struct mxc_isi_input *input;
>  	u64 sink_streams;

[Severity: High]
This isn't a bug introduced by this patch, but I noticed a potential NULL
pointer dereference in mxc_isi_crossbar_xlate_streams() which is called
from here.

If userspace configures routing that points to a disconnected sink pad and
then attempts to enable streams, media_pad_remote_pad_first() can return
NULL:

mxc_isi_crossbar_xlate_streams() {
	...
	pad = media_pad_remote_pad_first(&xbar->pads[sink_pad]);
	sd = media_entity_to_v4l2_subdev(pad->entity);
	if (!sd) {
	...
}

Does the immediate dereference of pad->entity crash the kernel before the
subsequent if (!sd) validation can handle the missing entity?

[Severity: Medium]
This is also a pre-existing issue in mxc_isi_crossbar_xlate_streams(), but I
noticed that BIT() is used on 64-bit stream masks:

mxc_isi_crossbar_xlate_streams() {
	...
		if (route->source_pad != source_pad ||
		    !(source_streams & BIT(route->source_stream)))
			continue;

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

Since source_streams and sink_streams are u64, and BIT() evaluates to a
32-bit unsigned long on 32-bit architectures, can this cause an
out-of-bounds shift or incorrect stream mask calculations if userspace
uses stream IDs of 32 or greater?

Should BIT_ULL() be used instead?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.