Skip to content

Commit

Permalink
net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_a…
Browse files Browse the repository at this point in the history
…ll_active()

rule_locs is allocated in ethtool_get_rxnfc and the size is determined by
rule_cnt from user space. So rule_cnt needs to be check before using
rule_locs to avoid OOB writing or NULL pointer dereference.

Fixes: c5d511c ("net: bcmasp: Add support for wake on net filters")
Signed-off-by: Hangyu Hua <[email protected]>
Reviewed-by: Simon Horman <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
HBh25Y authored and davem330 committed Sep 11, 2023
1 parent fa60b81 commit 9b90aca
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions drivers/net/ethernet/broadcom/asp2/bcmasp.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,16 @@ void bcmasp_netfilt_suspend(struct bcmasp_intf *intf)
ASP_RX_FILTER_BLK_CTRL);
}

void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
u32 *rule_cnt)
int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
u32 *rule_cnt)
{
struct bcmasp_priv *priv = intf->parent;
int j = 0, i;

for (i = 0; i < NUM_NET_FILTERS; i++) {
if (j == *rule_cnt)
return -EMSGSIZE;

if (!priv->net_filters[i].claimed ||
priv->net_filters[i].port != intf->port)
continue;
Expand All @@ -548,6 +551,8 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
}

*rule_cnt = j;

return 0;
}

int bcmasp_netfilt_get_active(struct bcmasp_intf *intf)
Expand Down
4 changes: 2 additions & 2 deletions drivers/net/ethernet/broadcom/asp2/bcmasp.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ void bcmasp_netfilt_release(struct bcmasp_intf *intf,

int bcmasp_netfilt_get_active(struct bcmasp_intf *intf);

void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
u32 *rule_cnt);
int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
u32 *rule_cnt);

void bcmasp_netfilt_suspend(struct bcmasp_intf *intf);

Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
err = bcmasp_flow_get(intf, cmd);
break;
case ETHTOOL_GRXCLSRLALL:
bcmasp_netfilt_get_all_active(intf, rule_locs, &cmd->rule_cnt);
err = bcmasp_netfilt_get_all_active(intf, rule_locs, &cmd->rule_cnt);
cmd->data = NUM_NET_FILTERS;
break;
default:
Expand Down

0 comments on commit 9b90aca

Please sign in to comment.