linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] Fix possible OOB write when using rule_buf
@ 2023-09-06  9:21 Hangyu Hua
  2023-09-06  9:21 ` [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active() Hangyu Hua
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Hangyu Hua @ 2023-09-06  9:21 UTC (permalink / raw)
  To: justin.chen, florian.fainelli, davem, edumazet, kuba, pabeni, mw,
	linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo, matthias.bgg,
	angelogioacchino.delregno, maxime.chevallier, nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek, Hangyu Hua

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(+)

-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
  2023-09-06  9:21 [PATCH 0/3] Fix possible OOB write when using rule_buf Hangyu Hua
@ 2023-09-06  9:21 ` Hangyu Hua
  2023-09-06 20:45   ` Justin Chen
  2023-09-07  9:44   ` Paolo Abeni
  2023-09-06  9:21 ` [PATCH 2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc() Hangyu Hua
  2023-09-06  9:21 ` [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() Hangyu Hua
  2 siblings, 2 replies; 8+ messages in thread
From: Hangyu Hua @ 2023-09-06  9:21 UTC (permalink / raw)
  To: justin.chen, florian.fainelli, davem, edumazet, kuba, pabeni, mw,
	linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo, matthias.bgg,
	angelogioacchino.delregno, maxime.chevallier, nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek, 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")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
index d63d321f3e7b..4df2ca871af8 100644
--- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
+++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
@@ -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;
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc()
  2023-09-06  9:21 [PATCH 0/3] Fix possible OOB write when using rule_buf Hangyu Hua
  2023-09-06  9:21 ` [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active() Hangyu Hua
@ 2023-09-06  9:21 ` Hangyu Hua
  2023-09-06  9:21 ` [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() Hangyu Hua
  2 siblings, 0 replies; 8+ messages in thread
From: Hangyu Hua @ 2023-09-06  9:21 UTC (permalink / raw)
  To: justin.chen, florian.fainelli, davem, edumazet, kuba, pabeni, mw,
	linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo, matthias.bgg,
	angelogioacchino.delregno, maxime.chevallier, nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek, 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")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index eb74ccddb440..21c3f9b015c8 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -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;
 		}
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()
  2023-09-06  9:21 [PATCH 0/3] Fix possible OOB write when using rule_buf Hangyu Hua
  2023-09-06  9:21 ` [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active() Hangyu Hua
  2023-09-06  9:21 ` [PATCH 2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc() Hangyu Hua
@ 2023-09-06  9:21 ` Hangyu Hua
  2023-09-07  9:33   ` Paolo Abeni
  2 siblings, 1 reply; 8+ messages in thread
From: Hangyu Hua @ 2023-09-06  9:21 UTC (permalink / raw)
  To: justin.chen, florian.fainelli, davem, edumazet, kuba, pabeni, mw,
	linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo, matthias.bgg,
	angelogioacchino.delregno, maxime.chevallier, nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek, 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")
Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
---
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index 6ad42e3b488f..d91fc0483c50 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -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++;
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
  2023-09-06  9:21 ` [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active() Hangyu Hua
@ 2023-09-06 20:45   ` Justin Chen
  2023-09-07  9:44   ` Paolo Abeni
  1 sibling, 0 replies; 8+ messages in thread
From: Justin Chen @ 2023-09-06 20:45 UTC (permalink / raw)
  To: Hangyu Hua, florian.fainelli, davem, edumazet, kuba, pabeni, mw,
	linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo, matthias.bgg,
	angelogioacchino.delregno, maxime.chevallier, nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek


[-- Attachment #1.1: Type: text/plain, Size: 1100 bytes --]



On 9/6/23 2:21 AM, Hangyu Hua wrote:
> 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")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>

Reviewed-by: Justin Chen <justin.chen@broadcom.com>

> ---
>   drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> index d63d321f3e7b..4df2ca871af8 100644
> --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> @@ -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;

[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4206 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all()
  2023-09-06  9:21 ` [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() Hangyu Hua
@ 2023-09-07  9:33   ` Paolo Abeni
  0 siblings, 0 replies; 8+ messages in thread
From: Paolo Abeni @ 2023-09-07  9:33 UTC (permalink / raw)
  To: Hangyu Hua, justin.chen, florian.fainelli, davem, edumazet, kuba,
	mw, linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo,
	matthias.bgg, angelogioacchino.delregno, maxime.chevallier,
	nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

On Wed, 2023-09-06 at 17:21 +0800, Hangyu Hua wrote:
> 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")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> index 6ad42e3b488f..d91fc0483c50 100644
> --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
> @@ -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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
  2023-09-06  9:21 ` [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active() Hangyu Hua
  2023-09-06 20:45   ` Justin Chen
@ 2023-09-07  9:44   ` Paolo Abeni
  2023-09-08  2:59     ` Hangyu Hua
  1 sibling, 1 reply; 8+ messages in thread
From: Paolo Abeni @ 2023-09-07  9:44 UTC (permalink / raw)
  To: Hangyu Hua, justin.chen, florian.fainelli, davem, edumazet, kuba,
	mw, linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo,
	matthias.bgg, angelogioacchino.delregno, maxime.chevallier,
	nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

On Wed, 2023-09-06 at 17:21 +0800, Hangyu Hua wrote:
> 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")
> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
> ---
>  drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> index d63d321f3e7b..4df2ca871af8 100644
> --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
> @@ -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


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active()
  2023-09-07  9:44   ` Paolo Abeni
@ 2023-09-08  2:59     ` Hangyu Hua
  0 siblings, 0 replies; 8+ messages in thread
From: Hangyu Hua @ 2023-09-08  2:59 UTC (permalink / raw)
  To: Paolo Abeni, justin.chen, florian.fainelli, davem, edumazet, kuba,
	mw, linux, nbd, john, sean.wang, Mark-MC.Lee, lorenzo,
	matthias.bgg, angelogioacchino.delregno, maxime.chevallier,
	nelson.chang
  Cc: bcm-kernel-feedback-list, netdev, linux-kernel, linux-arm-kernel,
	linux-mediatek

On 7/9/2023 17:44, Paolo Abeni wrote:
> On Wed, 2023-09-06 at 17:21 +0800, Hangyu Hua wrote:
>> 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")
>> Signed-off-by: Hangyu Hua <hbh25y@gmail.com>
>> ---
>>   drivers/net/ethernet/broadcom/asp2/bcmasp.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/broadcom/asp2/bcmasp.c b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
>> index d63d321f3e7b..4df2ca871af8 100644
>> --- a/drivers/net/ethernet/broadcom/asp2/bcmasp.c
>> +++ b/drivers/net/ethernet/broadcom/asp2/bcmasp.c
>> @@ -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.

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

> 
> Cheers,
> 
> Paolo
> 

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-09-08  3:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-06  9:21 [PATCH 0/3] Fix possible OOB write when using rule_buf Hangyu Hua
2023-09-06  9:21 ` [PATCH 1/3] net: ethernet: bcmasp: fix possible OOB write in bcmasp_netfilt_get_all_active() Hangyu Hua
2023-09-06 20:45   ` Justin Chen
2023-09-07  9:44   ` Paolo Abeni
2023-09-08  2:59     ` Hangyu Hua
2023-09-06  9:21 ` [PATCH 2/3] net: ethernet: mvpp2_main: fix possible OOB write in mvpp2_ethtool_get_rxnfc() Hangyu Hua
2023-09-06  9:21 ` [PATCH 3/3] net: ethernet: mtk_eth_soc: fix possible NULL pointer dereference in mtk_hwlro_get_fdir_all() Hangyu Hua
2023-09-07  9:33   ` Paolo Abeni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).