Skip to content

Commit f39acc8

Browse files
sladkanidavem330
authored andcommitted
net/sched: act_vlan: Push skb->data to mac_header prior calling skb_vlan_*() functions
Generic skb_vlan_push/skb_vlan_pop functions don't properly handle the case where the input skb data pointer does not point at the mac header: - They're doing push/pop, but fail to properly unwind data back to its original location. For example, in the skb_vlan_push case, any subsequent 'skb_push(skb, skb->mac_len)' calls make the skb->data point 4 bytes BEFORE start of frame, leading to bogus frames that may be transmitted. - They update rcsum per the added/removed 4 bytes tag. Alas if data is originally after the vlan/eth headers, then these bytes were already pulled out of the csum. OTOH calling skb_vlan_push/skb_vlan_pop with skb->data at mac_header present no issues. act_vlan is the only caller to skb_vlan_*() that has skb->data pointing at network header (upon ingress). Other calles (ovs, bpf) already adjust skb->data at mac_header. This patch fixes act_vlan to point to the mac_header prior calling skb_vlan_*() functions, as other callers do. Signed-off-by: Shmulik Ladkani <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Pravin Shelar <[email protected]> Cc: Jiri Pirko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f814bfd commit f39acc8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

net/sched/act_vlan.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ static int tcf_vlan(struct sk_buff *skb, const struct tc_action *a,
3737
bstats_update(&v->tcf_bstats, skb);
3838
action = v->tcf_action;
3939

40+
/* Ensure 'data' points at mac_header prior calling vlan manipulating
41+
* functions.
42+
*/
43+
if (skb_at_tc_ingress(skb))
44+
skb_push_rcsum(skb, skb->mac_len);
45+
4046
switch (v->tcfv_action) {
4147
case TCA_VLAN_ACT_POP:
4248
err = skb_vlan_pop(skb);
@@ -83,6 +89,9 @@ static int tcf_vlan(struct sk_buff *skb, const struct tc_action *a,
8389
action = TC_ACT_SHOT;
8490
v->tcf_qstats.drops++;
8591
unlock:
92+
if (skb_at_tc_ingress(skb))
93+
skb_pull_rcsum(skb, skb->mac_len);
94+
8695
spin_unlock(&v->tcf_lock);
8796
return action;
8897
}

0 commit comments

Comments
 (0)