Skip to content

Commit 8a83a00

Browse files
arndbdavem330
authored andcommitted
net: maintain namespace isolation between vlan and real device
In the vlan and macvlan drivers, the start_xmit function forwards data to the dev_queue_xmit function for another device, which may potentially belong to a different namespace. To make sure that classification stays within a single namespace, this resets the potentially critical fields. Signed-off-by: Arnd Bergmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6884b34 commit 8a83a00

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

drivers/net/macvlan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ static int macvlan_queue_xmit(struct sk_buff *skb, struct net_device *dev)
269269
}
270270

271271
xmit_world:
272-
skb->dev = vlan->lowerdev;
272+
skb_set_dev(skb, vlan->lowerdev);
273273
return dev_queue_xmit(skb);
274274
}
275275

include/linux/netdevice.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,15 @@ static inline bool netdev_uses_dsa_tags(struct net_device *dev)
10041004
return 0;
10051005
}
10061006

1007+
#ifndef CONFIG_NET_NS
1008+
static inline void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
1009+
{
1010+
skb->dev = dev;
1011+
}
1012+
#else /* CONFIG_NET_NS */
1013+
void skb_set_dev(struct sk_buff *skb, struct net_device *dev);
1014+
#endif
1015+
10071016
static inline bool netdev_uses_trailer_tags(struct net_device *dev)
10081017
{
10091018
#ifdef CONFIG_NET_DSA_TAG_TRAILER

net/8021q/vlan_dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ static netdev_tx_t vlan_dev_hard_start_xmit(struct sk_buff *skb,
322322
}
323323

324324

325-
skb->dev = vlan_dev_info(dev)->real_dev;
325+
skb_set_dev(skb, vlan_dev_info(dev)->real_dev);
326326
len = skb->len;
327327
ret = dev_queue_xmit(skb);
328328

net/core/dev.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,13 +1448,10 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
14481448
if (skb->len > (dev->mtu + dev->hard_header_len))
14491449
return NET_RX_DROP;
14501450

1451-
skb_dst_drop(skb);
1451+
skb_set_dev(skb, dev);
14521452
skb->tstamp.tv64 = 0;
14531453
skb->pkt_type = PACKET_HOST;
14541454
skb->protocol = eth_type_trans(skb, dev);
1455-
skb->mark = 0;
1456-
secpath_reset(skb);
1457-
nf_reset(skb);
14581455
return netif_rx(skb);
14591456
}
14601457
EXPORT_SYMBOL_GPL(dev_forward_skb);
@@ -1614,6 +1611,36 @@ static bool dev_can_checksum(struct net_device *dev, struct sk_buff *skb)
16141611
return false;
16151612
}
16161613

1614+
/**
1615+
* skb_dev_set -- assign a new device to a buffer
1616+
* @skb: buffer for the new device
1617+
* @dev: network device
1618+
*
1619+
* If an skb is owned by a device already, we have to reset
1620+
* all data private to the namespace a device belongs to
1621+
* before assigning it a new device.
1622+
*/
1623+
#ifdef CONFIG_NET_NS
1624+
void skb_set_dev(struct sk_buff *skb, struct net_device *dev)
1625+
{
1626+
skb_dst_drop(skb);
1627+
if (skb->dev && !net_eq(dev_net(skb->dev), dev_net(dev))) {
1628+
secpath_reset(skb);
1629+
nf_reset(skb);
1630+
skb_init_secmark(skb);
1631+
skb->mark = 0;
1632+
skb->priority = 0;
1633+
skb->nf_trace = 0;
1634+
skb->ipvs_property = 0;
1635+
#ifdef CONFIG_NET_SCHED
1636+
skb->tc_index = 0;
1637+
#endif
1638+
}
1639+
skb->dev = dev;
1640+
}
1641+
EXPORT_SYMBOL(skb_set_dev);
1642+
#endif /* CONFIG_NET_NS */
1643+
16171644
/*
16181645
* Invalidate hardware checksum when packet is to be mangled, and
16191646
* complete checksum manually on outgoing path.

0 commit comments

Comments
 (0)