1. 13 Feb, 2021 4 commits
    • Jesper Dangaard Brouer's avatar
      bpf: Add BPF-helper for MTU checking · 34b2021c
      Jesper Dangaard Brouer authored
      This BPF-helper bpf_check_mtu() works for both XDP and TC-BPF programs.
      
      The SKB object is complex and the skb->len value (accessible from
      BPF-prog) also include the length of any extra GRO/GSO segments, but
      without taking into account that these GRO/GSO segments get added
      transport (L4) and network (L3) headers before being transmitted. Thus,
      this BPF-helper is created such that the BPF-programmer don't need to
      handle these details in the BPF-prog.
      
      The API is designed to help the BPF-programmer, that want to do packet
      context size changes, which involves other helpers. These other helpers
      usually does a delta size adjustment. This helper also support a delta
      size (len_diff), which allow BPF-programmer to reuse arguments needed by
      these other helpers, and perform the MTU check prior to doing any actual
      size adjustment of the packet context.
      
      It is on purpose, that we allow the len adjustment to become a negative
      result, that will pass the MTU check. This might seem weird, but it's not
      this helpers responsibility to "catch" wrong len_diff adjustments. Other
      helpers will take care of these checks, if BPF-programmer chooses to do
      actual size adjustment.
      
      V14:
       - Improve man-page desc of len_diff.
      
      V13:
       - Enforce flag BPF_MTU_CHK_SEGS cannot use len_diff.
      
      V12:
       - Simplify segment check that calls skb_gso_validate_network_len.
       - Helpers should return long
      
      V9:
      - Use dev->hard_header_len (instead of ETH_HLEN)
      - Annotate with unlikely req from Daniel
      - Fix logic error using skb_gso_validate_network_len from Daniel
      
      V6:
      - Took John's advice and dropped BPF_MTU_CHK_RELAX
      - Returned MTU is kept at L3-level (like fib_lookup)
      
      V4: Lot of changes
       - ifindex 0 now use current netdev for MTU lookup
       - rename helper from bpf_mtu_check to bpf_check_mtu
       - fix bug for GSO pkt length (as skb->len is total len)
       - remove __bpf_len_adj_positive, simply allow negative len adj
      Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/161287790461.790810.3429728639563297353.stgit@firesoul
      34b2021c
    • Jesper Dangaard Brouer's avatar
      bpf: bpf_fib_lookup return MTU value as output when looked up · e1850ea9
      Jesper Dangaard Brouer authored
      The BPF-helpers for FIB lookup (bpf_xdp_fib_lookup and bpf_skb_fib_lookup)
      can perform MTU check and return BPF_FIB_LKUP_RET_FRAG_NEEDED. The BPF-prog
      don't know the MTU value that caused this rejection.
      
      If the BPF-prog wants to implement PMTU (Path MTU Discovery) (rfc1191) it
      need to know this MTU value for the ICMP packet.
      
      Patch change lookup and result struct bpf_fib_lookup, to contain this MTU
      value as output via a union with 'tot_len' as this is the value used for
      the MTU lookup.
      
      V5:
       - Fixed uninit value spotted by Dan Carpenter.
       - Name struct output member mtu_result
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
      Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/161287789952.790810.13134700381067698781.stgit@firesoul
      e1850ea9
    • Jesper Dangaard Brouer's avatar
      bpf: Fix bpf_fib_lookup helper MTU check for SKB ctx · 2c0a10af
      Jesper Dangaard Brouer authored
      BPF end-user on Cilium slack-channel (Carlo Carraro) wants to use
      bpf_fib_lookup for doing MTU-check, but *prior* to extending packet size,
      by adjusting fib_params 'tot_len' with the packet length plus the expected
      encap size. (Just like the bpf_check_mtu helper supports). He discovered
      that for SKB ctx the param->tot_len was not used, instead skb->len was used
      (via MTU check in is_skb_forwardable() that checks against netdev MTU).
      
      Fix this by using fib_params 'tot_len' for MTU check. If not provided (e.g.
      zero) then keep existing TC behaviour intact. Notice that 'tot_len' for MTU
      check is done like XDP code-path, which checks against FIB-dst MTU.
      
      V16:
      - Revert V13 optimization, 2nd lookup is against egress/resulting netdev
      
      V13:
      - Only do ifindex lookup one time, calling dev_get_by_index_rcu().
      
      V10:
      - Use same method as XDP for 'tot_len' MTU check
      
      Fixes: 4c79579b ("bpf: Change bpf_fib_lookup to return lookup status")
      Reported-by: default avatarCarlo Carraro <colrack@gmail.com>
      Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Link: https://lore.kernel.org/bpf/161287789444.790810.15247494756551413508.stgit@firesoul
      2c0a10af
    • Jesper Dangaard Brouer's avatar
      bpf: Remove MTU check in __bpf_skb_max_len · 6306c118
      Jesper Dangaard Brouer authored
      Multiple BPF-helpers that can manipulate/increase the size of the SKB uses
      __bpf_skb_max_len() as the max-length. This function limit size against
      the current net_device MTU (skb->dev->mtu).
      
      When a BPF-prog grow the packet size, then it should not be limited to the
      MTU. The MTU is a transmit limitation, and software receiving this packet
      should be allowed to increase the size. Further more, current MTU check in
      __bpf_skb_max_len uses the MTU from ingress/current net_device, which in
      case of redirects uses the wrong net_device.
      
      This patch keeps a sanity max limit of SKB_MAX_ALLOC (16KiB). The real limit
      is elsewhere in the system. Jesper's testing[1] showed it was not possible
      to exceed 8KiB when expanding the SKB size via BPF-helper. The limiting
      factor is the define KMALLOC_MAX_CACHE_SIZE which is 8192 for
      SLUB-allocator (CONFIG_SLUB) in-case PAGE_SIZE is 4096. This define is
      in-effect due to this being called from softirq context see code
      __gfp_pfmemalloc_flags() and __do_kmalloc_node(). Jakub's testing showed
      that frames above 16KiB can cause NICs to reset (but not crash). Keep this
      sanity limit at this level as memory layer can differ based on kernel
      config.
      
      [1] https://github.com/xdp-project/bpf-examples/tree/master/MTU-testsSigned-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
      Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
      Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
      Link: https://lore.kernel.org/bpf/161287788936.790810.2937823995775097177.stgit@firesoul
      6306c118
  2. 12 Feb, 2021 18 commits
  3. 11 Feb, 2021 10 commits
  4. 10 Feb, 2021 8 commits