0221-bpf-add-skb_postpush_rcsum-and-fix-dev_forward_skb-o.patch 3.9 KB

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