Skip to contentSkip to conversation

media: intel/ipu6: add csi2 port sanity check in notifier bound

PATCH In review [email protected] 2 participants 2 messages May 29, 2024

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

PATCH 2/2 media: intel/ipu6: add csi2 port sanity check in notifier bound

From: Bingbu Cao <[email protected]>

Invalid csi2 port will break the isys notifier bound ops as it is trying to access an invalid csi2 sub-device instance based on the port. It will trigger a mc warning, and it will cause the sensor driver to unbound an inexistent isys csi2 and crash. Adding a csi2 port sanity check, return error to avoid such case.

---
 drivers/media/pci/intel/ipu6/ipu6-isys.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/pci/intel/ipu6/ipu6-isys.c +8 -0
index 5992138c7290..997fbfbf2ea5 100644
@@ -676,8 +676,16 @@ static int isys_notifier_bound(struct v4l2_async_notifier *notifier,
 		container_of(notifier, struct ipu6_isys, notifier);
 	struct sensor_async_sd *s_asd =
 		container_of(asc, struct sensor_async_sd, asc);
+	u32 nports;
 	int ret;
 
+	nports = isys->pdata->ipdata->csi2.nports;
+	if (nports <= s_asd->csi2.port) {
+		dev_err(&isys->adev->auxdev.dev, "invalid csi2 port %u\n",
+			s_asd->csi2.port);
+		return -EINVAL;
+	}
+
 	ret = ipu_bridge_instantiate_vcm(sd->dev);
 	if (ret) {
 		dev_err(&isys->adev->auxdev.dev, "instantiate vcm failed\n");
Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi Bingbu,

Thanks for the patch.

Quoted 18 lines · On Wed, May 29, 2024 at 11:46:00AM +0800, [email protected] wrote:

From: Bingbu Cao <[email protected]>

Invalid csi2 port will break the isys notifier bound ops as it is trying to access an invalid csi2 sub-device instance based on the port. It will trigger a mc warning, and it will cause the sensor driver to unbound an inexistent isys csi2 and crash. Adding a csi2 port sanity check, return error to avoid such case.

---
 drivers/media/pci/intel/ipu6/ipu6-isys.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/pci/intel/ipu6/ipu6-isys.c +0 -0
index 5992138c7290..997fbfbf2ea5 100644

drivers/media/pci/intel/ipu6/ipu6-isys.c static int isys_notifier_bound(struct v4l2_async_notifier *notifier, · line 683

Quoted 8 lines
drivers/media/pci/intel/ipu6/ipu6-isys.c +3 -0
@@ -676,8 +676,16 @@ static int isys_notifier_bound(struct v4l2_async_notifier *notifier,
 		container_of(notifier, struct ipu6_isys, notifier);
 	struct sensor_async_sd *s_asd =
 		container_of(asc, struct sensor_async_sd, asc);
+	u32 nports;
 	int ret;
 
+	nports = isys->pdata->ipdata->csi2.nports;
+	if (nports <= s_asd->csi2.port) {

No need for a temporary variable. I'd also put the non-static value (s_asd->csi2.port) on the left side of the comparison.

Quoted 8 lines
drivers/media/pci/intel/ipu6/ipu6-isys.c +5 -0
+		dev_err(&isys->adev->auxdev.dev, "invalid csi2 port %u\n",
+			s_asd->csi2.port);
+		return -EINVAL;
+	}
+
 	ret = ipu_bridge_instantiate_vcm(sd->dev);
 	if (ret) {
 		dev_err(&isys->adev->auxdev.dev, "instantiate vcm failed\n");
Signature · 3 lines
Kind regards,

Sakari Ailus