Skip to contentSkip to conversation

Fix possible OOB write when using rule_buf

PATCH Superseded Hangyu Hua 3 participants 8 messages Sep 6, 2023 – Sep 8, 2023

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Hangyu Hua

author
#0 lore raw

cover 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.

Hangyu Hua (3):
net: ethernet: bcmasp: fix possible OOB write in
bcmasp_netfilt_get_all_active()
net: ethernet: mvpp2_main: fix possible OOB write in
mvpp2_ethtool_get_rxnfc()
net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in
mtk_hwlro_get_fdir_all()

 drivers/net/ethernet/broadcom/asp2/bcmasp.c     | 3 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 5 +++++
 drivers/net/ethernet/mediatek/mtk_eth_soc.c     | 4 ++++
 3 files changed, 12 insertions(+)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/3 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 c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -0
index d63d321f3e7b..4df2ca871af8 100644
@@ -535,6 +535,9 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
 	int j = 0, i;
 
 	for (i = 0; i < NUM_NET_FILTERS; i++) {
+		if (j == *rule_cnt)
+			break;
+
 		if (!priv->net_filters[i].claimed ||
 		    priv->net_filters[i].port != intf->port)
 			continue;
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH 2/3 net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc()

In reply to Hangyu Hua

rules 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 rules to avoid OOB writing or NULL pointer dereference.

Fixes 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +5 -0
index eb74ccddb440..21c3f9b015c8 100644
@@ -5586,6 +5586,11 @@ static int mvpp2_ethtool_get_rxnfc(struct net_device *dev,
 		break;
 	case ETHTOOL_GRXCLSRLALL:
 		for (i = 0; i < MVPP2_N_RFS_ENTRIES_PER_FLOW; i++) {
+			if (loc == info->rule_cnt) {
+				ret = -EMSGSIZE;
+				break;
+			}
+
 			if (port->rfs_rules[i])
 				rules[loc++] = i;
 		}
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH 3/3 net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()

In reply to Hangyu Hua

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 NULL pointer dereference.

Fixes 7aab747e5563 ("net: ethernet: mediatek: add ethtool functions to configure RX flows of HW LRO")
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -0
index 6ad42e3b488f..d91fc0483c50 100644
@@ -2994,6 +2994,10 @@ static int mtk_hwlro_get_fdir_all(struct net_device *dev,
 	int i;
 
 	for (i = 0; i < MTK_MAX_LRO_IP_CNT; i++) {
+		if (cnt == cmd->rule_cnt) {
+			return -EMSGSIZE;
+		}
+
 		if (mac->hwlro_ip[i]) {
 			rule_locs[cnt] = i;
 			cnt++;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()

In reply to Hangyu Hua
Quoted 6 lines · Hangyu Hua

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 c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
Quoted 18 lines
---
  drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -0
index d63d321f3e7b..4df2ca871af8 100644
@@ -535,6 +535,9 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
  	int j = 0, i;
 
  	for (i = 0; i < NUM_NET_FILTERS; i++) {
+		if (j == *rule_cnt)
+			break;
+
  		if (!priv->net_filters[i].claimed ||
  		    priv->net_filters[i].port != intf->port)
  			continue;
maintainer
#7 lore raw

Re: [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()

In reply to Hangyu Hua
Quoted 15 lines · Hangyu Hua

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 NULL pointer dereference.

Fixes 7aab747e5563 ("net: ethernet: mediatek: add ethtool functions to configure RX flows of HW LRO")
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +0 -0
index 6ad42e3b488f..d91fc0483c50 100644

drivers/net/ethernet/mediatek/mtk_eth_soc.c static int mtk_hwlro_get_fdir_all(struct net_device *dev, · line 2999

Quoted 6 lines
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -0
@@ -2994,6 +2994,10 @@ static int mtk_hwlro_get_fdir_all(struct net_device *dev,
 	int i;
 
 	for (i = 0; i < MTK_MAX_LRO_IP_CNT; i++) {
+		if (cnt == cmd->rule_cnt) {
+			return -EMSGSIZE;
+		}

Please drop the brackets above, they are not needed.

Thanks!

Paolo

maintainer
#3 lore raw

Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()

In reply to Hangyu Hua
Quoted 15 lines · Hangyu Hua

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 c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +0 -0
index d63d321f3e7b..4df2ca871af8 100644

drivers/net/ethernet/broadcom/asp2/bcmasp.c void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, · line 539

Quoted 5 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +2 -0
@@ -535,6 +535,9 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
 	int j = 0, i;
 
 	for (i = 0; i < NUM_NET_FILTERS; i++) {
+		if (j == *rule_cnt)
+			break;

Side note: it's a bit unfortunate/confusing that the drivers can arbitrary return -EMSGSIZE or silently truncate the list. I think it would be clearer if we could stick to single behavior - and I'll vote for -EMSGSIZE.

Cheers,

Paolo

author
#4 lore raw

Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()

Quoted 18 lines · Paolo Abeni
Quoted 17 lines · Hangyu Hua

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 c5d511c49587 ("net: bcmasp: Add support for wake on net filters")
---
  drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +0 -0
index d63d321f3e7b..4df2ca871af8 100644
@@ -535,6 +535,9 @@ void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs,
  	int j = 0, i;
 
Quoted 8 lines

drivers/net/ethernet/broadcom/asp2/bcmasp.c void bcmasp_netfilt_get_all_active(struct bcmasp_intf *intf, u32 *rule_locs, · line 539

Quoted 3 lines
drivers/net/ethernet/broadcom/asp2/bcmasp.c +2 -0
  	for (i = 0; i < NUM_NET_FILTERS; i++) {
+		if (j == *rule_cnt)
+			break;

Side note: it's a bit unfortunate/confusing that the drivers can arbitrary return -EMSGSIZE or silently truncate the list. I think it would be clearer if we could stick to single behavior - and I'll vote for -EMSGSIZE.

I see. I used break directly here beacause this function is defined as void. But since you mentioned this I will fix this out.

Thanks,
Hangyu

Quoted 5 lines

Cheers,

Paolo