net: bcmgenet: reject undersized RX classification rule buffers
Subsystems (3)
PATCH v2 1/1 net: bcmgenet: reject undersized RX classification rule buffers
The rule list can grow between ETHTOOL_GRXCLSRLCNT and ETHTOOL_GRXCLSRLALL. If the supplied array is too small, bcmgenet_get_rxnfc() currently reports success with only the rule locations that fit.
Return -EMSGSIZE when another location cannot fit so callers can detect an incomplete dump. On success, continue reporting the number of locations copied.
---
Changes in v2:
- Retarget to net-next as requested by Nicolai.
- Clarify the commit message and drop the Fixes and test lines.
- No code changes.
v1: https://lore.kernel.org/netdev/[email protected]/
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/ethernet/broadcom/genet/bcmgenet.c +6 -4
@@ -1664,7 +1664,7 @@ static int bcmgenet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,struct bcmgenet_priv *priv =netdev_priv (dev);struct bcmgenet_rxnfc_rule *rule;int err =0 ; -int i =0 ; +u32 i =0 ;switch (cmd->cmd) {case ETHTOOL_GRXCLSRLCNT :
@@ -1675,9 +1675,11 @@ static int bcmgenet_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd, err =bcmgenet_get_flow (dev, cmd, cmd->fs.location);break ;case ETHTOOL_GRXCLSRLALL : -list_for_each_entry (rule, &priv->rxnfc_list, list) -if (i < cmd->rule_cnt) - rule_locs[i++] = rule->fs.location; +list_for_each_entry (rule, &priv->rxnfc_list, list) { +if (i == cmd->rule_cnt) +return -EMSGSIZE ; + rule_locs[i++] = rule->fs.location; + } cmd->rule_cnt = i; cmd->data =MAX_NUM_OF_FS_RULES ;break ;
Hi Artemii
Quoted 16 lines · Artemii Mashanov
The rule list can grow between
ETHTOOL_GRXCLSRLCNTandETHTOOL_GRXCLSRLALL. If the supplied array is too small,bcmgenet_get_rxnfc()currently reports success with only the rule locations that fit.Return
-EMSGSIZEwhen another location cannot fit so callers can detect an incomplete dump. On success, continue reporting the number of locations copied.Signed-off-by Artemii Mashanov <[email protected]>---
Changes in v2:
- Retarget to net-next as requested by Nicolai.
- Clarify the commit message and drop the Fixes and test lines.
- No code changes.
Quoted 3 lines
v1: https://lore.kernel.org/netdev/[email protected]/
[...]
Thanks,
Nicolai