Skip to content

Commit 9b90aca

Browse files
HBh25Ydavem330
authored andcommitted
net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_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]>
1 parent fa60b81 commit 9b90aca

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

drivers/net/ethernet/broadcom/asp2/bcmasp.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,13 +528,16 @@ void bcmasp_netfilt_suspend(struct bcmasp_intf *intf)
528528
ASP_RX_FILTER_BLK_CTRL);
529529
}
530530

531-
void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
532-
u32 *rule_cnt)
531+
int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
532+
u32 *rule_cnt)
533533
{
534534
struct bcmasp_priv *priv = intf->parent;
535535
int j = 0, i;
536536

537537
for (i = 0; i < NUM_NET_FILTERS; i++) {
538+
if (j == *rule_cnt)
539+
return -EMSGSIZE;
540+
538541
if (!priv->net_filters[i].claimed ||
539542
priv->net_filters[i].port != intf->port)
540543
continue;
@@ -548,6 +551,8 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
548551
}
549552

550553
*rule_cnt = j;
554+
555+
return 0;
551556
}
552557

553558
int bcmasp_netfilt_get_active(struct bcmasp_intf *intf)

drivers/net/ethernet/broadcom/asp2/bcmasp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ void bcmasp_netfilt_release(struct bcmasp_intf *intf,
577577

578578
int bcmasp_netfilt_get_active(struct bcmasp_intf *intf);
579579

580-
void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
581-
u32 *rule_cnt);
580+
int bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
581+
u32 *rule_cnt);
582582

583583
void bcmasp_netfilt_suspend(struct bcmasp_intf *intf);
584584

drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static int bcmasp_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
335335
err = bcmasp_flow_get(intf, cmd);
336336
break;
337337
case ETHTOOL_GRXCLSRLALL:
338-
bcmasp_netfilt_get_all_active(intf, rule_locs, &cmd->rule_cnt);
338+
err = bcmasp_netfilt_get_all_active(intf, rule_locs, &cmd->rule_cnt);
339339
cmd->data = NUM_NET_FILTERS;
340340
break;
341341
default:

0 commit comments

Comments
 (0)