Skip to content

Commit 0b9c391

Browse files
committed
Merge branch 'rule_buf-OOB'
Hangyu Hua says: ==================== Fix possible OOB write when using rule_buf ADD bounds checks in bcmasp_netfilt_get_all_active and mvpp2_ethtool_get_rxnfc and mtk_hwlro_get_fdir_all when using rule_buf from ethtool_get_rxnfc. v2: [PATCH v2 1/3]: use -EMSGSIZE instead of truncating the list sliently. [PATCH v2 3/3]: drop the brackets. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents fa60b81 + e4c7981 commit 0b9c391

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-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:

drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5586,6 +5586,11 @@ static int mvpp2_ethtool_get_rxnfc(struct net_device *dev,
55865586
break;
55875587
case ETHTOOL_GRXCLSRLALL:
55885588
for (i = 0; i < MVPP2_N_RFS_ENTRIES_PER_FLOW; i++) {
5589+
if (loc == info->rule_cnt) {
5590+
ret = -EMSGSIZE;
5591+
break;
5592+
}
5593+
55895594
if (port->rfs_rules[i])
55905595
rules[loc++] = i;
55915596
}

drivers/net/ethernet/mediatek/mtk_eth_soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,9 @@ static int mtk_hwlro_get_fdir_all(struct net_device *dev,
29942994
int i;
29952995

29962996
for (i = 0; i < MTK_MAX_LRO_IP_CNT; i++) {
2997+
if (cnt == cmd->rule_cnt)
2998+
return -EMSGSIZE;
2999+
29973000
if (mac->hwlro_ip[i]) {
29983001
rule_locs[cnt] = i;
29993002
cnt++;

0 commit comments

Comments
 (0)