netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fsl/fman: Validate cell-index value obtained from Device Tree
@ 2024-07-02  9:50 Aleksandr Mishin
  2024-07-02 13:36 ` Simon Horman
  2024-07-02 14:01 ` [PATCH v2] " Aleksandr Mishin
  0 siblings, 2 replies; 5+ messages in thread
From: Aleksandr Mishin @ 2024-07-02  9:50 UTC (permalink / raw)
  To: Igal Liberman
  Cc: Aleksandr Mishin, Madalin Bucur, Sean Anderson, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	lvc-project

Cell-index value is obtained from Device Tree and then used to calculate
the index for accessing arrays port_mfl[], mac_mfl[] and intr_mng[].
In case of broken DT due to any error cell-index can contain any value
and it is possible to go beyond the array boundaries which can lead
at least to memory corruption.
Validate cell-index value obtained from Device Tree.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: 414fd46e7762 ("fsl/fman: Add FMan support")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/net/ethernet/freescale/fman/fman.c | 7 +++++++
 drivers/net/ethernet/freescale/fman/fman.h | 2 ++
 drivers/net/ethernet/freescale/fman/mac.c  | 5 +++++
 3 files changed, 14 insertions(+)

diff --git a/drivers/net/ethernet/freescale/fman/fman.c b/drivers/net/ethernet/freescale/fman/fman.c
index d96028f01770..6929bca3f768 100644
--- a/drivers/net/ethernet/freescale/fman/fman.c
+++ b/drivers/net/ethernet/freescale/fman/fman.c
@@ -2933,3 +2933,10 @@ module_exit(fman_unload);
 
 MODULE_LICENSE("Dual BSD/GPL");
 MODULE_DESCRIPTION("Freescale DPAA Frame Manager driver");
+
+int check_mac_id(u32 mac_id)
+{
+	if (mac_id >= MAX_NUM_OF_MACS)
+		return -EINVAL;
+	return 0;
+}
diff --git a/drivers/net/ethernet/freescale/fman/fman.h b/drivers/net/ethernet/freescale/fman/fman.h
index 2ea575a46675..3cedde4851e1 100644
--- a/drivers/net/ethernet/freescale/fman/fman.h
+++ b/drivers/net/ethernet/freescale/fman/fman.h
@@ -372,6 +372,8 @@ u16 fman_get_max_frm(void);
 
 int fman_get_rx_extra_headroom(void);
 
+int check_mac_id(u32 mac_id);
+
 #ifdef CONFIG_DPAA_ERRATUM_A050385
 bool fman_has_errata_a050385(void);
 #endif
diff --git a/drivers/net/ethernet/freescale/fman/mac.c b/drivers/net/ethernet/freescale/fman/mac.c
index 9767586b4eb3..7a67b4c887e2 100644
--- a/drivers/net/ethernet/freescale/fman/mac.c
+++ b/drivers/net/ethernet/freescale/fman/mac.c
@@ -247,6 +247,11 @@ static int mac_probe(struct platform_device *_of_dev)
 		dev_err(dev, "failed to read cell-index for %pOF\n", mac_node);
 		return -EINVAL;
 	}
+	err = check_mac_id(val);
+	if (err) {
+		dev_err(dev, "cell-index value is out of range for %pOF\n", mac_node);
+		return err;
+	}
 	priv->cell_index = (u8)val;
 
 	/* Get the MAC address */
-- 
2.30.2


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

end of thread, other threads:[~2024-07-02 17:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-02  9:50 [PATCH] fsl/fman: Validate cell-index value obtained from Device Tree Aleksandr Mishin
2024-07-02 13:36 ` Simon Horman
2024-07-02 17:44   ` Jakub Kicinski
2024-07-02 14:01 ` [PATCH v2] " Aleksandr Mishin
2024-07-02 14:50   ` Sean Anderson

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).