Skip to contentSkip to conversation

media: v4l: subdev: Make link validation safer

PATCH Superseded Sakari Ailus 5 participants 10 messages Mar 9, 2023 – Mar 12, 2023 Media (V4L/DVB)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l: subdev: Make link validation safer

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/media/v4l2-core/v4l2-subdev.c +11 -0
index 1bebcda2bd20c..dd911180ec899 100644
@@ -1209,6 +1209,17 @@ int v4l2_subdev_link_validate(struct media_link *link)
 	struct v4l2_subdev_state *source_state, *sink_state;
 	int ret;
 
+	if (!is_media_entity_v4l2_subdev(link->sink->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->sink->entity->name);
+		return 0;
+	}
+	if (!is_media_entity_v4l2_subdev(link->source->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->source->entity->name);
+		return 0;
+	}
+
 	sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
 	source_sd = media_entity_to_v4l2_subdev(link->source->entity);
 
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw

Hi Sakari,

Quoted 26 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>
---
  drivers/media/v4l2-core/v4l2-subdev.c | 11 +++++++++++
  1 file changed, 11 insertions(+)
drivers/media/v4l2-core/v4l2-subdev.c +4 -0
index 1bebcda2bd20c..dd911180ec899 100644
@@ -1209,6 +1209,17 @@ int v4l2_subdev_link_validate(struct media_link *link)
  	struct v4l2_subdev_state *source_state, *sink_state;
  	int ret;
 
+	if (!is_media_entity_v4l2_subdev(link->sink->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->sink->entity->name);
+		return 0;

drivers/media/v4l2-core/v4l2-subdev.c int v4l2_subdev_link_validate(struct media_link *link) · line 1225

Quoted 10 lines
drivers/media/v4l2-core/v4l2-subdev.c +7 -0
+	}
+	if (!is_media_entity_v4l2_subdev(link->source->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->source->entity->name);
+		return 0;
+	}
+
  	sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
  	source_sd = media_entity_to_v4l2_subdev(link->source->entity);
 

I think this is supposed to be v2. You missed my RB, but here it is again:

Also, the commit message says "debug message", but it's a warn now.

Tomi

#2 lore raw
Quoted 5 lines · Tomi Valkeinen

I think this is supposed to be v2. You missed my RB, but here it is again:

Also, the commit message says "debug message", but it's a warn now.

Thanks, I'll address this while applying it.

Signature · 1 line
Sakari Ailus
#3 lore raw
In reply to Sakari Ailus
Quoted 10 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>

This was intended to be v2. V1 is here:

<URL:https://lore.kernel.org/linux-media/[email protected]/T/#m12c7e39e154a799b1034388d0c63ce0f65979a1b>

Signature · 1 line
Sakari Ailus
#4 lore raw
In reply to Sakari Ailus

Hi Sakari,

Quoted 10 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>

FWIW you have my Reported-by in there twice now ...

Regards,

Hans

Quoted 26 lines
---
 drivers/media/v4l2-core/v4l2-subdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/media/v4l2-core/v4l2-subdev.c +11 -0
index 1bebcda2bd20c..dd911180ec899 100644
@@ -1209,6 +1209,17 @@ int v4l2_subdev_link_validate(struct media_link *link)
 	struct v4l2_subdev_state *source_state, *sink_state;
 	int ret;
 
+	if (!is_media_entity_v4l2_subdev(link->sink->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->sink->entity->name);
+		return 0;
+	}
+	if (!is_media_entity_v4l2_subdev(link->source->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->source->entity->name);
+		return 0;
+	}
+
 	sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
 	source_sd = media_entity_to_v4l2_subdev(link->source->entity);
 
#5 lore raw
Quoted 9 lines · Hans de Goede

Hi Sakari,

Quoted 6 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Quoted 6 lines
Quoted 4 lines
Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>

FWIW you have my Reported-by in there twice now ...

Ah, thanks. I'll drop the first tag.

Signature · 1 line
Sakari Ailus
#6 lore raw
Quoted 10 lines · Sakari Ailus
Quoted 9 lines · Hans de Goede

Hi Sakari,

Quoted 6 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>

FWIW you have my Reported-by in there twice now ...

Ah, thanks. I'll drop the first tag.

$ git grep Reported-and-tested-by Documentation/
Documentation/process/maintainer-tip.rst:Please do not use combined tags, e.g. ``Reported-and-tested-by``, as

Tomi

#7 lore raw
Quoted 16 lines · Tomi Valkeinen
Quoted 15 lines · Sakari Ailus
Quoted 14 lines · Hans de Goede

Hi Sakari,

Quoted 10 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

FWIW you have my Reported-by in there twice now ...

Ah, thanks. I'll drop the first tag.

$ git grep Reported-and-tested-by Documentation/
Documentation/process/maintainer-tip.rst:Please do not use combined tags, e.g. ``Reported-and-tested-by``, as

Uh-oh. Well, I'll just split that. Thanks.

Signature · 1 line
Sakari Ailus
#8 lore raw

Hi,

Quoted 17 lines · Sakari Ailus
Quoted 16 lines · Tomi Valkeinen
Quoted 15 lines · Sakari Ailus
Quoted 14 lines · Hans de Goede

Hi Sakari,

Quoted 10 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

FWIW you have my Reported-by in there twice now ...

Ah, thanks. I'll drop the first tag.

$ git grep Reported-and-tested-by Documentation/
Documentation/process/maintainer-tip.rst:Please do not use combined tags, e.g. ``Reported-and-tested-by``, as

Uh-oh. Well, I'll just split that. Thanks.

This is new to me too, but good to know. I'll try to get rid of the habbit of using the combined tags then.

Regards,

Hans

Reviewed-by on v1 1/1
#9 lore raw
In reply to Sakari Ailus

Hi Sakari,

Thank you for the patch.

Quoted 19 lines · Sakari Ailus

Link validation currently accesses invalid pointers if the link passed to it is not between two sub-devices. This is of course a driver bug.

Ignore the error but print a debug message, as this is how it used to work previously.

Fixes a6b995ed03ff ("media: subdev: use streams in v4l2_subdev_link_validate()")
Reported-and-tested-by Hans de Goede <[email protected]>
---
 drivers/media/v4l2-core/v4l2-subdev.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/media/v4l2-core/v4l2-subdev.c +0 -0
index 1bebcda2bd20c..dd911180ec899 100644

drivers/media/v4l2-core/v4l2-subdev.c int v4l2_subdev_link_validate(struct media_link *link) · line 1214

Quoted 6 lines
drivers/media/v4l2-core/v4l2-subdev.c +3 -0
@@ -1209,6 +1209,17 @@ int v4l2_subdev_link_validate(struct media_link *link)
 	struct v4l2_subdev_state *source_state, *sink_state;
 	int ret;
 
+	if (!is_media_entity_v4l2_subdev(link->sink->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->sink->entity->name);

Printing the whole link would make it easier to debug the problem:

		pr_warn_once("sink of link '%s':%u->'%s':%u is not a V4L2 sub-device, driver bug!\n",
			     link->source->entity->name, link->source->index);
			     link->sink->entity->name, link->sink->index);

Same below. With this, and the other comments in the mail thread addressed,

Quoted 11 lines
drivers/media/v4l2-core/v4l2-subdev.c +8 -0
+		return 0;
+	}
+	if (!is_media_entity_v4l2_subdev(link->source->entity)) {
+		pr_warn_once("entity \"%s\" not a V4L2 sub-device, driver bug!\n",
+			     link->source->entity->name);
+		return 0;
+	}
+
 	sink_sd = media_entity_to_v4l2_subdev(link->sink->entity);
 	source_sd = media_entity_to_v4l2_subdev(link->source->entity);
 
Signature · 3 lines
Regards,

Laurent Pinchart