Skip to contentSkip to conversation

net: dsa: b53: fix an off by one in checking "vlan->vid"

PATCH Applied Dan Carpenter 3 participants 3 messages Jan 19, 2021 – Jan 20, 2021

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

PATCH 1/1 net: dsa: b53: fix an off by one in checking "vlan->vid"

The > comparison should be >= to prevent accessing one element beyond the end of the dev->vlans[] array in the caller function, b53_vlan_add(). The "dev->vlans" array is allocated in the b53_switch_init() function and it has "dev->num_vlans" elements.

Fixes a2482d2ce349 ("net: dsa: b53: Plug in VLAN support")
---
 drivers/net/dsa/b53/b53_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dsa/b53/b53_common.c +1 -1
index 288b5a5c3e0d..95c7fa171e35 100644
@@ -1404,7 +1404,7 @@ int b53_vlan_prepare(struct dsa_switch *ds, int port,
 	    !(vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED))
 		return -EINVAL;
 
-	if (vlan->vid_end > dev->num_vlans)
+	if (vlan->vid_end >= dev->num_vlans)
 		return -ERANGE;
 
 	b53_enable_vlan(dev, true, ds->vlan_filtering);
Signature · 1 line
2.29.2
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dan Carpenter

The > comparison should be >= to prevent accessing one element beyond the end of the dev->vlans[] array in the caller function, b53_vlan_add(). The "dev->vlans" array is allocated in the b53_switch_init() function and it has "dev->num_vlans" elements.

Fixes a2482d2ce349 ("net: dsa: b53: Plug in VLAN support")
Signature · 1 line
Florian
maintainer Applied
#2 lore raw
Quoted 10 lines · On Tue, 19 Jan 2021 09:14:03 -0800 Florian Fainelli wrote:
Quoted 7 lines · Dan Carpenter

The > comparison should be >= to prevent accessing one element beyond the end of the dev->vlans[] array in the caller function, b53_vlan_add(). The "dev->vlans" array is allocated in the b53_switch_init() function and it has "dev->num_vlans" elements.

Fixes a2482d2ce349 ("net: dsa: b53: Plug in VLAN support")

Applied, thanks!