netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset
@ 2023-08-17 12:01 Daniel Golle
  2023-08-18 12:12 ` Simon Horman
  2023-08-19  1:33 ` Jakub Kicinski
  0 siblings, 2 replies; 3+ messages in thread
From: Daniel Golle @ 2023-08-17 12:01 UTC (permalink / raw)
  To: Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
	Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
	Sujuan Chen, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

When a hardware reset is triggered on devices not initializing WED the
calls to mtk_wed_fe_reset and mtk_wed_fe_reset_complete dereference a
pointer on uninitialized stack memory.
Initialize the hw_list will 0s and break out of both functions in case
a hw_list entry is 0.

Fixes: 08a764a7c51b ("net: ethernet: mtk_wed: add reset/reset_complete callbacks")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
 drivers/net/ethernet/mediatek/mtk_wed.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
index 00aeee0d5e45f..d14f5137379b9 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -41,7 +41,7 @@
 #define MTK_WED_RRO_QUE_CNT		8192
 #define MTK_WED_MIOD_ENTRY_CNT		128
 
-static struct mtk_wed_hw *hw_list[2];
+static struct mtk_wed_hw *hw_list[2] = {};
 static DEFINE_MUTEX(hw_lock);
 
 struct mtk_wed_flow_block_priv {
@@ -222,9 +222,13 @@ void mtk_wed_fe_reset(void)
 
 	for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
 		struct mtk_wed_hw *hw = hw_list[i];
-		struct mtk_wed_device *dev = hw->wed_dev;
+		struct mtk_wed_device *dev;
 		int err;
 
+		if (!hw)
+			break;
+
+		dev = hw->wed_dev;
 		if (!dev || !dev->wlan.reset)
 			continue;
 
@@ -245,8 +249,12 @@ void mtk_wed_fe_reset_complete(void)
 
 	for (i = 0; i < ARRAY_SIZE(hw_list); i++) {
 		struct mtk_wed_hw *hw = hw_list[i];
-		struct mtk_wed_device *dev = hw->wed_dev;
+		struct mtk_wed_device *dev;
+
+		if (!hw)
+			break;
 
+		dev = hw->wed_dev;
 		if (!dev || !dev->wlan.reset_complete)
 			continue;
 
-- 
2.41.0


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

* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset
  2023-08-17 12:01 [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset Daniel Golle
@ 2023-08-18 12:12 ` Simon Horman
  2023-08-19  1:33 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Simon Horman @ 2023-08-18 12:12 UTC (permalink / raw)
  To: Daniel Golle
  Cc: Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
	Lorenzo Bianconi, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Matthias Brugger, AngeloGioacchino Del Regno,
	Sujuan Chen, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

On Thu, Aug 17, 2023 at 01:01:11PM +0100, Daniel Golle wrote:
> When a hardware reset is triggered on devices not initializing WED the
> calls to mtk_wed_fe_reset and mtk_wed_fe_reset_complete dereference a
> pointer on uninitialized stack memory.
> Initialize the hw_list will 0s and break out of both functions in case
> a hw_list entry is 0.
> 
> Fixes: 08a764a7c51b ("net: ethernet: mtk_wed: add reset/reset_complete callbacks")
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>

Reviewed-by: Simon Horman <horms@kernel.org>


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

* Re: [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset
  2023-08-17 12:01 [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset Daniel Golle
  2023-08-18 12:12 ` Simon Horman
@ 2023-08-19  1:33 ` Jakub Kicinski
  1 sibling, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2023-08-19  1:33 UTC (permalink / raw)
  To: Daniel Golle
  Cc: Felix Fietkau, John Crispin, Sean Wang, Mark Lee,
	Lorenzo Bianconi, David S. Miller, Eric Dumazet, Paolo Abeni,
	Matthias Brugger, AngeloGioacchino Del Regno, Sujuan Chen, netdev,
	linux-kernel, linux-arm-kernel, linux-mediatek

On Thu, 17 Aug 2023 13:01:11 +0100 Daniel Golle wrote:
> Initialize the hw_list will 0s and break out of both functions in case
> a hw_list entry is 0.

Static variables are always initialized to 0, I don't think that part
is need.
-- 
pw-bot: cr

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

end of thread, other threads:[~2023-08-19  1:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-17 12:01 [PATCH net] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset Daniel Golle
2023-08-18 12:12 ` Simon Horman
2023-08-19  1:33 ` Jakub Kicinski

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