net: dsa: sja1105: fix NULL pointer dereference in sja1105_reload_cbs()
Vladimir Oltean
maintainerPATCH 1/1 net: dsa: sja1105: fix NULL pointer dereference in sja1105_reload_cbs()
From: Vladimir Oltean <[email protected]>
priv->cbs is an array of priv->info->num_cbs_shapers elements of type struct sja1105_cbs_entry which only get allocated if CONFIG_NET_SCH_CBS is enabled.
However, sja1105_reload_cbs() is called from sja1105_static_config_reload() which in turn is called for any of the items in sja1105_reset_reasons, therefore during the normal runtime of the driver and not just from a code path which can be triggered by the tc-cbs offload.
The sja1105_reload_cbs() function does not contain a check whether the priv->cbs array is NULL or not, it just assumes it isn't and proceeds to iterate through the credit-based shaper elements. This leads to a NULL pointer dereference.
The solution is to return success if the priv->cbs array has not been allocated, since sja1105_reload_cbs() has nothing to do.
--- drivers/net/dsa/sja1105/sja1105_main.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +6 -0
@@ -1818,6 +1818,12 @@ static int sja1105_reload_cbs(struct sja1105_private *priv) {int rc =0 , i; +/* The credit based shapers are only allocated if +* CONFIG_NET_SCH_CBS is enabled. +*/ +if (!priv->cbs) +return 0 ; +for (i =0 ; i < priv->info->num_cbs_shapers; i++) {struct sja1105_cbs_entry *cbs = &priv->cbs[i];
Signature · 1 line
2.25.1
This patch was applied to netdev/net.git (refs/heads/master):
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
Quoted 6 lines · On Thu, 24 Jun 2021 18:52:07 +0300 you wrote:
From: Vladimir Oltean <[email protected]>
priv->cbsis an array ofpriv->info->num_cbs_shaperselements of type structsja1105_cbs_entrywhich only get allocated ifCONFIG_NET_SCH_CBSis enabled.
Quoted 6 lines
However,
sja1105_reload_cbs()is called fromsja1105_static_config_reload()which in turn is called for any of the items insja1105_reset_reasons, therefore during the normal runtime of the driver and not just from a code path which can be triggered by the tc-cbs offload.[...]
Here is the summary with links:
- [net] net: dsa: sja1105: fix NULL pointer dereference in sja1105_reload_cbs()
https://git.kernel.org/netdev/net/c/be7f62eebaff
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html