linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check
@ 2020-04-14 13:21 peng.fan
  2020-04-14 13:32 ` Fabio Estevam
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: peng.fan @ 2020-04-14 13:21 UTC (permalink / raw)
  To: shawnguo, s.hauer, jassisinghbrar, o.rempel, leonard.crestez
  Cc: kernel, festevam, linux-imx, Anson.Huang, aisheng.dong,
	linux-arm-kernel, linux-kernel, Peng Fan

From: Peng Fan <peng.fan@nxp.com>

The i.MX8 SCU message header size is the number of "u32" elements,
not "u8", so fix the check.

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1461658 ("Memory - corruptions")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---

V2:
 Drop parenthesis, add comment, update err msg.

 drivers/mailbox/imx-mailbox.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c
index 7906624a731c..fd3a9a60416d 100644
--- a/drivers/mailbox/imx-mailbox.c
+++ b/drivers/mailbox/imx-mailbox.c
@@ -154,12 +154,17 @@ static int imx_mu_scu_tx(struct imx_mu_priv *priv,
 
 	switch (cp->type) {
 	case IMX_MU_TYPE_TX:
-		if (msg->hdr.size > sizeof(*msg)) {
+		/*
+		 * msg->hdr.size specifies the number of u32 words while
+		 * sizeof yields bytes.
+		 */
+
+		if (msg->hdr.size > sizeof(*msg) / 4) {
 			/*
 			 * The real message size can be different to
 			 * struct imx_sc_rpc_msg_max size
 			 */
-			dev_err(priv->dev, "Exceed max msg size (%zu) on TX, got: %i\n", sizeof(*msg), msg->hdr.size);
+			dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on TX; got: %i bytes\n", sizeof(*msg), msg->hdr.size << 2);
 			return -EINVAL;
 		}
 
@@ -198,9 +203,8 @@ static int imx_mu_scu_rx(struct imx_mu_priv *priv,
 	imx_mu_xcr_rmw(priv, 0, IMX_MU_xCR_RIEn(0));
 	*data++ = imx_mu_read(priv, priv->dcfg->xRR[0]);
 
-	if (msg.hdr.size > sizeof(msg)) {
-		dev_err(priv->dev, "Exceed max msg size (%zu) on RX, got: %i\n",
-			sizeof(msg), msg.hdr.size);
+	if (msg.hdr.size > sizeof(msg) / 4) {
+		dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on RX; got: %i bytes\n", sizeof(msg), msg.hdr.size << 2);
 		return -EINVAL;
 	}
 
-- 
2.16.4


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check
  2020-04-14 13:21 [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check peng.fan
@ 2020-04-14 13:32 ` Fabio Estevam
  2020-04-14 13:34   ` Peng Fan
  2020-04-14 19:54 ` Leonard Crestez
  2020-04-15  5:55 ` Oleksij Rempel
  2 siblings, 1 reply; 5+ messages in thread
From: Fabio Estevam @ 2020-04-14 13:32 UTC (permalink / raw)
  To: Peng Fan
  Cc: Shawn Guo, Sascha Hauer, jassisinghbrar, Oleksij Rempel,
	Leonard Crestez, Sascha Hauer, NXP Linux Team, Yongcai Huang,
	Dong Aisheng,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-kernel

Hi Peng,

On Tue, Apr 14, 2020 at 10:30 AM <peng.fan@nxp.com> wrote:
>
> From: Peng Fan <peng.fan@nxp.com>
>
> The i.MX8 SCU message header size is the number of "u32" elements,
> not "u8", so fix the check.

Since this is a fix, please add a Fixes tag

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check
  2020-04-14 13:32 ` Fabio Estevam
@ 2020-04-14 13:34   ` Peng Fan
  0 siblings, 0 replies; 5+ messages in thread
From: Peng Fan @ 2020-04-14 13:34 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Shawn Guo, Sascha Hauer, jassisinghbrar, Oleksij Rempel,
	Leonard Crestez, Sascha Hauer, dl-linux-imx, Anson Huang,
	Aisheng Dong,
	moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
	linux-kernel

Hi Fabio,

> Subject: Re: [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check
> 
> Hi Peng,
> 
> On Tue, Apr 14, 2020 at 10:30 AM <peng.fan@nxp.com> wrote:
> >
> > From: Peng Fan <peng.fan@nxp.com>
> >
> > The i.MX8 SCU message header size is the number of "u32" elements, not
> > "u8", so fix the check.
> 
> Since this is a fix, please add a Fixes tag

The patch is in Linux-next tree, not in linus tree now, so a fixes tag would be invalid
after patch goes from next to linus tree.

Thanks,
Peng.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check
  2020-04-14 13:21 [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check peng.fan
  2020-04-14 13:32 ` Fabio Estevam
@ 2020-04-14 19:54 ` Leonard Crestez
  2020-04-15  5:55 ` Oleksij Rempel
  2 siblings, 0 replies; 5+ messages in thread
From: Leonard Crestez @ 2020-04-14 19:54 UTC (permalink / raw)
  To: Peng Fan, shawnguo, jassisinghbrar
  Cc: s.hauer, o.rempel, kernel, festevam, dl-linux-imx, Anson Huang,
	Aisheng Dong, linux-arm-kernel, linux-kernel

On 2020-04-14 4:30 PM, Peng Fan wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> The i.MX8 SCU message header size is the number of "u32" elements,
> not "u8", so fix the check.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1461658 ("Memory - corruptions")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check
  2020-04-14 13:21 [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check peng.fan
  2020-04-14 13:32 ` Fabio Estevam
  2020-04-14 19:54 ` Leonard Crestez
@ 2020-04-15  5:55 ` Oleksij Rempel
  2 siblings, 0 replies; 5+ messages in thread
From: Oleksij Rempel @ 2020-04-15  5:55 UTC (permalink / raw)
  To: peng.fan
  Cc: shawnguo, s.hauer, jassisinghbrar, leonard.crestez, kernel,
	festevam, linux-imx, Anson.Huang, aisheng.dong, linux-arm-kernel,
	linux-kernel

[-- Attachment #1: Type: text/plain, Size: 2557 bytes --]

On Tue, Apr 14, 2020 at 09:21:15PM +0800, peng.fan@nxp.com wrote:
> From: Peng Fan <peng.fan@nxp.com>
> 
> The i.MX8 SCU message header size is the number of "u32" elements,
> not "u8", so fix the check.
> 
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1461658 ("Memory - corruptions")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>

Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>

Measuring size in mailboxes instead of bytes is really challenging :) I
would expect similar issues on other places as well.

Regards,
Oleksij

> ---
> 
> V2:
>  Drop parenthesis, add comment, update err msg.
> 
>  drivers/mailbox/imx-mailbox.c | 14 +++++++++-----
>  1 file changed, 9 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mailbox/imx-mailbox.c b/drivers/mailbox/imx-mailbox.c
> index 7906624a731c..fd3a9a60416d 100644
> --- a/drivers/mailbox/imx-mailbox.c
> +++ b/drivers/mailbox/imx-mailbox.c
> @@ -154,12 +154,17 @@ static int imx_mu_scu_tx(struct imx_mu_priv *priv,
>  
>  	switch (cp->type) {
>  	case IMX_MU_TYPE_TX:
> -		if (msg->hdr.size > sizeof(*msg)) {
> +		/*
> +		 * msg->hdr.size specifies the number of u32 words while
> +		 * sizeof yields bytes.
> +		 */
> +
> +		if (msg->hdr.size > sizeof(*msg) / 4) {
>  			/*
>  			 * The real message size can be different to
>  			 * struct imx_sc_rpc_msg_max size
>  			 */
> -			dev_err(priv->dev, "Exceed max msg size (%zu) on TX, got: %i\n", sizeof(*msg), msg->hdr.size);
> +			dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on TX; got: %i bytes\n", sizeof(*msg), msg->hdr.size << 2);
>  			return -EINVAL;
>  		}
>  
> @@ -198,9 +203,8 @@ static int imx_mu_scu_rx(struct imx_mu_priv *priv,
>  	imx_mu_xcr_rmw(priv, 0, IMX_MU_xCR_RIEn(0));
>  	*data++ = imx_mu_read(priv, priv->dcfg->xRR[0]);
>  
> -	if (msg.hdr.size > sizeof(msg)) {
> -		dev_err(priv->dev, "Exceed max msg size (%zu) on RX, got: %i\n",
> -			sizeof(msg), msg.hdr.size);
> +	if (msg.hdr.size > sizeof(msg) / 4) {
> +		dev_err(priv->dev, "Maximal message size (%zu bytes) exceeded on RX; got: %i bytes\n", sizeof(msg), msg.hdr.size << 2);
>  		return -EINVAL;
>  	}
>  
> -- 
> 2.16.4
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-15  5:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14 13:21 [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check peng.fan
2020-04-14 13:32 ` Fabio Estevam
2020-04-14 13:34   ` Peng Fan
2020-04-14 19:54 ` Leonard Crestez
2020-04-15  5:55 ` Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).