diff mbox series

[net,v2] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset

Message ID 5465c1609b464cc7407ae1530c40821dcdf9d3e6.1692634266.git.daniel@makrotopia.org (mailing list archive)
State Accepted
Commit 604204fcb321abe81238551936ecda5269e81076
Delegated to: Netdev Maintainers
Headers show
Series [net,v2] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1328 this patch: 1328
netdev/cc_maintainers success CCed 15 of 15 maintainers
netdev/build_clang success Errors and warnings before: 1351 this patch: 1351
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1351 this patch: 1351
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Daniel Golle Aug. 21, 2023, 4:12 p.m. UTC
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.
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>
---
Changes since v1:
 * remove unneeded {} initialization for stack allocated memory

 drivers/net/ethernet/mediatek/mtk_wed.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Lorenzo Bianconi Aug. 21, 2023, 4:30 p.m. UTC | #1
> 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.
> 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>

Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>

> Reviewed-by: Simon Horman <horms@kernel.org>
> ---
> Changes since v1:
>  * remove unneeded {} initialization for stack allocated memory
> 
>  drivers/net/ethernet/mediatek/mtk_wed.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
> index 00aeee0d5e45f..94376aa2b34c5 100644
> --- a/drivers/net/ethernet/mediatek/mtk_wed.c
> +++ b/drivers/net/ethernet/mediatek/mtk_wed.c
> @@ -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
Jakub Kicinski Aug. 22, 2023, 6:01 p.m. UTC | #2
On Mon, 21 Aug 2023 17:12:44 +0100 Daniel Golle wrote:
> Changes since v1:
>  * remove unneeded {} initialization for stack allocated memory

s/stack/.bss/, FWIW, thanks for updating!
patchwork-bot+netdevbpf@kernel.org Aug. 22, 2023, 6:10 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 21 Aug 2023 17:12:44 +0100 you 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.
> 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>
> 
> [...]

Here is the summary with links:
  - [net,v2] net: ethernet: mtk_eth_soc: fix NULL pointer on hw reset
    https://git.kernel.org/netdev/net/c/604204fcb321

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mediatek/mtk_wed.c b/drivers/net/ethernet/mediatek/mtk_wed.c
index 00aeee0d5e45f..94376aa2b34c5 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed.c
@@ -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;