Fix possible OOB write when using rule_buf
Subsystems (6)
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
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.
--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +3 -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 ; +if (!priv->net_filters[i].claimed || priv->net_filters[i].port != intf->port)continue ;
Signature · 1 line
2.34.1
Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
Quoted 6 lines · Hangyu Hua
rule_locsis allocated inethtool_get_rxnfcand the size is determined byrule_cntfrom user space. Sorule_cntneeds to be check before usingrule_locsto avoid OOB writing or NULL pointer dereference.Fixes c5d511c49587 ("net: bcmasp: Add support for wake on net filters")Signed-off-by Hangyu Hua <[email protected]>
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@@ -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 ;
Paolo Abeni
maintainerRe: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
In reply to Hangyu HuaQuoted 15 lines · Hangyu Hua
rule_locsis allocated inethtool_get_rxnfcand the size is determined byrule_cntfrom user space. Sorule_cntneeds to be check before usingrule_locsto avoid OOB writing or NULL pointer dereference.Fixes c5d511c49587 ("net: bcmasp: Add support for wake on net filters")Signed-off-by Hangyu Hua <[email protected]>--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/ethernet/broadcom/asp2/bcmasp.c +0
-0
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
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_locsis allocated inethtool_get_rxnfcand the size is determined byrule_cntfrom user space. Sorule_cntneeds to be check before usingrule_locsto avoid OOB writing or NULL pointer dereference.Fixes c5d511c49587 ("net: bcmasp: Add support for wake on net filters")Signed-off-by Hangyu Hua <[email protected]>--- drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++ 1 file changed, 3 insertions(+)drivers/net/ethernet/broadcom/asp2/bcmasp.c +0
-0@@ -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
-0for (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
-EMSGSIZEor 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
PATCH 2/3 net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc()
In reply to Hangyu Huarules 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.
--- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +5 -0
@@ -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
PATCH 3/3 net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()
In reply to Hangyu Huarule_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.
--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +4 -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 ; + } +if (mac->hwlro_ip[i]) { rule_locs[cnt] = i; cnt++;
Signature · 1 line
2.34.1
Paolo Abeni
maintainerRe: [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()
Quoted 15 lines · Hangyu Hua
rule_locsis allocated inethtool_get_rxnfcand the size is determined byrule_cntfrom user space. Sorule_cntneeds to be check before usingrule_locsto avoid NULL pointer dereference.Fixes 7aab747e5563 ("net: ethernet: mediatek: add ethtool functions to configure RX flows of HW LRO")Signed-off-by Hangyu Hua <[email protected]>--- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/ethernet/mediatek/mtk_eth_soc.c +0
-0
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