Skip to content

Commit be7f62e

Browse files
vladimirolteandavem330
authored andcommitted
net: dsa: sja1105: fix NULL pointer dereference in sja1105_reload_cbs()
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. Fixes: 4d75250 ("net: dsa: sja1105: offload the Credit-Based Shaper qdisc") Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8bead5c commit be7f62e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/net/dsa/sja1105/sja1105_main.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,12 @@ static int sja1105_reload_cbs(struct sja1105_private *priv)
17981798
{
17991799
int rc = 0, i;
18001800

1801+
/* The credit based shapers are only allocated if
1802+
* CONFIG_NET_SCH_CBS is enabled.
1803+
*/
1804+
if (!priv->cbs)
1805+
return 0;
1806+
18011807
for (i = 0; i < priv->info->num_cbs_shapers; i++) {
18021808
struct sja1105_cbs_entry *cbs = &priv->cbs[i];
18031809

0 commit comments

Comments
 (0)