brcm2708: update linux 4.4 patches to latest version
[openwrt/staging/lynxis/omap.git] / target / linux / brcm2708 / patches-4.4 / 0221-bpf-add-skb_postpush_rcsum-and-fix-dev_forward_skb-o.patch
1 From 367956e87b62ae1f015ccbff58c7920a2e7a3511 Mon Sep 17 00:00:00 2001
2 From: Daniel Borkmann <daniel@iogearbox.net>
3 Date: Thu, 7 Jan 2016 15:50:23 +0100
4 Subject: [PATCH 221/423] bpf: add skb_postpush_rcsum and fix dev_forward_skb
5 occasions
6
7 Add a small helper skb_postpush_rcsum() and fix up redirect locations
8 that need CHECKSUM_COMPLETE fixups on ingress. dev_forward_skb() expects
9 a proper csum that covers also Ethernet header, f.e. since 2c26d34bbcc0
10 ("net/core: Handle csum for CHECKSUM_COMPLETE VXLAN forwarding"), we
11 also do skb_postpull_rcsum() after pulling Ethernet header off via
12 eth_type_trans().
13
14 When using eBPF in a netns setup f.e. with vxlan in collect metadata mode,
15 I can trigger the following csum issue with an IPv6 setup:
16
17 [ 505.144065] dummy1: hw csum failure
18 [...]
19 [ 505.144108] Call Trace:
20 [ 505.144112] <IRQ> [<ffffffff81372f08>] dump_stack+0x44/0x5c
21 [ 505.144134] [<ffffffff81607cea>] netdev_rx_csum_fault+0x3a/0x40
22 [ 505.144142] [<ffffffff815fee3f>] __skb_checksum_complete+0xcf/0xe0
23 [ 505.144149] [<ffffffff816f0902>] nf_ip6_checksum+0xb2/0x120
24 [ 505.144161] [<ffffffffa08c0e0e>] icmpv6_error+0x17e/0x328 [nf_conntrack_ipv6]
25 [ 505.144170] [<ffffffffa0898eca>] ? ip6t_do_table+0x2fa/0x645 [ip6_tables]
26 [ 505.144177] [<ffffffffa08c0725>] ? ipv6_get_l4proto+0x65/0xd0 [nf_conntrack_ipv6]
27 [ 505.144189] [<ffffffffa06c9a12>] nf_conntrack_in+0xc2/0x5a0 [nf_conntrack]
28 [ 505.144196] [<ffffffffa08c039c>] ipv6_conntrack_in+0x1c/0x20 [nf_conntrack_ipv6]
29 [ 505.144204] [<ffffffff8164385d>] nf_iterate+0x5d/0x70
30 [ 505.144210] [<ffffffff816438d6>] nf_hook_slow+0x66/0xc0
31 [ 505.144218] [<ffffffff816bd302>] ipv6_rcv+0x3f2/0x4f0
32 [ 505.144225] [<ffffffff816bca40>] ? ip6_make_skb+0x1b0/0x1b0
33 [ 505.144232] [<ffffffff8160b77b>] __netif_receive_skb_core+0x36b/0x9a0
34 [ 505.144239] [<ffffffff8160bdc8>] ? __netif_receive_skb+0x18/0x60
35 [ 505.144245] [<ffffffff8160bdc8>] __netif_receive_skb+0x18/0x60
36 [ 505.144252] [<ffffffff8160ccff>] process_backlog+0x9f/0x140
37 [ 505.144259] [<ffffffff8160c4a5>] net_rx_action+0x145/0x320
38 [...]
39
40 What happens is that on ingress, we push Ethernet header back in, either
41 from cls_bpf or right before skb_do_redirect(), but without updating csum.
42 The "hw csum failure" can be fixed by using the new skb_postpush_rcsum()
43 helper for the dev_forward_skb() case to correct the csum diff again.
44
45 Thanks to Hannes Frederic Sowa for the csum_partial() idea!
46
47 Fixes: 3896d655f4d4 ("bpf: introduce bpf_clone_redirect() helper")
48 Fixes: 27b29f63058d ("bpf: add bpf_redirect() helper")
49 Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
50 Acked-by: Alexei Starovoitov <ast@kernel.org>
51 Signed-off-by: David S. Miller <davem@davemloft.net>
52 ---
53 net/core/filter.c | 17 +++++++++++++----
54 1 file changed, 13 insertions(+), 4 deletions(-)
55
56 --- a/net/core/filter.c
57 +++ b/net/core/filter.c
58 @@ -1293,8 +1293,9 @@ static u64 bpf_skb_store_bytes(u64 r1, u
59 /* skb_store_bits cannot return -EFAULT here */
60 skb_store_bits(skb, offset, ptr, len);
61
62 - if (BPF_RECOMPUTE_CSUM(flags) && skb->ip_summed == CHECKSUM_COMPLETE)
63 - skb->csum = csum_add(skb->csum, csum_partial(ptr, len, 0));
64 + if (BPF_RECOMPUTE_CSUM(flags))
65 + skb_postpush_rcsum(skb, ptr, len);
66 +
67 return 0;
68 }
69
70 @@ -1420,8 +1421,12 @@ static u64 bpf_clone_redirect(u64 r1, u6
71 if (unlikely(!skb2))
72 return -ENOMEM;
73
74 - if (BPF_IS_REDIRECT_INGRESS(flags))
75 + if (BPF_IS_REDIRECT_INGRESS(flags)) {
76 + if (skb_at_tc_ingress(skb2))
77 + skb_postpush_rcsum(skb2, skb_mac_header(skb2),
78 + skb2->mac_len);
79 return dev_forward_skb(dev, skb2);
80 + }
81
82 skb2->dev = dev;
83 skb_sender_cpu_clear(skb2);
84 @@ -1464,8 +1469,12 @@ int skb_do_redirect(struct sk_buff *skb)
85 return -EINVAL;
86 }
87
88 - if (BPF_IS_REDIRECT_INGRESS(ri->flags))
89 + if (BPF_IS_REDIRECT_INGRESS(ri->flags)) {
90 + if (skb_at_tc_ingress(skb))
91 + skb_postpush_rcsum(skb, skb_mac_header(skb),
92 + skb->mac_len);
93 return dev_forward_skb(dev, skb);
94 + }
95
96 skb->dev = dev;
97 skb_sender_cpu_clear(skb);