Skip to contentSkip to conversation

soc_camera: avoid potential null-dereference

PATCH In review Andy Shevchenko 2 participants 5 messages Jan 7, 2015 – Jan 18, 2015 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 soc_camera: avoid potential null-dereference

We have to check the pointer before dereferencing it.

---
 drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/soc_camera/soc_camera.c +3 -1
index b3db51c..8c665c4 100644
@@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
 static int soc_camera_pdrv_probe(struct platform_device *pdev)
 {
 	struct soc_camera_desc *sdesc = pdev->dev.platform_data;
-	struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
+	struct soc_camera_subdev_desc *ssdd;
 	struct soc_camera_device *icd;
 	int ret;
 
@@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
 	if (!icd)
 		return -ENOMEM;
 
+	ssdd = &sdesc->subdev_desc;
+
 	/*
 	 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
 	 * regulator allocation is a dummy. They are actually requested by the
Signature · 1 line
1.8.3.101.g727a46b
#1 lore raw

Hi Andy,

Thanks for the patch. Will queue for the next pull request.

Regards
Guennadi

Quoted 32 lines · Andy Shevchenko

We have to check the pointer before dereferencing it.

---
 drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/soc_camera/soc_camera.c +3 -1
index b3db51c..8c665c4 100644
@@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
 static int soc_camera_pdrv_probe(struct platform_device *pdev)
 {
 	struct soc_camera_desc *sdesc = pdev->dev.platform_data;
-	struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
+	struct soc_camera_subdev_desc *ssdd;
 	struct soc_camera_device *icd;
 	int ret;
 
@@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
 	if (!icd)
 		return -ENOMEM;
 
+	ssdd = &sdesc->subdev_desc;
+
 	/*
 	 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
 	 * regulator allocation is a dummy. They are actually requested by the
Signature · 1 line
1.8.3.101.g727a46b
#2 lore raw
Quoted 3 lines · Guennadi Liakhovetski

Hi Andy,

Thanks for the patch. Will queue for the next pull request.

If you didn't do that please wait. It seems it has one more place with similar issue. Moreover, I would like to add a person's name who reported this.

Quoted 38 lines

Regards
Guennadi

Quoted 32 lines · Andy Shevchenko

We have to check the pointer before dereferencing it.

---
 drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/soc_camera/soc_camera.c +3 -2
index b3db51c..8c665c4 100644
@@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
 static int soc_camera_pdrv_probe(struct platform_device *pdev)
 {
      struct soc_camera_desc *sdesc = pdev->dev.platform_data;
-     struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
+     struct soc_camera_subdev_desc *ssdd;
      struct soc_camera_device *icd;
      int ret;
 
@@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
      if (!icd)
              return -ENOMEM;
 
+     ssdd = &sdesc->subdev_desc;
+
      /*
       * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
       * regulator allocation is a dummy. They are actually requested by the
--

1.8.3.101.g727a46b

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 3 lines · Guennadi Liakhovetski

Hi Andy,

Thanks for the patch. Will queue for the next pull request.

If you didn't do that please wait. It seems it has one more place with similar issue. Moreover, I would like to add a person's name who reported this.

Okay, the second one is false positive.
And

Quoted 45 lines
Quoted 31 lines

Regards
Guennadi

Quoted 24 lines · Andy Shevchenko

We have to check the pointer before dereferencing it.

---
 drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/soc_camera/soc_camera.c +1 -1
index b3db51c..8c665c4 100644
@@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
 static int soc_camera_pdrv_probe(struct platform_device *pdev)
 {
      struct soc_camera_desc *sdesc = pdev->dev.platform_data;
-     struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
+     struct soc_camera_subdev_desc *ssdd;
      struct soc_camera_device *icd;
      int ret;
 
@@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
      if (!icd)
              return -ENOMEM;
 
Quoted 8 lines
Quoted 8 lines
drivers/media/platform/soc_camera/soc_camera.c +2 -1
+     ssdd = &sdesc->subdev_desc;
+
      /*
       * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
       * regulator allocation is a dummy. They are actually requested by the
--

1.8.3.101.g727a46b

--
With Best Regards,
Andy Shevchenko

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Guennadi Liakhovetski
Quoted 3 lines · Guennadi Liakhovetski

Hi Andy,

Thanks for the patch. Will queue for the next pull request.

Actually no, I won't. I don't think there's currently a but there. the pointer isn't dereferenced before being checked. Only an address of a field in a struct, it's pointing to is calculated. So, if it's NULL just a small offset will be calculated, but no dereferencing will take place.

Thanks
Guennadi

Quoted 38 lines

Regards
Guennadi

Quoted 32 lines · Andy Shevchenko

We have to check the pointer before dereferencing it.

---
 drivers/media/platform/soc_camera/soc_camera.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/soc_camera/soc_camera.c +3 -1
index b3db51c..8c665c4 100644
@@ -2166,7 +2166,7 @@ static int soc_camera_video_start(struct soc_camera_device *icd)
 static int soc_camera_pdrv_probe(struct platform_device *pdev)
 {
 	struct soc_camera_desc *sdesc = pdev->dev.platform_data;
-	struct soc_camera_subdev_desc *ssdd = &sdesc->subdev_desc;
+	struct soc_camera_subdev_desc *ssdd;
 	struct soc_camera_device *icd;
 	int ret;
 
@@ -2177,6 +2177,8 @@ static int soc_camera_pdrv_probe(struct platform_device *pdev)
 	if (!icd)
 		return -ENOMEM;
 
+	ssdd = &sdesc->subdev_desc;
+
 	/*
 	 * In the asynchronous case ssdd->num_regulators == 0 yet, so, the below
 	 * regulator allocation is a dummy. They are actually requested by the
Signature · 1 line
1.8.3.101.g727a46b