Commit 48cc32d3 authored by Florian Zumbiehl's avatar Florian Zumbiehl Committed by David S. Miller

vlan: don't deliver frames for unknown vlans to protocols

6a32e4f9 made the vlan code skip marking
vlan-tagged frames for not locally configured vlans as PACKET_OTHERHOST if
there was an rx_handler, as the rx_handler could cause the frame to be received
on a different (virtual) vlan-capable interface where that vlan might be
configured.

As rx_handlers do not necessarily return RX_HANDLER_ANOTHER, this could cause
frames for unknown vlans to be delivered to the protocol stack as if they had
been received untagged.

For example, if an ipv6 router advertisement that's tagged for a locally not
configured vlan is received on an interface with macvlan interfaces attached,
macvlan's rx_handler returns RX_HANDLER_PASS after delivering the frame to the
macvlan interfaces, which caused it to be passed to the protocol stack, leading
to ipv6 addresses for the announced prefix being configured even though those
are completely unusable on the underlying interface.

The fix moves marking as PACKET_OTHERHOST after the rx_handler so the
rx_handler, if there is one, sees the frame unchanged, but afterwards,
before the frame is delivered to the protocol stack, it gets marked whether
there is an rx_handler or not.
Signed-off-by: default avatarFlorian Zumbiehl <florz@florz.de>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2e71a6f8
...@@ -80,6 +80,8 @@ static inline int is_vlan_dev(struct net_device *dev) ...@@ -80,6 +80,8 @@ static inline int is_vlan_dev(struct net_device *dev)
} }
#define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT) #define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT)
#define vlan_tx_nonzero_tag_present(__skb) \
(vlan_tx_tag_present(__skb) && ((__skb)->vlan_tci & VLAN_VID_MASK))
#define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) #define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT)
#if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
...@@ -89,7 +91,7 @@ extern struct net_device *__vlan_find_dev_deep(struct net_device *real_dev, ...@@ -89,7 +91,7 @@ extern struct net_device *__vlan_find_dev_deep(struct net_device *real_dev,
extern struct net_device *vlan_dev_real_dev(const struct net_device *dev); extern struct net_device *vlan_dev_real_dev(const struct net_device *dev);
extern u16 vlan_dev_vlan_id(const struct net_device *dev); extern u16 vlan_dev_vlan_id(const struct net_device *dev);
extern bool vlan_do_receive(struct sk_buff **skb, bool last_handler); extern bool vlan_do_receive(struct sk_buff **skb);
extern struct sk_buff *vlan_untag(struct sk_buff *skb); extern struct sk_buff *vlan_untag(struct sk_buff *skb);
extern int vlan_vid_add(struct net_device *dev, unsigned short vid); extern int vlan_vid_add(struct net_device *dev, unsigned short vid);
...@@ -120,10 +122,8 @@ static inline u16 vlan_dev_vlan_id(const struct net_device *dev) ...@@ -120,10 +122,8 @@ static inline u16 vlan_dev_vlan_id(const struct net_device *dev)
return 0; return 0;
} }
static inline bool vlan_do_receive(struct sk_buff **skb, bool last_handler) static inline bool vlan_do_receive(struct sk_buff **skb)
{ {
if (((*skb)->vlan_tci & VLAN_VID_MASK) && last_handler)
(*skb)->pkt_type = PACKET_OTHERHOST;
return false; return false;
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#include <linux/export.h> #include <linux/export.h>
#include "vlan.h" #include "vlan.h"
bool vlan_do_receive(struct sk_buff **skbp, bool last_handler) bool vlan_do_receive(struct sk_buff **skbp)
{ {
struct sk_buff *skb = *skbp; struct sk_buff *skb = *skbp;
u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK; u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK;
...@@ -13,14 +13,8 @@ bool vlan_do_receive(struct sk_buff **skbp, bool last_handler) ...@@ -13,14 +13,8 @@ bool vlan_do_receive(struct sk_buff **skbp, bool last_handler)
struct vlan_pcpu_stats *rx_stats; struct vlan_pcpu_stats *rx_stats;
vlan_dev = vlan_find_dev(skb->dev, vlan_id); vlan_dev = vlan_find_dev(skb->dev, vlan_id);
if (!vlan_dev) { if (!vlan_dev)
/* Only the last call to vlan_do_receive() should change
* pkt_type to PACKET_OTHERHOST
*/
if (vlan_id && last_handler)
skb->pkt_type = PACKET_OTHERHOST;
return false; return false;
}
skb = *skbp = skb_share_check(skb, GFP_ATOMIC); skb = *skbp = skb_share_check(skb, GFP_ATOMIC);
if (unlikely(!skb)) if (unlikely(!skb))
......
...@@ -3300,18 +3300,18 @@ static int __netif_receive_skb(struct sk_buff *skb) ...@@ -3300,18 +3300,18 @@ static int __netif_receive_skb(struct sk_buff *skb)
&& !skb_pfmemalloc_protocol(skb)) && !skb_pfmemalloc_protocol(skb))
goto drop; goto drop;
rx_handler = rcu_dereference(skb->dev->rx_handler);
if (vlan_tx_tag_present(skb)) { if (vlan_tx_tag_present(skb)) {
if (pt_prev) { if (pt_prev) {
ret = deliver_skb(skb, pt_prev, orig_dev); ret = deliver_skb(skb, pt_prev, orig_dev);
pt_prev = NULL; pt_prev = NULL;
} }
if (vlan_do_receive(&skb, !rx_handler)) if (vlan_do_receive(&skb))
goto another_round; goto another_round;
else if (unlikely(!skb)) else if (unlikely(!skb))
goto unlock; goto unlock;
} }
rx_handler = rcu_dereference(skb->dev->rx_handler);
if (rx_handler) { if (rx_handler) {
if (pt_prev) { if (pt_prev) {
ret = deliver_skb(skb, pt_prev, orig_dev); ret = deliver_skb(skb, pt_prev, orig_dev);
...@@ -3331,6 +3331,9 @@ static int __netif_receive_skb(struct sk_buff *skb) ...@@ -3331,6 +3331,9 @@ static int __netif_receive_skb(struct sk_buff *skb)
} }
} }
if (vlan_tx_nonzero_tag_present(skb))
skb->pkt_type = PACKET_OTHERHOST;
/* deliver only exact match when indicated */ /* deliver only exact match when indicated */
null_or_dev = deliver_exact ? skb->dev : NULL; null_or_dev = deliver_exact ? skb->dev : NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment