media: nxp: isi: Check whether pad is non-NULL before access
Subsystems (3)
PATCH 1/1 media: nxp: isi: Check whether pad is non-NULL before access
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
---
Cc: Fabio Estevam <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]
--- drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +7 -1
@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, } pad =media_pad_remote_pad_first (&xbar->pads[sink_pad]); - sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { +dev_dbg (xbar->isi->dev, +"no pad connected to crossbar input %u\n" , + sink_pad); +return ERR_PTR (-EPIPE ); + } + sd =media_entity_to_v4l2_subdev (pad->entity);if (!sd) { dev_dbg(xbar->isi->dev, "no entity connected to crossbar input %u\n",
Signature · 1 line
2.42.0
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, · line 164
Quoted 4 lines · Marek Vasut
pad = media_pad_remote_pad_first(&xbar->pads[sink_pad]);drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +2
-1- sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { + dev_dbg(xbar->isi->dev,
Maybe dev_err() here instead?
Anyway:
Quoted 8 lines · Fabio Estevam
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, · line 164
Quoted 4 lines · Marek Vasut
pad = media_pad_remote_pad_first(&xbar->pads[sink_pad]);drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +2
-1- sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { + dev_dbg(xbar->isi->dev,Maybe
dev_err()here instead?
That dev_dbg() is aligned with the prints in the rest of the function and it's not like kernel should do dev_err() into kernel log every time userspace does something wrong.
Quoted 3 lines
Anyway:
Reviewed-by Fabio Estevam <[email protected]>
Thanks !
Laurent Pinchart
maintainerQuoted 8 lines · Marek Vasut
Quoted 7 lines · Fabio Estevam
Quoted 4 lines · Marek Vasut
pad = media_pad_remote_pad_first(&xbar->pads[sink_pad]);drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +2
-1- sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { + dev_dbg(xbar->isi->dev,
Quoted 5 lines
Quoted 1 line
Maybe
dev_err()here instead?That
dev_dbg()is aligned with the prints in the rest of the function and it's not like kernel should dodev_err()into kernel log every time userspace does something wrong.
We usually use dev_dbg() for errors that can be easily triggered from userspace, to avoid giving unpriviledged processes an easy way to flood the kernel log.
Quoted 5 lines
Quoted 3 lines
Anyway:
Reviewed-by Fabio Estevam <[email protected]>Thanks !
Signature · 3 lines
Regards, Laurent Pinchart
Kieran Bingham
Reviewed-byQuoting Laurent Pinchart (2023-12-03 17:00:57)
Quoted 11 lines · Marek Vasut
Quoted 10 lines · Fabio Estevam
Quoted 8 lines · Marek Vasut
drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, · line 164
Quoted 5 lines
pad = media_pad_remote_pad_first(&xbar->pads[sink_pad]);drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +2
-1- sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { + dev_dbg(xbar->isi->dev,Maybe
dev_err()here instead?
Quoted 7 lines
Quoted 3 lines
That
dev_dbg()is aligned with the prints in the rest of the function and it's not like kernel should dodev_err()into kernel log every time userspace does something wrong.We usually use
dev_dbg()for errors that can be easily triggered from userspace, to avoid giving unpriviledged processes an easy way to flood the kernel log.
When this call returns it will also report a dev_err "Failed to enable pipe":
[ 56.806321] mxc-isi 32e00000.isi: no pad connecxted to crossbar input 0 [ 56.813655] mxc-isi 32e00000.isi: Failed to enable pipe 0
Personally - I'd make this print dev_err so the /reason/ we failed to enable the pipe is also stated.
But I can confirm this is a bug and fairly easily trigged by attempting to capture from the ISI through the libcamera simple pipeline handler, which (I believe) does not do any route handling at present.
Which ever log level:
And this needs to go to stable, as this caused a null-pointer-deref for me on a v6.6 tree.
--
Kieran
Quoted 16 lines
Quoted 6 lines
Quoted 4 lines
Anyway:
Reviewed-by Fabio Estevam <[email protected]>Thanks !
Signature · 8 lines
Regards, Laurent Pinchart _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Laurent Pinchart
maintainerHi Marek,
Thank you for the patch.
Quoted 3 lines · Marek Vasut
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
Could you share more information about how to misconfigure the routing ?
Quoted 36 lines
Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")Signed-off-by Marek Vasut <[email protected]>---
Cc: Fabio Estevam <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +7
-1@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, } pad =media_pad_remote_pad_first (&xbar->pads[sink_pad]); - sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { +dev_dbg (xbar->isi->dev, +"no pad connected to crossbar input %u\n" , + sink_pad); +return ERR_PTR (-EPIPE ); + } + sd =media_entity_to_v4l2_subdev (pad->entity);if (!sd) { dev_dbg(xbar->isi->dev, "no entity connected to crossbar input %u\n",
Signature · 3 lines
Regards, Laurent Pinchart
Quoting Laurent Pinchart (2023-12-03 16:59:59)
Quoted 10 lines
Hi Marek,
Thank you for the patch.
Quoted 3 lines · Marek Vasut
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
Could you share more information about how to misconfigure the routing ?
You simply do 'nothing'.
--
Kieran
Quoted 42 lines
Quoted 37 lines
Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")Signed-off-by Marek Vasut <[email protected]>---
Cc: Fabio Estevam <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +7
-1@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, } pad =media_pad_remote_pad_first (&xbar->pads[sink_pad]); - sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { +dev_dbg (xbar->isi->dev, +"no pad connected to crossbar input %u\n" , + sink_pad); +return ERR_PTR (-EPIPE ); + } + sd =media_entity_to_v4l2_subdev (pad->entity);if (!sd) { dev_dbg(xbar->isi->dev, "no entity connected to crossbar input %u\n",Signature · 3 lines
Regards, Laurent Pinchart
Laurent Pinchart
maintainerQuoted 5 lines · Kieran Bingham
Quoting Laurent Pinchart (2023-12-03 16:59:59)
Quoted 4 lines
Hi Marek,
Thank you for the patch.
Quoted 8 lines
Quoted 6 lines · Marek Vasut
Quoted 3 lines
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
Could you share more information about how to misconfigure the routing ?
You simply do 'nothing'.
The default configuration should be working one. I think that should then be fixed too (in a separate patch).
Quoted 41 lines
Quoted 41 lines
Quoted 36 lines
Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")Signed-off-by Marek Vasut <[email protected]>---
Cc: Fabio Estevam <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +7
-1@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, } pad =media_pad_remote_pad_first (&xbar->pads[sink_pad]); - sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { +dev_dbg (xbar->isi->dev, +"no pad connected to crossbar input %u\n" , + sink_pad); +return ERR_PTR (-EPIPE ); + } + sd =media_entity_to_v4l2_subdev (pad->entity);if (!sd) { dev_dbg(xbar->isi->dev, "no entity connected to crossbar input %u\n",Signature · 3 lines
Regards, Laurent Pinchart
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 11 lines · Laurent Pinchart
Quoted 10 lines · Kieran Bingham
Quoting Laurent Pinchart (2023-12-03 16:59:59)
Quoted 9 lines
Hi Marek,
Thank you for the patch.
Quoted 3 lines · Marek Vasut
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Could you share more information about how to misconfigure the routing ?
You simply do 'nothing'.
The default configuration should be working one. I think that should then be fixed too (in a separate patch).
I managed to reproduce the issue (I had to heavily hack libcamera, by default it would reject incorrect configurations before triggering the kernel bug). The default configuration of the crossbar switch is fine, this patch is the right fix.
I'd like to expand the commit message with a clearer description of the erronous configuration. Marek, are you fine with the following commit message ?
--------
When translating source to sink streams in the crossbar subdev, the driver tries to locate the remote subdev connected to the sink pad. The remote pad may be NULL, if userspace tries to enable a stream that ends at an unconnected crossbar sink. When that occurs, the driver dereferences the NULL pad, leading to a crash.
Prevent the crash by checking if the pad is NULL before using it, and return an error if it is.
--------
If so I'll update it locally, no need for a new version.
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")Signed-off-by Marek Vasut <[email protected]>---
Cc: Fabio Estevam <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +7
-1@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, } pad =media_pad_remote_pad_first (&xbar->pads[sink_pad]); - sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { +dev_dbg (xbar->isi->dev, +"no pad connected to crossbar input %u\n" , + sink_pad); +return ERR_PTR (-EPIPE ); + } + sd =media_entity_to_v4l2_subdev (pad->entity);if (!sd) { dev_dbg(xbar->isi->dev, "no entity connected to crossbar input %u\n",
Signature · 3 lines
Regards, Laurent Pinchart
Laurent Pinchart
maintainerQuoted 16 lines · Laurent Pinchart
Quoted 15 lines · Laurent Pinchart
Quoted 13 lines · Kieran Bingham
Quoting Laurent Pinchart (2023-12-03 16:59:59)
Quoted 10 lines
Hi Marek,
Thank you for the patch.
Quoted 3 lines · Marek Vasut
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
Could you share more information about how to misconfigure the routing ?
You simply do 'nothing'.
Quoted 7 lines
Quoted 2 lines
The default configuration should be working one. I think that should then be fixed too (in a separate patch).
I managed to reproduce the issue (I had to heavily hack libcamera, by default it would reject incorrect configurations before triggering the kernel bug). The default configuration of the crossbar switch is fine, this patch is the right fix.
Actually, I think this should be fixed by catching the pipeline misconfiguration at validation time, not when enabling streams. It would make this patch redundant, but I think we can still merge it for additional safety, especially as it may take more time to implement the validation time check.
Quoted 55 lines
I'd like to expand the commit message with a clearer description of the erronous configuration. Marek, are you fine with the following commit message ?
--------
When translating source to sink streams in the crossbar subdev, the driver tries to locate the remote subdev connected to the sink pad. The remote pad may be NULL, if userspace tries to enable a stream that ends at an unconnected crossbar sink. When that occurs, the driver dereferences the NULL pad, leading to a crash.Prevent the crash by checking if the pad is NULL before using it, and return an error if it is.
--------If so I'll update it locally, no need for a new version.
Reviewed-by Laurent Pinchart <[email protected]>Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Quoted 36 lines
Fixes cf21f328fcaf ("media: nxp: Add i.MX8 ISI driver")Signed-off-by Marek Vasut <[email protected]>---
Cc: Fabio Estevam <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Mauro Carvalho Chehab <[email protected]>
Cc: NXP Linux Team <[email protected]>
Cc: Pengutronix Kernel Team <[email protected]>
Cc: Sascha Hauer <[email protected]>
Cc: Shawn Guo <[email protected]>
Cc: [email protected]
Cc: [email protected]--- drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/media/platform/nxp/imx8-isi/imx8-isi-crossbar.c +7
-1@@ -160,8 +160,14 @@ mxc_isi_crossbar_xlate_streams(struct mxc_isi_crossbar *xbar, } pad =media_pad_remote_pad_first (&xbar->pads[sink_pad]); - sd =media_entity_to_v4l2_subdev (pad->entity); +if (!pad) { +dev_dbg (xbar->isi->dev, +"no pad connected to crossbar input %u\n" , + sink_pad); +return ERR_PTR (-EPIPE ); + } + sd =media_entity_to_v4l2_subdev (pad->entity);if (!sd) { dev_dbg(xbar->isi->dev, "no entity connected to crossbar input %u\n",
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 35 lines · Laurent Pinchart
Quoted 11 lines · Laurent Pinchart
Quoted 10 lines · Kieran Bingham
Quoting Laurent Pinchart (2023-12-03 16:59:59)
Quoted 9 lines
Hi Marek,
Thank you for the patch.
Quoted 3 lines · Marek Vasut
The pad can be NULL if media controller routing is not set up correctly. Check whether the pad is NULL before using it, otherwise it is possible to achieve NULL pointer dereference.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Could you share more information about how to misconfigure the routing ?
You simply do 'nothing'.
The default configuration should be working one. I think that should then be fixed too (in a separate patch).
I managed to reproduce the issue (I had to heavily hack libcamera, by default it would reject incorrect configurations before triggering the kernel bug). The default configuration of the crossbar switch is fine, this patch is the right fix.
I'd like to expand the commit message with a clearer description of the erronous configuration. Marek, are you fine with the following commit message ?
--------
When translating source to sink streams in the crossbar subdev, the driver tries to locate the remote subdev connected to the sink pad. The remote pad may be NULL, if userspace tries to enable a stream that ends at an unconnected crossbar sink. When that occurs, the driver dereferences the NULL pad, leading to a crash.
Quoted 7 lines
Prevent the crash by checking if the pad is NULL before using it, and return an error if it is.
--------If so I'll update it locally, no need for a new version.
Reviewed-by Laurent Pinchart <[email protected]>
Sure, go for it.