Skip to content

Commit fa4e0f8

Browse files
dcarattidavem330
authored andcommitted
net/sched: fix corrupted L2 header with MPLS 'push' and 'pop' actions
the following script: # tc qdisc add dev eth0 clsact # tc filter add dev eth0 egress protocol ip matchall \ > action mpls push protocol mpls_uc label 0x355aa bos 1 causes corruption of all IP packets transmitted by eth0. On TC egress, we can't rely on the value of skb->mac_len, because it's 0 and a MPLS 'push' operation will result in an overwrite of the first 4 octets in the packet L2 header (e.g. the Destination Address if eth0 is an Ethernet); the same error pattern is present also in the MPLS 'pop' operation. Fix this error in act_mpls data plane, computing 'mac_len' as the difference between the network header and the mac header (when not at TC ingress), and use it in MPLS 'push'/'pop' core functions. v2: unbreak 'make htmldocs' because of missing documentation of 'mac_len' in skb_mpls_pop(), reported by kbuild test robot CC: Lorenzo Bianconi <lorenzo@kernel.org> Fixes: 2a2ea50 ("net: sched: add mpls manipulation actions to TC") Reviewed-by: Simon Horman <simon.horman@netronome.com> Acked-by: John Hurley <john.hurley@netronome.com> Signed-off-by: Davide Caratti <dcaratti@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent dedc5a0 commit fa4e0f8

4 files changed

Lines changed: 25 additions & 16 deletions

File tree

‎include/linux/skbuff.h‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3510,8 +3510,9 @@ int skb_ensure_writable(struct sk_buff *skb, int write_len);
35103510
int __skb_vlan_pop(struct sk_buff *skb, u16 *vlan_tci);
35113511
int skb_vlan_pop(struct sk_buff *skb);
35123512
int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
3513-
int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto);
3514-
int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto);
3513+
int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
3514+
int mac_len);
3515+
int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len);
35153516
int skb_mpls_update_lse(struct sk_buff *skb, __be32 mpls_lse);
35163517
int skb_mpls_dec_ttl(struct sk_buff *skb);
35173518
struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy,

‎net/core/skbuff.c‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5477,12 +5477,14 @@ static void skb_mod_eth_type(struct sk_buff *skb, struct ethhdr *hdr,
54775477
* @skb: buffer
54785478
* @mpls_lse: MPLS label stack entry to push
54795479
* @mpls_proto: ethertype of the new MPLS header (expects 0x8847 or 0x8848)
5480+
* @mac_len: length of the MAC header
54805481
*
54815482
* Expects skb->data at mac header.
54825483
*
54835484
* Returns 0 on success, -errno otherwise.
54845485
*/
5485-
int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto)
5486+
int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
5487+
int mac_len)
54865488
{
54875489
struct mpls_shim_hdr *lse;
54885490
int err;
@@ -5499,15 +5501,15 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto)
54995501
return err;
55005502

55015503
if (!skb->inner_protocol) {
5502-
skb_set_inner_network_header(skb, skb->mac_len);
5504+
skb_set_inner_network_header(skb, mac_len);
55035505
skb_set_inner_protocol(skb, skb->protocol);
55045506
}
55055507

55065508
skb_push(skb, MPLS_HLEN);
55075509
memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
5508-
skb->mac_len);
5510+
mac_len);
55095511
skb_reset_mac_header(skb);
5510-
skb_set_network_header(skb, skb->mac_len);
5512+
skb_set_network_header(skb, mac_len);
55115513

55125514
lse = mpls_hdr(skb);
55135515
lse->label_stack_entry = mpls_lse;
@@ -5526,29 +5528,30 @@ EXPORT_SYMBOL_GPL(skb_mpls_push);
55265528
*
55275529
* @skb: buffer
55285530
* @next_proto: ethertype of header after popped MPLS header
5531+
* @mac_len: length of the MAC header
55295532
*
55305533
* Expects skb->data at mac header.
55315534
*
55325535
* Returns 0 on success, -errno otherwise.
55335536
*/
5534-
int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto)
5537+
int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len)
55355538
{
55365539
int err;
55375540

55385541
if (unlikely(!eth_p_mpls(skb->protocol)))
55395542
return 0;
55405543

5541-
err = skb_ensure_writable(skb, skb->mac_len + MPLS_HLEN);
5544+
err = skb_ensure_writable(skb, mac_len + MPLS_HLEN);
55425545
if (unlikely(err))
55435546
return err;
55445547

55455548
skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN);
55465549
memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
5547-
skb->mac_len);
5550+
mac_len);
55485551

55495552
__skb_pull(skb, MPLS_HLEN);
55505553
skb_reset_mac_header(skb);
5551-
skb_set_network_header(skb, skb->mac_len);
5554+
skb_set_network_header(skb, mac_len);
55525555

55535556
if (skb->dev && skb->dev->type == ARPHRD_ETHER) {
55545557
struct ethhdr *hdr;

‎net/openvswitch/actions.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key,
165165
{
166166
int err;
167167

168-
err = skb_mpls_push(skb, mpls->mpls_lse, mpls->mpls_ethertype);
168+
err = skb_mpls_push(skb, mpls->mpls_lse, mpls->mpls_ethertype,
169+
skb->mac_len);
169170
if (err)
170171
return err;
171172

@@ -178,7 +179,7 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
178179
{
179180
int err;
180181

181-
err = skb_mpls_pop(skb, ethertype);
182+
err = skb_mpls_pop(skb, ethertype, skb->mac_len);
182183
if (err)
183184
return err;
184185

‎net/sched/act_mpls.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,33 @@ static int tcf_mpls_act(struct sk_buff *skb, const struct tc_action *a,
5555
struct tcf_mpls *m = to_mpls(a);
5656
struct tcf_mpls_params *p;
5757
__be32 new_lse;
58-
int ret;
58+
int ret, mac_len;
5959

6060
tcf_lastuse_update(&m->tcf_tm);
6161
bstats_cpu_update(this_cpu_ptr(m->common.cpu_bstats), skb);
6262

6363
/* Ensure 'data' points at mac_header prior calling mpls manipulating
6464
* functions.
6565
*/
66-
if (skb_at_tc_ingress(skb))
66+
if (skb_at_tc_ingress(skb)) {
6767
skb_push_rcsum(skb, skb->mac_len);
68+
mac_len = skb->mac_len;
69+
} else {
70+
mac_len = skb_network_header(skb) - skb_mac_header(skb);
71+
}
6872

6973
ret = READ_ONCE(m->tcf_action);
7074

7175
p = rcu_dereference_bh(m->mpls_p);
7276

7377
switch (p->tcfm_action) {
7478
case TCA_MPLS_ACT_POP:
75-
if (skb_mpls_pop(skb, p->tcfm_proto))
79+
if (skb_mpls_pop(skb, p->tcfm_proto, mac_len))
7680
goto drop;
7781
break;
7882
case TCA_MPLS_ACT_PUSH:
7983
new_lse = tcf_mpls_get_lse(NULL, p, !eth_p_mpls(skb->protocol));
80-
if (skb_mpls_push(skb, new_lse, p->tcfm_proto))
84+
if (skb_mpls_push(skb, new_lse, p->tcfm_proto, mac_len))
8185
goto drop;
8286
break;
8387
case TCA_MPLS_ACT_MODIFY:

0 commit comments

Comments
 (0)