Skip to contentSkip to conversation

net: mvpp2: prevent buffer overflow in mvpp22_rss_ctx()

PATCH Applied Dan Carpenter 2 participants 4 messages May 6, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 net: mvpp2: prevent buffer overflow in mvpp22_rss_ctx()

The "rss_context" variable comes from the user via ethtool_get_rxfh(). It can be any u32 value except zero. Eventually it gets passed to mvpp22_rss_ctx() and if it is over MVPP22_N_RSS_TABLES (8) then it results in an array overflow.

Fixes 895586d5dc32 ("net: mvpp2: cls: Use RSS contexts to handle RSS tables")
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c +2 -0
index 1fa60e985b43a..2b5dad2ec650c 100644
@@ -4329,6 +4329,8 @@ static int mvpp2_ethtool_get_rxfh_context(struct net_device *dev, u32 *indir,
 
 	if (!mvpp22_rss_is_supported())
 		return -EOPNOTSUPP;
+	if (rss_context >= MVPP22_N_RSS_TABLES)
+		return -EINVAL;
 
 	if (hfunc)
 		*hfunc = ETH_RSS_HASH_CRC32;
Signature · 1 line
2.26.2
#1 lore raw

PATCH 2/2 net: mvpp2: cls: Prevent buffer overflow in mvpp2_ethtool_cls_rule_del()

The "info->fs.location" is a u32 that comes from the user via the ethtool_set_rxnfc() function. We need to check for invalid values to prevent a buffer overflow.

I copy and pasted this check from the mvpp2_ethtool_cls_rule_ins() function.

Fixes 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/net/ethernet/marvell/mvpp2/mvpp2_cls.c +3 -0
index 8972cdd559e85..7352244c5e68b 100644
@@ -1428,6 +1428,9 @@ int mvpp2_ethtool_cls_rule_del(struct mvpp2_port *port,
 	struct mvpp2_ethtool_fs *efs;
 	int ret;
 
+	if (info->fs.location >= MVPP2_N_RFS_ENTRIES_PER_FLOW)
+		return -EINVAL;
+
 	efs = port->rfs_rules[info->fs.location];
 	if (!efs)
 		return -EINVAL;
Signature · 1 line
2.26.2
maintainer Applied
#3 lore raw
In reply to Dan Carpenter

From: Dan Carpenter <[email protected]>
Date: Wed, 6 May 2020 13:16:22 +0300

Quoted 7 lines

The "rss_context" variable comes from the user via ethtool_get_rxfh(). It can be any u32 value except zero. Eventually it gets passed to mvpp22_rss_ctx() and if it is over MVPP22_N_RSS_TABLES (8) then it results in an array overflow.

Fixes 895586d5dc32 ("net: mvpp2: cls: Use RSS contexts to handle RSS tables")

Applied.

maintainer Applied
#2 lore raw

Re: [PATCH 2/2 net] net: mvpp2: cls: Prevent buffer overflow in mvpp2_ethtool_cls_rule_del()

In reply to Dan Carpenter

From: Dan Carpenter <[email protected]>
Date: Wed, 6 May 2020 13:16:56 +0300

Quoted 9 lines

The "info->fs.location" is a u32 that comes from the user via the ethtool_set_rxnfc() function. We need to check for invalid values to prevent a buffer overflow.

I copy and pasted this check from the mvpp2_ethtool_cls_rule_ins() function.

Fixes 90b509b39ac9 ("net: mvpp2: cls: Add Classification offload support")

Applied.