Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: a bug fix and test cases for bpf_skb_change_tail() #4722

Closed
wants to merge 4 commits into from

Commits on Dec 6, 2024

  1. bpf: Check negative offsets in __bpf_skb_min_len()

    skb_network_offset() and skb_transport_offset() can be negative when
    they are called after we pull the transport header, for example, when
    we use eBPF sockmap at the point of ->sk_data_ready().
    
    __bpf_skb_min_len() uses an unsigned int to get these offsets, this
    leads to a very large number which then causes bpf_skb_change_tail()
    failed unexpectedly.
    
    Fix this by using a signed int to get these offsets and ensure the
    minimum is at least zero.
    
    Fixes: 5293efe ("bpf: add bpf_skb_change_tail helper")
    Cc: John Fastabend <[email protected]>
    Cc: Daniel Borkmann <[email protected]>
    Signed-off-by: Cong Wang <[email protected]>
    Cong Wang authored and Kernel Patches Daemon committed Dec 6, 2024
    Configuration menu
    Copy the full SHA
    531f6cb View commit details
    Browse the repository at this point in the history
  2. selftests/bpf: Add a BPF selftest for bpf_skb_change_tail()

    As requested by Daniel, we need to add a selftest to cover
    bpf_skb_change_tail() cases in skb_verdict. Here we test trimming,
    growing and error cases, and validate its expected return values and the
    expected sizes of the payload.
    
    Cc: John Fastabend <[email protected]>
    Cc: Daniel Borkmann <[email protected]>
    Cc: Zijian Zhang <[email protected]>
    Signed-off-by: Cong Wang <[email protected]>
    Cong Wang authored and Kernel Patches Daemon committed Dec 6, 2024
    Configuration menu
    Copy the full SHA
    b385e42 View commit details
    Browse the repository at this point in the history
  3. selftests/bpf: Introduce socket_helpers.h for TC tests

    Pull socket helpers out of sockmap_helpers.h so that they can be reused
    for TC tests as well. This prepares for the next patch.
    
    Cc: John Fastabend <[email protected]>
    Cc: Daniel Borkmann <[email protected]>
    Cc: Zijian Zhang <[email protected]>
    Signed-off-by: Cong Wang <[email protected]>
    Cong Wang authored and Kernel Patches Daemon committed Dec 6, 2024
    Configuration menu
    Copy the full SHA
    d2b30a2 View commit details
    Browse the repository at this point in the history
  4. selftests/bpf: Test bpf_skb_change_tail() in TC ingress

    Similarly to the previous test, we also need a test case to cover
    positive offsets as well, TC is an excellent hook for this.
    
    Cc: John Fastabend <[email protected]>
    Cc: Daniel Borkmann <[email protected]>
    Cc: Zijian Zhang <[email protected]>
    Signed-off-by: Cong Wang <[email protected]>
    Cong Wang authored and Kernel Patches Daemon committed Dec 6, 2024
    Configuration menu
    Copy the full SHA
    f3b08dc View commit details
    Browse the repository at this point in the history