TC 'csum' action needs to read the packets' ethertype. In case the value is encoded in unstripped/nested VLAN headers, call pskb_may_pull() to be sure that all tags are in the linear part of skb. While at it, move this code in a helper function: other TC actions (like 'pedit' and 'skbedit') might need to read the innermost ethertype.
Fixes: 2ecba2d1e45b ("net: sched: act_csum: Fix csum calc for tagged packets") CC: Eli Britstein <el...@mellanox.com> CC: Li Shuang <shu...@redhat.com> Suggested-by: Eric Dumazet <eric.duma...@gmail.com> Signed-off-by: Davide Caratti <dcara...@redhat.com> --- include/net/pkt_cls.h | 21 +++++++++++++++++++++ net/sched/act_csum.c | 14 ++------------ 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index 514e3c80ecc1..0215dfbda9ac 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -953,4 +953,25 @@ struct tc_root_qopt_offload { bool ingress; }; +static inline int tc_skb_pull_vlans(struct sk_buff *skb, + unsigned int *hdr_count, + __be16 *proto) +{ + if (skb_vlan_tag_present(skb)) + *proto = skb->protocol; + + while (eth_type_vlan(*proto)) { + struct vlan_hdr *vlan; + + if (unlikely(!pskb_may_pull(skb, VLAN_HLEN))) + return -ENOMEM; + + vlan = (struct vlan_hdr *)skb->data; + *proto = vlan->h_vlan_encapsulated_proto; + skb_pull(skb, VLAN_HLEN); + skb_reset_network_header(skb); + (*hdr_count)++; + } + return 0; +} #endif diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c index 14bb525e355e..e8308ddcae9d 100644 --- a/net/sched/act_csum.c +++ b/net/sched/act_csum.c @@ -574,7 +574,6 @@ static int tcf_csum_act(struct sk_buff *skb, const struct tc_action *a, struct tcf_result *res) { struct tcf_csum *p = to_tcf_csum(a); - bool orig_vlan_tag_present = false; unsigned int vlan_hdr_count = 0; struct tcf_csum_params *params; u32 update_flags; @@ -604,17 +603,8 @@ static int tcf_csum_act(struct sk_buff *skb, const struct tc_action *a, break; case cpu_to_be16(ETH_P_8021AD): /* fall through */ case cpu_to_be16(ETH_P_8021Q): - if (skb_vlan_tag_present(skb) && !orig_vlan_tag_present) { - protocol = skb->protocol; - orig_vlan_tag_present = true; - } else { - struct vlan_hdr *vlan = (struct vlan_hdr *)skb->data; - - protocol = vlan->h_vlan_encapsulated_proto; - skb_pull(skb, VLAN_HLEN); - skb_reset_network_header(skb); - vlan_hdr_count++; - } + if (tc_skb_pull_vlans(skb, &vlan_hdr_count, &protocol)) + goto drop; goto again; } -- 2.20.1