Skip to content

Commit 3e3aac4

Browse files
edumazetdavem330
authored andcommitted
vlan: fix a race in egress prio management
egress_priority_map[] hash table updates are protected by rtnl, and we never remove elements until device is dismantled. We have to make sure that before inserting an new element in hash table, all its fields are committed to memory or else another cpu could find corrupt values and crash. Signed-off-by: Eric Dumazet <[email protected]> Cc: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d4b812d commit 3e3aac4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

net/8021q/vlan_dev.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ vlan_dev_get_egress_qos_mask(struct net_device *dev, struct sk_buff *skb)
7373
{
7474
struct vlan_priority_tci_mapping *mp;
7575

76+
smp_rmb(); /* coupled with smp_wmb() in vlan_dev_set_egress_priority() */
77+
7678
mp = vlan_dev_priv(dev)->egress_priority_map[(skb->priority & 0xF)];
7779
while (mp) {
7880
if (mp->priority == skb->priority) {
@@ -249,6 +251,11 @@ int vlan_dev_set_egress_priority(const struct net_device *dev,
249251
np->next = mp;
250252
np->priority = skb_prio;
251253
np->vlan_qos = vlan_qos;
254+
/* Before inserting this element in hash table, make sure all its fields
255+
* are committed to memory.
256+
* coupled with smp_rmb() in vlan_dev_get_egress_qos_mask()
257+
*/
258+
smp_wmb();
252259
vlan->egress_priority_map[skb_prio & 0xF] = np;
253260
if (vlan_qos)
254261
vlan->nr_egress_mappings++;

0 commit comments

Comments
 (0)