Skip to content

Commit e0d7968

Browse files
Toshiaki Makitadavem330
Toshiaki Makita
authored andcommitted
bridge: Prevent insertion of FDB entry with disallowed vlan
br_handle_local_finish() is allowing us to insert an FDB entry with disallowed vlan. For example, when port 1 and 2 are communicating in vlan 10, and even if vlan 10 is disallowed on port 3, port 3 can interfere with their communication by spoofed src mac address with vlan id 10. Note: Even if it is judged that a frame should not be learned, it should not be dropped because it is destined for not forwarding layer but higher layer. See IEEE 802.1Q-2011 8.13.10. Signed-off-by: Toshiaki Makita <[email protected]> Acked-by: Vlad Yasevich <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bfc5184 commit e0d7968

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

net/bridge/br_input.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ static int br_handle_local_finish(struct sk_buff *skb)
147147
struct net_bridge_port *p = br_port_get_rcu(skb->dev);
148148
u16 vid = 0;
149149

150-
br_vlan_get_tag(skb, &vid);
151-
if (p->flags & BR_LEARNING)
150+
/* check if vlan is allowed, to avoid spoofing */
151+
if (p->flags & BR_LEARNING && br_should_learn(p, skb, &vid))
152152
br_fdb_update(p->br, p, eth_hdr(skb)->h_source, vid, false);
153153
return 0; /* process further */
154154
}

net/bridge/br_private.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ bool br_allowed_ingress(struct net_bridge *br, struct net_port_vlans *v,
581581
struct sk_buff *skb, u16 *vid);
582582
bool br_allowed_egress(struct net_bridge *br, const struct net_port_vlans *v,
583583
const struct sk_buff *skb);
584+
bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid);
584585
struct sk_buff *br_handle_vlan(struct net_bridge *br,
585586
const struct net_port_vlans *v,
586587
struct sk_buff *skb);
@@ -648,6 +649,12 @@ static inline bool br_allowed_egress(struct net_bridge *br,
648649
return true;
649650
}
650651

652+
static inline bool br_should_learn(struct net_bridge_port *p,
653+
struct sk_buff *skb, u16 *vid)
654+
{
655+
return true;
656+
}
657+
651658
static inline struct sk_buff *br_handle_vlan(struct net_bridge *br,
652659
const struct net_port_vlans *v,
653660
struct sk_buff *skb)

net/bridge/br_vlan.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,34 @@ bool br_allowed_egress(struct net_bridge *br,
241241
return false;
242242
}
243243

244+
/* Called under RCU */
245+
bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
246+
{
247+
struct net_bridge *br = p->br;
248+
struct net_port_vlans *v;
249+
250+
if (!br->vlan_enabled)
251+
return true;
252+
253+
v = rcu_dereference(p->vlan_info);
254+
if (!v)
255+
return false;
256+
257+
br_vlan_get_tag(skb, vid);
258+
if (!*vid) {
259+
*vid = br_get_pvid(v);
260+
if (*vid == VLAN_N_VID)
261+
return false;
262+
263+
return true;
264+
}
265+
266+
if (test_bit(*vid, v->vlan_bitmap))
267+
return true;
268+
269+
return false;
270+
}
271+
244272
/* Must be protected by RTNL.
245273
* Must be called with vid in range from 1 to 4094 inclusive.
246274
*/

0 commit comments

Comments
 (0)