Skip to contentSkip to conversation

mailbox: imx-mailbox: fix scu msg header size check

PATCH In review [email protected] 4 participants 5 messages Apr 14, 2020 – Apr 15, 2020

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

PATCH v2 1/1 mailbox: imx-mailbox: fix scu msg header size check

From: Peng Fan <[email protected]>

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

Addresses-Coverity-ID: 1461658 ("Memory - corruptions")

---

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

 drivers/mailbox/imx-mailbox.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/mailbox/imx-mailbox.c +9 -5
index 7906624a731c..fd3a9a60416d 100644
@@ -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;
 	}
 
Signature · 7 lines
2.16.4


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author
#2 lore raw

Hi Fabio,

Quoted 4 lines

Subject: Re: [PATCH V2] mailbox: imx-mailbox: fix scu msg header size check

Hi Peng,

Quoted 8 lines
Quoted 5 lines · On Tue, Apr 14, 2020 at 10:30 AM <[email protected]> wrote:

From: Peng Fan <[email protected]>

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.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Reviewed-by on v2 1/1
#3 lore raw
In reply to [email protected]
Quoted 8 lines · Peng Fan

From: Peng Fan <[email protected]>

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

Addresses-Coverity-ID: 1461658 ("Memory - corruptions")

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Acked-by on v2 1/1
#4 lore raw
In reply to [email protected]
Quoted 8 lines · On Tue, Apr 14, 2020 at 09:21:15PM +0800, [email protected] wrote:

From: Peng Fan <[email protected]>

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

Addresses-Coverity-ID: 1461658 ("Memory - corruptions")

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

Regards,
Oleksij

Quoted 48 lines

---

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

 drivers/mailbox/imx-mailbox.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/mailbox/imx-mailbox.c +9 -5
index 7906624a731c..fd3a9a60416d 100644
@@ -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;
 	}
 
Signature · 1 line
2.16.4
Signature · 4 lines
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 |

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel