Skip to contentSkip to conversation

media: imx: imx-mipi-csis: Fix null pointer dereference when link is not set

PATCH In review Alexander Shiyan 3 participants 7 messages Oct 6, 2023 – Oct 11, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: imx: imx-mipi-csis: Fix null pointer dereference when link is not set

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

---
 drivers/media/platform/nxp/imx-mipi-csis.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/nxp/imx-mipi-csis.c +3 -0
index 5f93712bf485..df5a159b2d39 100644
@@ -595,6 +595,9 @@ static int mipi_csis_calculate_params(struct mipi_csis_device *csis,
 	s64 link_freq;
 	u32 lane_rate;
 
+	if (!csis->src_sd)
+		return -EINVAL;
+
 	/* Calculate the line rate from the pixel rate. */
 	link_freq = v4l2_get_link_freq(csis->src_sd->ctrl_handler,
 				       csis_fmt->width,
Signature · 1 line
2.39.1
#1 lore raw

Hi Alexander,

Quoted 2 lines · Alexander Shiyan

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

That would seem like an understatement.

Any idea when this was introduced (and which patch did), Fixes: and Cc:
stable should be added if this is already in a release.

Quoted 20 lines
---
 drivers/media/platform/nxp/imx-mipi-csis.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/nxp/imx-mipi-csis.c +3 -0
index 5f93712bf485..df5a159b2d39 100644
@@ -595,6 +595,9 @@ static int mipi_csis_calculate_params(struct mipi_csis_device *csis,
 	s64 link_freq;
 	u32 lane_rate;
 
+	if (!csis->src_sd)
+		return -EINVAL;
+
 	/* Calculate the line rate from the pixel rate. */
 	link_freq = v4l2_get_link_freq(csis->src_sd->ctrl_handler,
 				       csis_fmt->width,
Signature · 3 lines
Regards,

Sakari Ailus
maintainer
#2 lore raw
Quoted 8 lines · Sakari Ailus
Quoted 2 lines · Alexander Shiyan

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

That would seem like an understatement.

Any idea when this was introduced (and which patch did), Fixes: and Cc:
stable should be added if this is already in a release.

It's actually an issue in the pipeline validation code in the V4L2 core. The link is marked as MUST_CONNECT, but that isn't handled properly :-( It's been on my todo list for a while but I haven't had time to get to it. Feel free to give it a go.

Quoted 19 lines
Quoted 19 lines
---
 drivers/media/platform/nxp/imx-mipi-csis.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/media/platform/nxp/imx-mipi-csis.c +3 -0
index 5f93712bf485..df5a159b2d39 100644
@@ -595,6 +595,9 @@ static int mipi_csis_calculate_params(struct mipi_csis_device *csis,
 	s64 link_freq;
 	u32 lane_rate;
 
+	if (!csis->src_sd)
+		return -EINVAL;
+
 	/* Calculate the line rate from the pixel rate. */
 	link_freq = v4l2_get_link_freq(csis->src_sd->ctrl_handler,
 				       csis_fmt->width,
Signature · 3 lines
Regards,

Laurent Pinchart
#3 lore raw
Quoted 7 lines · Laurent Pinchart
Quoted 6 lines · Sakari Ailus
Quoted 2 lines · Alexander Shiyan

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

That would seem like an understatement.

Quoted 7 lines
Quoted 2 lines

Any idea when this was introduced (and which patch did), Fixes: and Cc:
stable should be added if this is already in a release.

It's actually an issue in the pipeline validation code in the V4L2 core. The link is marked as MUST_CONNECT, but that isn't handled properly :-( It's been on my todo list for a while but I haven't had time to get to it. Feel free to give it a go.

What's wrong there? It used to work at least...

Signature · 1 line
Sakari Ailus
maintainer
#4 lore raw
Quoted 11 lines · Sakari Ailus
Quoted 10 lines · Laurent Pinchart
Quoted 8 lines · Sakari Ailus
Quoted 2 lines · Alexander Shiyan

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

That would seem like an understatement.

Any idea when this was introduced (and which patch did), Fixes: and Cc:
stable should be added if this is already in a release.

Quoted 6 lines
Quoted 4 lines

It's actually an issue in the pipeline validation code in the V4L2 core. The link is marked as MUST_CONNECT, but that isn't handled properly :-( It's been on my todo list for a while but I haven't had time to get to it. Feel free to give it a go.

What's wrong there? It used to work at least...

It's called a regression :-) If I recall correctly, if the pad is not connected, it's not added to the list of pads to check, and the MUST_CONNECT flag is not checked.

Signature · 3 lines
Regards,

Laurent Pinchart
#5 lore raw
Quoted 17 lines · Laurent Pinchart
Quoted 16 lines · Sakari Ailus
Quoted 14 lines · Laurent Pinchart
Quoted 8 lines · Sakari Ailus
Quoted 2 lines · Alexander Shiyan

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

That would seem like an understatement.

Any idea when this was introduced (and which patch did), Fixes: and Cc:
stable should be added if this is already in a release.

It's actually an issue in the pipeline validation code in the V4L2 core. The link is marked as MUST_CONNECT, but that isn't handled properly :-( It's been on my todo list for a while but I haven't had time to get to it. Feel free to give it a go.

Quoted 5 lines
Quoted 1 line

What's wrong there? It used to work at least...

It's called a regression :-) If I recall correctly, if the pad is not connected, it's not added to the list of pads to check, and the MUST_CONNECT flag is not checked.

This has potential for other similar issues in a number of drivers. I suppose this broke with the graph traversal changes ~ a year ago?

Signature · 1 line
Sakari Ailus
maintainer
#6 lore raw
Quoted 18 lines · Sakari Ailus
Quoted 17 lines · Laurent Pinchart
Quoted 16 lines · Sakari Ailus
Quoted 14 lines · Laurent Pinchart
Quoted 8 lines · Sakari Ailus
Quoted 2 lines · Alexander Shiyan

Let's add a check for src_sd before using it.
The link may not be set, in which case the call to this function will fail.

That would seem like an understatement.

Any idea when this was introduced (and which patch did), Fixes: and Cc:
stable should be added if this is already in a release.

It's actually an issue in the pipeline validation code in the V4L2 core. The link is marked as MUST_CONNECT, but that isn't handled properly :-( It's been on my todo list for a while but I haven't had time to get to it. Feel free to give it a go.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

What's wrong there? It used to work at least...

It's called a regression :-) If I recall correctly, if the pad is not connected, it's not added to the list of pads to check, and the MUST_CONNECT flag is not checked.

This has potential for other similar issues in a number of drivers.

Indeed, which is why it should be fixed there.

Quoted 1 line

I suppose this broke with the graph traversal changes ~ a year ago?

I assume so, yes.

Signature · 3 lines
Regards,

Laurent Pinchart