Skip to contentSkip to conversation

bridge: pass correct vlan id to multicast code

PATCH Applied Vlad Yasevich 5 participants 7 messages Oct 28, 2013 – Oct 29, 2013

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

PATCH 1/1 bridge: pass correct vlan id to multicast code

Currently multicast code attempts to extrace the vlan id from the skb even when vlan filtering is disabled. This can lead to mdb entries being created with the wrong vlan id. Pass the already extracted vlan id to the multicast filtering code to make the correct id is used in creation as well as lookup.

---
 net/bridge/br_device.c    |  2 +-
 net/bridge/br_input.c     |  2 +-
 net/bridge/br_multicast.c | 44 +++++++++++++++++++-------------------------
 net/bridge/br_private.h   |  6 ++++--
 4 files changed, 25 insertions(+), 29 deletions(-)
net/bridge/br_device.c +1 -1
index ca04163..e6b7fec 100644
@@ -64,7 +64,7 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
 			br_flood_deliver(br, skb, false);
 			goto out;
 		}
-		if (br_multicast_rcv(br, NULL, skb)) {
+		if (br_multicast_rcv(br, NULL, skb, vid)) {
 			kfree_skb(skb);
 			goto out;
 		}
net/bridge/br_input.c +1 -1
index a2fd37e..7e73c32 100644
@@ -80,7 +80,7 @@ int br_handle_frame_finish(struct sk_buff *skb)
 		br_fdb_update(br, p, eth_hdr(skb)->h_source, vid);
 
 	if (!is_broadcast_ether_addr(dest) && is_multicast_ether_addr(dest) &&
-	    br_multicast_rcv(br, p, skb))
+	    br_multicast_rcv(br, p, skb, vid))
 		goto drop;
 
 	if (p->state == BR_STATE_LEARNING)
net/bridge/br_multicast.c +19 -25

178 lines not on this page · raw message

net/bridge/br_private.h +4 -2
index e14c33b..2e8244e 100644
@@ -451,7 +451,8 @@ extern int br_ioctl_deviceless_stub(struct net *net, unsigned int cmd, void __us
 extern unsigned int br_mdb_rehash_seq;
 extern int br_multicast_rcv(struct net_bridge *br,
 			    struct net_bridge_port *port,
-			    struct sk_buff *skb);
+			    struct sk_buff *skb,
+			    u16 vid);
 extern struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
 					       struct sk_buff *skb, u16 vid);
 extern void br_multicast_add_port(struct net_bridge_port *port);
@@ -522,7 +523,8 @@ static inline bool br_multicast_querier_exists(struct net_bridge *br,
 #else
 static inline int br_multicast_rcv(struct net_bridge *br,
 				   struct net_bridge_port *port,
-				   struct sk_buff *skb)
+				   struct sk_buff *skb,
+				   u16 vid)
 {
 	return 0;
 }
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Vlad Yasevich

Currently multicast code attempts to extrace the vlan id from the skb even when vlan filtering is disabled. This can lead to mdb entries being created with the wrong vlan id. Pass the already extracted vlan id to the multicast filtering code to make the correct id is used in creation as well as lookup.

Hi Vlad,

Can we just update br_vlan_get_tag() to set vid to 0 if dev->vlan is disabled? I guess it would effect br_handle_local_finish().

Quoted 7 lines
---
 net/bridge/br_device.c    |  2 +-
 net/bridge/br_input.c     |  2 +-
 net/bridge/br_multicast.c | 44 +++++++++++++++++++-------------------------
 net/bridge/br_private.h   |  6 ++++--
 4 files changed, 25 insertions(+), 29 deletions(-)

...

Quoted 15 lines
net/bridge/br_multicast.c +2 -1
index 8b0b610..686284f 100644
@@ -947,7 +947,8 @@ void br_multicast_disable_port(struct net_bridge_port *port)
 
 static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 					 struct net_bridge_port *port,
-					 struct sk_buff *skb)
+					 struct sk_buff *skb,
+					 u16 vid)
 {
 	struct igmpv3_report *ih;
 	struct igmpv3_grec *grec;

net/bridge/br_multicast.c static int br_ip4_multicast_igmp3_report(struct net_bridge *br, · line 965

Quoted 9 lines
net/bridge/br_multicast.c +0 -2
@@ -957,12 +958,10 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 	int type;
 	int err = 0;
 	__be32 group;
-	u16 vid = 0;
 
 	if (!pskb_may_pull(skb, sizeof(*ih)))
 		return -EINVAL;
 
-	br_vlan_get_tag(skb, &vid);

After applied the patch, we always use vid in br_dev_xmit()->br_allowed_ingress(), is it possible that the vlan of bridge is re-enabled when other changed functions are called?

We can just add a enabled checking before this kind of br_vlan_get_tag()?

if (!br->vlan_enabled)

    br_vlan_get_tag(skb2, &vid);
Quoted 3 lines
net/bridge/br_multicast.c +0 -0
 	ih = igmpv3_report_hdr(skb);
 	num = ntohs(ih->ngrec);
 	len = sizeof(*ih);

...

Signature · 1 line
			Amos.
#2 lore raw
Quoted 7 lines · Amos Kong
Quoted 6 lines · Vlad Yasevich

Currently multicast code attempts to extrace the vlan id from the skb even when vlan filtering is disabled. This can lead to mdb entries being created with the wrong vlan id. Pass the already extracted vlan id to the multicast filtering code to make the correct id is used in creation as well as lookup.

Thanks!

Quoted 5 lines

Hi Vlad,

Can we just update br_vlan_get_tag() to set vid to 0 if dev->vlan is disabled? I guess it would effect br_handle_local_finish().

br_handle_local_finish() looks also buggy.
But adding vlan enabled checking would not fix it completely because vlan_bitmap and PVID are not taken into account in that function.

Since we cannot pass vid as an argument from br_dev_xmit() to br_handle_[local/frame]_finish() because of NF_HOOK, br_handle_local_finish() seems to have to check vlan_enabled, vlan_bitmap, and pvid by itself.

IMHO it can be addressed by another patch.

Quoted 40 lines
Quoted 8 lines
---
 net/bridge/br_device.c    |  2 +-
 net/bridge/br_input.c     |  2 +-
 net/bridge/br_multicast.c | 44 +++++++++++++++++++-------------------------
 net/bridge/br_private.h   |  6 ++++--
 4 files changed, 25 insertions(+), 29 deletions(-)

...

Quoted 15 lines
net/bridge/br_multicast.c +2 -1
index 8b0b610..686284f 100644
@@ -947,7 +947,8 @@ void br_multicast_disable_port(struct net_bridge_port *port)
 
 static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 					 struct net_bridge_port *port,
-					 struct sk_buff *skb)
+					 struct sk_buff *skb,
+					 u16 vid)
 {
 	struct igmpv3_report *ih;
 	struct igmpv3_grec *grec;

net/bridge/br_multicast.c static int br_ip4_multicast_igmp3_report(struct net_bridge *br, · line 965

Quoted 9 lines
net/bridge/br_multicast.c +0 -2
@@ -957,12 +958,10 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 	int type;
 	int err = 0;
 	__be32 group;
-	u16 vid = 0;
 
 	if (!pskb_may_pull(skb, sizeof(*ih)))
 		return -EINVAL;
 
-	br_vlan_get_tag(skb, &vid);

After applied the patch, we always use vid in br_dev_xmit()->br_allowed_ingress(), is it possible that the vlan of bridge is re-enabled when other changed functions are called?

Quoted 4 lines

We can just add a enabled checking before this kind of br_vlan_get_tag()?

if (!br->vlan_enabled)

    br_vlan_get_tag(skb2, &vid);

Maybe this leads to a wrong way to update mdb in some cases like
Vlan_filtering is disabled (by default).
Add some vids we want to allow.
Receive a frame whose vid wouldn't be allowed with vlan_filtering enabled. The frame passes br_allowed_ingress().
Enable vlan_filtering.
The frame reaches br_ip4_multicast_igmp3_report().
Mdb is updated with disabled vid.

Thanks,

Toshiaki Makita

Quoted 8 lines
Quoted 5 lines
net/bridge/br_multicast.c +0 -0
 	ih = igmpv3_report_hdr(skb);
 	num = ntohs(ih->ngrec);
 	len = sizeof(*ih);

...

#4 lore raw
In reply to Amos Kong
Quoted 8 lines · Amos Kong
Quoted 6 lines · Vlad Yasevich

Currently multicast code attempts to extrace the vlan id from the skb even when vlan filtering is disabled. This can lead to mdb entries being created with the wrong vlan id. Pass the already extracted vlan id to the multicast filtering code to make the correct id is used in creation as well as lookup.

Quoted 4 lines

Hi Vlad,

Can we just update br_vlan_get_tag() to set vid to 0 if dev->vlan is disabled? I guess it would effect br_handle_local_finish().

I have another patch that refactors the br_vlan_get_tag() and that would address this issue. I am testing it now.

I am hoping to simplify the patch a bit though since I am not crazy about the function signature that br_vlan_get_tag() gets.

-vlad

Quoted 52 lines
Quoted 8 lines
---
  net/bridge/br_device.c    |  2 +-
  net/bridge/br_input.c     |  2 +-
  net/bridge/br_multicast.c | 44 +++++++++++++++++++-------------------------
  net/bridge/br_private.h   |  6 ++++--
  4 files changed, 25 insertions(+), 29 deletions(-)

...

Quoted 15 lines
net/bridge/br_multicast.c +2 -1
index 8b0b610..686284f 100644
@@ -947,7 +947,8 @@ void br_multicast_disable_port(struct net_bridge_port *port)
 
  static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
  					 struct net_bridge_port *port,
-					 struct sk_buff *skb)
+					 struct sk_buff *skb,
+					 u16 vid)
  {
  	struct igmpv3_report *ih;
  	struct igmpv3_grec *grec;

net/bridge/br_multicast.c static int br_ip4_multicast_igmp3_report(struct net_bridge *br, · line 965

Quoted 9 lines
net/bridge/br_multicast.c +0 -2
@@ -957,12 +958,10 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
  	int type;
  	int err = 0;
  	__be32 group;
-	u16 vid = 0;
 
  	if (!pskb_may_pull(skb, sizeof(*ih)))
  		return -EINVAL;
 
-	br_vlan_get_tag(skb, &vid);

After applied the patch, we always use vid in br_dev_xmit()->br_allowed_ingress(), is it possible that the vlan of bridge is re-enabled when other changed functions are called?

We can just add a enabled checking before this kind of br_vlan_get_tag()?

if (!br->vlan_enabled)

     br_vlan_get_tag(skb2, &vid);
Quoted 3 lines
net/bridge/br_multicast.c +0 -0
  	ih = igmpv3_report_hdr(skb);
  	num = ntohs(ih->ngrec);
  	len = sizeof(*ih);

...

#3 lore raw
In reply to Toshiaki Makita
Quoted 84 lines · Toshiaki Makita
Quoted 7 lines · Amos Kong
Quoted 6 lines · Vlad Yasevich

Currently multicast code attempts to extrace the vlan id from the skb even when vlan filtering is disabled. This can lead to mdb entries being created with the wrong vlan id. Pass the already extracted vlan id to the multicast filtering code to make the correct id is used in creation as well as lookup.

Thanks!

Quoted 5 lines

Hi Vlad,

Can we just update br_vlan_get_tag() to set vid to 0 if dev->vlan is disabled? I guess it would effect br_handle_local_finish().

br_handle_local_finish() looks also buggy.
But adding vlan enabled checking would not fix it completely because vlan_bitmap and PVID are not taken into account in that function.

Since we cannot pass vid as an argument from br_dev_xmit() to br_handle_[local/frame]_finish() because of NF_HOOK, br_handle_local_finish() seems to have to check vlan_enabled, vlan_bitmap, and pvid by itself.

IMHO it can be addressed by another patch.

Quoted 39 lines
Quoted 7 lines
---
 net/bridge/br_device.c    |  2 +-
 net/bridge/br_input.c     |  2 +-
 net/bridge/br_multicast.c | 44 +++++++++++++++++++-------------------------
 net/bridge/br_private.h   |  6 ++++--
 4 files changed, 25 insertions(+), 29 deletions(-)

...

Quoted 15 lines
net/bridge/br_multicast.c +2 -1
index 8b0b610..686284f 100644
@@ -947,7 +947,8 @@ void br_multicast_disable_port(struct net_bridge_port *port)
 
 static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 					 struct net_bridge_port *port,
-					 struct sk_buff *skb)
+					 struct sk_buff *skb,
+					 u16 vid)
 {
 	struct igmpv3_report *ih;
 	struct igmpv3_grec *grec;

net/bridge/br_multicast.c static int br_ip4_multicast_igmp3_report(struct net_bridge *br, · line 965

Quoted 9 lines
net/bridge/br_multicast.c +0 -2
@@ -957,12 +958,10 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
 	int type;
 	int err = 0;
 	__be32 group;
-	u16 vid = 0;
 
 	if (!pskb_may_pull(skb, sizeof(*ih)))
 		return -EINVAL;
 
-	br_vlan_get_tag(skb, &vid);

After applied the patch, we always use vid in br_dev_xmit()->br_allowed_ingress(), is it possible that the vlan of bridge is re-enabled when other changed functions are called?

Quoted 4 lines

We can just add a enabled checking before this kind of br_vlan_get_tag()?

if (!br->vlan_enabled)

    br_vlan_get_tag(skb2, &vid);

Maybe this leads to a wrong way to update mdb in some cases like
Vlan_filtering is disabled (by default).
Add some vids we want to allow.
Receive a frame whose vid wouldn't be allowed with vlan_filtering enabled. The frame passes br_allowed_ingress().
Enable vlan_filtering.
The frame reaches br_ip4_multicast_igmp3_report().
Mdb is updated with disabled vid.

Quoted 3 lines

Thanks,

Toshiaki Makita

Thanks all your explanation, I'm ok with the patch.

Signature · 1 line
			Amos.
#5 lore raw
In reply to Amos Kong
Quoted 22 lines · Amos Kong
Quoted 20 lines · Vlad Yasevich
net/bridge/br_multicast.c +2 -2
index 8b0b610..686284f 100644
@@ -947,7 +947,8 @@ void br_multicast_disable_port(struct net_bridge_port *port)
 
  static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
  					 struct net_bridge_port *port,
-					 struct sk_buff *skb)
+					 struct sk_buff *skb,
+					 u16 vid)
  {
  	struct igmpv3_report *ih;
  	struct igmpv3_grec *grec;
@@ -957,12 +958,10 @@ static int br_ip4_multicast_igmp3_report(struct net_bridge *br,
  	int type;
  	int err = 0;
  	__be32 group;
-	u16 vid = 0;
 
Quoted 5 lines

net/bridge/br_multicast.c static int br_ip4_multicast_igmp3_report(struct net_bridge *br, · line 965

Quoted 4 lines
net/bridge/br_multicast.c +0 -1
  	if (!pskb_may_pull(skb, sizeof(*ih)))
  		return -EINVAL;
 
-	br_vlan_get_tag(skb, &vid);

Sorry, missed this question last time.

Quoted 4 lines

After applied the patch, we always use vid in br_dev_xmit()->br_allowed_ingress(), is it possible that the vlan of bridge is re-enabled when other changed functions are called?

If the frame was allowed to enter, then the current configuration should apply the the frame. If the config changes during the frame processing we don't really want to use that. Otherwise, you'd get
inconsistent results.

Quoted 5 lines

We can just add a enabled checking before this kind of br_vlan_get_tag()?

if (!br->vlan_enabled)

     br_vlan_get_tag(skb2, &vid);

This sort of what the next patches I am working on do. But we still want to get the vlan id once and then use it throught out. There is no need to retrieve it again.

-vlad

Quoted 7 lines
Quoted 4 lines
net/bridge/br_multicast.c +0 -0
  	ih = igmpv3_report_hdr(skb);
  	num = ntohs(ih->ngrec);
  	len = sizeof(*ih);

...

maintainer Applied
#6 lore raw
In reply to Vlad Yasevich

From: Vlad Yasevich <[email protected]>
Date: Mon, 28 Oct 2013 15:45:07 -0400

Quoted 8 lines

Currently multicast code attempts to extrace the vlan id from the skb even when vlan filtering is disabled. This can lead to mdb entries being created with the wrong vlan id. Pass the already extracted vlan id to the multicast filtering code to make the correct id is used in creation as well as lookup.

Applied, thanks Vlad and others.