Fix possible OOB write when using rule_buf
Subsystems (6)
v2 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.
v2:
[PATCH v2 1/3]: use -EMSGSIZE instead of truncating the list sliently. [PATCH v2 3/3]: drop the brackets.
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 | 9 +++++++-- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 4 ++-- drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 2 +- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 5 +++++ drivers/net/ethernet/mediatek/mtk_eth_soc.c | 3 +++ 5 files changed, 18 insertions(+), 5 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 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.
---
v2: use -EMSGSIZE instead of truncating the list sliently.
drivers/net/ethernet/broadcom/asp2/bcmasp.c | 9 +++++++-- drivers/net/ethernet/broadcom/asp2/bcmasp.h | 4 ++-- drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp.c +7 -2
@@ -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 ;
@@ -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)
drivers/net/ethernet/broadcom/asp2/bcmasp.h +2 -2
@@ -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);
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +1 -1
@@ -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 :
Signature · 1 line
2.34.1
Re: [PATCH v2 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]>
PATCH v2 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
Re: [PATCH v2 2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc()
pt., 8 wrz 2023 o 08:21 Hangyu Hua <[email protected]> napisał(a):
Quoted 17 lines
rules is allocated in
ethtool_get_rxnfcand the size is determined byrule_cntfrom user space. Sorule_cntneeds to be check before using rules to avoid OOB writing or NULL pointer dereference.Fixes 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")Signed-off-by Hangyu Hua <[email protected]>--- drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +0
-0@@ -5586,6 +5586,11 @@ static int mvpp2_ethtool_get_rxnfc(struct net_device *dev,break ;
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c static int mvpp2_ethtool_get_rxnfc(struct net_device *dev, · line 5596
Quoted 10 lines
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +5
-0case 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; }
Thanks,
Marcin
Re: [PATCH v2 2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc()
In reply to Hangyu HuaQuoted 6 lines · Hangyu Hua
rules is allocated in
ethtool_get_rxnfcand the size is determined byrule_cntfrom user space. Sorule_cntneeds to be check before using rules to avoid OOB writing or NULL pointer dereference.Fixes 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")Signed-off-by Hangyu Hua <[email protected]>
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
PATCH v2 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.
---
v2: drop the brackets.
drivers/net/ethernet/mediatek/mtk_eth_soc.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/mediatek/mtk_eth_soc.c +3 -0
@@ -2994,6 +2994,9 @@ 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
Re: [PATCH v2 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()
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 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]>
This series was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 9 lines · On Fri, 8 Sep 2023 14:19:47 +0800 you wrote:
ADD bounds checks in
bcmasp_netfilt_get_all_activeandmvpp2_ethtool_get_rxnfcandmtk_hwlro_get_fdir_allwhen usingrule_buffromethtool_get_rxnfc.v2:
[PATCH v2 1/3]: use-EMSGSIZEinstead of truncating the list sliently. [PATCH v2 3/3]: drop the brackets.[...]
Here is the summary with links:
- [v2,1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
https://git.kernel.org/netdev/net/c/9b90aca97f6d - [v2,2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc() https://git.kernel.org/netdev/net/c/51fe0a470543 - [v2,3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() https://git.kernel.org/netdev/net/c/e4c79810755f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html