30 Sep, 2020

1 commit

  • In preempt kernel, BPF_PROG_TEST_RUN on raw_tp triggers:

    [ 35.874974] BUG: using smp_processor_id() in preemptible [00000000]
    code: new_name/87
    [ 35.893983] caller is bpf_prog_test_run_raw_tp+0xd4/0x1b0
    [ 35.900124] CPU: 1 PID: 87 Comm: new_name Not tainted 5.9.0-rc6-g615bd02bf #1
    [ 35.907358] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996),
    BIOS 1.10.2-1ubuntu1 04/01/2014
    [ 35.916941] Call Trace:
    [ 35.919660] dump_stack+0x77/0x9b
    [ 35.923273] check_preemption_disabled+0xb4/0xc0
    [ 35.928376] bpf_prog_test_run_raw_tp+0xd4/0x1b0
    [ 35.933872] ? selinux_bpf+0xd/0x70
    [ 35.937532] __do_sys_bpf+0x6bb/0x21e0
    [ 35.941570] ? find_held_lock+0x2d/0x90
    [ 35.945687] ? vfs_write+0x150/0x220
    [ 35.949586] do_syscall_64+0x2d/0x40
    [ 35.953443] entry_SYSCALL_64_after_hwframe+0x44/0xa9

    Fix this by calling migrate_disable() before smp_processor_id().

    Fixes: 1b4d60ec162f ("bpf: Enable BPF_PROG_TEST_RUN for raw_tracepoint")
    Reported-by: Alexei Starovoitov
    Signed-off-by: Song Liu
    Signed-off-by: Alexei Starovoitov

    Song Liu
     

29 Sep, 2020

1 commit

  • Add .test_run for raw_tracepoint. Also, introduce a new feature that runs
    the target program on a specific CPU. This is achieved by a new flag in
    bpf_attr.test, BPF_F_TEST_RUN_ON_CPU. When this flag is set, the program
    is triggered on cpu with id bpf_attr.test.cpu. This feature is needed for
    BPF programs that handle perf_event and other percpu resources, as the
    program can access these resource locally.

    Signed-off-by: Song Liu
    Signed-off-by: Daniel Borkmann
    Acked-by: John Fastabend
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20200925205432.1777-2-songliubraving@fb.com

    Song Liu
     

24 Aug, 2020

1 commit

  • Replace the existing /* fall through */ comments and its variants with
    the new pseudo-keyword macro fallthrough[1]. Also, remove unnecessary
    fall-through markings when it is the case.

    [1] https://www.kernel.org/doc/html/v5.7/process/deprecated.html?highlight=fallthrough#implicit-switch-case-fall-through

    Signed-off-by: Gustavo A. R. Silva

    Gustavo A. R. Silva
     

04 Aug, 2020

2 commits

  • Now skb->dev is unconditionally set to the loopback device in current net
    namespace. But if we want to test bpf program which contains code branch
    based on ifindex condition (eg filters out localhost packets) it is useful
    to allow specifying of ifindex from userspace. This patch adds such option
    through ctx_in (__sk_buff) parameter.

    Signed-off-by: Dmitry Yakunin
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20200803090545.82046-3-zeil@yandex-team.ru

    Dmitry Yakunin
     
  • Now it's impossible to test all branches of cgroup_skb bpf program which
    accesses skb->family and skb->{local,remote}_ip{4,6} fields because they
    are zeroed during socket allocation. This commit fills socket family and
    addresses from related fields in constructed skb.

    Signed-off-by: Dmitry Yakunin
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20200803090545.82046-2-zeil@yandex-team.ru

    Dmitry Yakunin
     

01 Jul, 2020

1 commit

  • Add two tests for PTR_TO_BTF_ID vs. null ptr comparison,
    one for PTR_TO_BTF_ID in the ctx structure and the
    other for PTR_TO_BTF_ID after one level pointer chasing.
    In both cases, the test ensures condition is not
    removed.

    For example, for this test
    struct bpf_fentry_test_t {
    struct bpf_fentry_test_t *a;
    };
    int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
    {
    if (arg == 0)
    test7_result = 1;
    return 0;
    }
    Before the previous verifier change, we have xlated codes:
    int test7(long long unsigned int * ctx):
    ; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
    0: (79) r1 = *(u64 *)(r1 +0)
    ; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
    1: (b4) w0 = 0
    2: (95) exit
    After the previous verifier change, we have:
    int test7(long long unsigned int * ctx):
    ; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
    0: (79) r1 = *(u64 *)(r1 +0)
    ; if (arg == 0)
    1: (55) if r1 != 0x0 goto pc+4
    ; test7_result = 1;
    2: (18) r1 = map[id:6][0]+48
    4: (b7) r2 = 1
    5: (7b) *(u64 *)(r1 +0) = r2
    ; int BPF_PROG(test7, struct bpf_fentry_test_t *arg)
    6: (b4) w0 = 0
    7: (95) exit

    Signed-off-by: Yonghong Song
    Signed-off-by: Daniel Borkmann
    Acked-by: John Fastabend
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20200630171241.2523875-1-yhs@fb.com

    Yonghong Song
     

19 May, 2020

1 commit

  • Commit bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
    recently changed bpf_prog_test_run_xdp() to use larger frames for XDP in
    order to test tail growing frames (via bpf_xdp_adjust_tail) and to have
    memory backing frame better resemble drivers.

    The commit contains a bug, as it tries to copy the max data size from
    userspace, instead of the size provided by userspace. This cause XDP
    unit tests to fail sporadically with EFAULT, an unfortunate behavior.
    The fix is to only copy the size specified by userspace.

    Fixes: bc56c919fce7 ("bpf: Add xdp.frame_sz in bpf_prog_test_run_xdp().")
    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/158980712729.256597.6115007718472928659.stgit@firesoul

    Jesper Dangaard Brouer
     

15 May, 2020

1 commit

  • Update the memory requirements, when adding xdp.frame_sz in BPF test_run
    function bpf_prog_test_run_xdp() which e.g. is used by XDP selftests.

    Specifically add the expected reserved tailroom, but also allocated a
    larger memory area to reflect that XDP frames usually comes in this
    format. Limit the provided packet data size to 4096 minus headroom +
    tailroom, as this also reflect a common 3520 bytes MTU limit with XDP.

    Note that bpf_test_init already use a memory allocation method that clears
    memory. Thus, this already guards against leaking uninit kernel memory.

    Signed-off-by: Jesper Dangaard Brouer
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/158945349549.97035.15316291762482444006.stgit@firesoul

    Jesper Dangaard Brouer
     

29 Mar, 2020

1 commit

  • Fix build warnings when building net/bpf/test_run.o with W=1 due
    to missing prototype for bpf_fentry_test{1..6}.

    Instead of declaring prototypes, turn off warnings with
    __diag_{push,ignore,pop} as pointed out by Alexei.

    Signed-off-by: Jean-Philippe Menil
    Signed-off-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20200327204713.28050-1-jpmenil@gmail.com

    Jean-Philippe Menil
     

05 Mar, 2020

2 commits

  • Test for two scenarios:

    * When the fmod_ret program returns 0, the original function should
    be called along with fentry and fexit programs.
    * When the fmod_ret program returns a non-zero value, the original
    function should not be called, no side effect should be observed and
    fentry and fexit programs should be called.

    The result from the kernel function call and whether a side-effect is
    observed is returned via the retval attr of the BPF_PROG_TEST_RUN (bpf)
    syscall.

    Signed-off-by: KP Singh
    Signed-off-by: Alexei Starovoitov
    Acked-by: Andrii Nakryiko
    Acked-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20200304191853.1529-8-kpsingh@chromium.org

    KP Singh
     
  • The current fexit and fentry tests rely on a different program to
    exercise the functions they attach to. Instead of doing this, implement
    the test operations for tracing which will also be used for
    BPF_MODIFY_RETURN in a subsequent patch.

    Also, clean up the fexit test to use the generated skeleton.

    Signed-off-by: KP Singh
    Signed-off-by: Alexei Starovoitov
    Acked-by: Andrii Nakryiko
    Acked-by: Daniel Borkmann
    Link: https://lore.kernel.org/bpf/20200304191853.1529-7-kpsingh@chromium.org

    KP Singh
     

04 Mar, 2020

1 commit

  • BPF programs may want to know whether an skb is gso. The canonical
    answer is skb_is_gso(skb), which tests that gso_size != 0.

    Expose this field in the same manner as gso_segs. That field itself
    is not a sufficient signal, as the comment in skb_shared_info makes
    clear: gso_segs may be zero, e.g., from dodgy sources.

    Also prepare net/bpf/test_run for upcoming BPF_PROG_TEST_RUN tests
    of the feature.

    Signed-off-by: Willem de Bruijn
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20200303200503.226217-2-willemdebruijn.kernel@gmail.com

    Willem de Bruijn
     

25 Feb, 2020

1 commit

  • Replace the preemption disable/enable with migrate_disable/enable() to
    reflect the actual requirement and to allow PREEMPT_RT to substitute it
    with an actual migration disable mechanism which does not disable
    preemption.

    [ tglx: Switched it over to migrate disable ]

    Signed-off-by: David S. Miller
    Signed-off-by: Thomas Gleixner
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20200224145643.785306549@linutronix.de

    David Miller
     

19 Dec, 2019

1 commit


14 Dec, 2019

2 commits


11 Dec, 2019

1 commit

  • Switch existing pattern of "offsetof(..., member) + FIELD_SIZEOF(...,
    member)' to "offsetofend(..., member)" which does exactly what
    we need without all the copy-paste.

    Suggested-by: Andrii Nakryiko
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann
    Acked-by: Andrii Nakryiko
    Link: https://lore.kernel.org/bpf/20191210191933.105321-1-sdf@google.com

    Stanislav Fomichev
     

19 Nov, 2019

1 commit

  • The error return path on when bpf_fentry_test* tests fail does not
    kfree 'data'. Fix this by adding the missing kfree.

    Addresses-Coverity: ("Resource leak")

    Fixes: faeb2dce084a ("bpf: Add kernel test functions for fentry testing")
    Signed-off-by: Colin Ian King
    Signed-off-by: Alexei Starovoitov
    Link: https://lore.kernel.org/bpf/20191118114059.37287-1-colin.king@canonical.com

    Colin Ian King
     

16 Nov, 2019

1 commit

  • Add few kernel functions with various number of arguments,
    their types and sizes for BPF trampoline testing to cover
    different calling conventions.

    Signed-off-by: Alexei Starovoitov
    Signed-off-by: Daniel Borkmann
    Acked-by: Song Liu
    Link: https://lore.kernel.org/bpf/20191114185720.1641606-9-ast@kernel.org

    Alexei Starovoitov
     

16 Oct, 2019

1 commit

  • It's useful for implementing EDT related tests (set tstamp, run the
    test, see how the tstamp is changed or observe some other parameter).

    Note that bpf_ktime_get_ns() helper is using monotonic clock, so for
    the BPF programs that compare tstamp against it, tstamp should be
    derived from clock_gettime(CLOCK_MONOTONIC, ...).

    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Alexei Starovoitov
    Acked-by: Martin KaFai Lau
    Link: https://lore.kernel.org/bpf/20191015183125.124413-1-sdf@google.com

    Stanislav Fomichev
     

26 Jul, 2019

2 commits

  • This will allow us to write tests for those flags.

    v2:
    * Swap kfree(data) and kfree(user_ctx) (Song Liu)

    Acked-by: Petar Penkov
    Acked-by: Willem de Bruijn
    Acked-by: Song Liu
    Cc: Song Liu
    Cc: Willem de Bruijn
    Cc: Petar Penkov
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Alexei Starovoitov

    Stanislav Fomichev
     
  • C flow dissector supports input flags that tell it to customize parsing
    by either stopping early or trying to parse as deep as possible. Pass
    those flags to the BPF flow dissector so it can make the same
    decisions. In the next commits I'll add support for those flags to
    our reference bpf_flow.c

    v3:
    * Export copy of flow dissector flags instead of moving (Alexei Starovoitov)

    Acked-by: Petar Penkov
    Acked-by: Willem de Bruijn
    Acked-by: Song Liu
    Cc: Song Liu
    Cc: Willem de Bruijn
    Cc: Petar Penkov
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Alexei Starovoitov

    Stanislav Fomichev
     

31 May, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this program is free software you can redistribute it and or modify
    it under the terms of version 2 of the gnu general public license as
    published by the free software foundation

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 107 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Allison Randal
    Reviewed-by: Richard Fontana
    Reviewed-by: Steve Winslow
    Reviewed-by: Alexios Zavras
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190528171438.615055994@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

21 May, 2019

1 commit


28 Apr, 2019

1 commit

  • After allowing a bpf prog to
    - directly read the skb->sk ptr
    - get the fullsock bpf_sock by "bpf_sk_fullsock()"
    - get the bpf_tcp_sock by "bpf_tcp_sock()"
    - get the listener sock by "bpf_get_listener_sock()"
    - avoid duplicating the fields of "(bpf_)sock" and "(bpf_)tcp_sock"
    into different bpf running context.

    this patch is another effort to make bpf's network programming
    more intuitive to do (together with memory and performance benefit).

    When bpf prog needs to store data for a sk, the current practice is to
    define a map with the usual 4-tuples (src/dst ip/port) as the key.
    If multiple bpf progs require to store different sk data, multiple maps
    have to be defined. Hence, wasting memory to store the duplicated
    keys (i.e. 4 tuples here) in each of the bpf map.
    [ The smallest key could be the sk pointer itself which requires
    some enhancement in the verifier and it is a separate topic. ]

    Also, the bpf prog needs to clean up the elem when sk is freed.
    Otherwise, the bpf map will become full and un-usable quickly.
    The sk-free tracking currently could be done during sk state
    transition (e.g. BPF_SOCK_OPS_STATE_CB).

    The size of the map needs to be predefined which then usually ended-up
    with an over-provisioned map in production. Even the map was re-sizable,
    while the sk naturally come and go away already, this potential re-size
    operation is arguably redundant if the data can be directly connected
    to the sk itself instead of proxy-ing through a bpf map.

    This patch introduces sk->sk_bpf_storage to provide local storage space
    at sk for bpf prog to use. The space will be allocated when the first bpf
    prog has created data for this particular sk.

    The design optimizes the bpf prog's lookup (and then optionally followed by
    an inline update). bpf_spin_lock should be used if the inline update needs
    to be protected.

    BPF_MAP_TYPE_SK_STORAGE:
    -----------------------
    To define a bpf "sk-local-storage", a BPF_MAP_TYPE_SK_STORAGE map (new in
    this patch) needs to be created. Multiple BPF_MAP_TYPE_SK_STORAGE maps can
    be created to fit different bpf progs' needs. The map enforces
    BTF to allow printing the sk-local-storage during a system-wise
    sk dump (e.g. "ss -ta") in the future.

    The purpose of a BPF_MAP_TYPE_SK_STORAGE map is not for lookup/update/delete
    a "sk-local-storage" data from a particular sk.
    Think of the map as a meta-data (or "type") of a "sk-local-storage". This
    particular "type" of "sk-local-storage" data can then be stored in any sk.

    The main purposes of this map are mostly:
    1. Define the size of a "sk-local-storage" type.
    2. Provide a similar syscall userspace API as the map (e.g. lookup/update,
    map-id, map-btf...etc.)
    3. Keep track of all sk's storages of this "type" and clean them up
    when the map is freed.

    sk->sk_bpf_storage:
    ------------------
    The main lookup/update/delete is done on sk->sk_bpf_storage (which
    is a "struct bpf_sk_storage"). When doing a lookup,
    the "map" pointer is now used as the "key" to search on the
    sk_storage->list. The "map" pointer is actually serving
    as the "type" of the "sk-local-storage" that is being
    requested.

    To allow very fast lookup, it should be as fast as looking up an
    array at a stable-offset. At the same time, it is not ideal to
    set a hard limit on the number of sk-local-storage "type" that the
    system can have. Hence, this patch takes a cache approach.
    The last search result from sk_storage->list is cached in
    sk_storage->cache[] which is a stable sized array. Each
    "sk-local-storage" type has a stable offset to the cache[] array.
    In the future, a map's flag could be introduced to do cache
    opt-out/enforcement if it became necessary.

    The cache size is 16 (i.e. 16 types of "sk-local-storage").
    Programs can share map. On the program side, having a few bpf_progs
    running in the networking hotpath is already a lot. The bpf_prog
    should have already consolidated the existing sock-key-ed map usage
    to minimize the map lookup penalty. 16 has enough runway to grow.

    All sk-local-storage data will be removed from sk->sk_bpf_storage
    during sk destruction.

    bpf_sk_storage_get() and bpf_sk_storage_delete():
    ------------------------------------------------
    Instead of using bpf_map_(lookup|update|delete)_elem(),
    the bpf prog needs to use the new helper bpf_sk_storage_get() and
    bpf_sk_storage_delete(). The verifier can then enforce the
    ARG_PTR_TO_SOCKET argument. The bpf_sk_storage_get() also allows to
    "create" new elem if one does not exist in the sk. It is done by
    the new BPF_SK_STORAGE_GET_F_CREATE flag. An optional value can also be
    provided as the initial value during BPF_SK_STORAGE_GET_F_CREATE.
    The BPF_MAP_TYPE_SK_STORAGE also supports bpf_spin_lock. Together,
    it has eliminated the potential use cases for an equivalent
    bpf_map_update_elem() API (for bpf_prog) in this patch.

    Misc notes:
    ----------
    1. map_get_next_key is not supported. From the userspace syscall
    perspective, the map has the socket fd as the key while the map
    can be shared by pinned-file or map-id.

    Since btf is enforced, the existing "ss" could be enhanced to pretty
    print the local-storage.

    Supporting a kernel defined btf with 4 tuples as the return key could
    be explored later also.

    2. The sk->sk_lock cannot be acquired. Atomic operations is used instead.
    e.g. cmpxchg is done on the sk->sk_bpf_storage ptr.
    Please refer to the source code comments for the details in
    synchronization cases and considerations.

    3. The mem is charged to the sk->sk_omem_alloc as the sk filter does.

    Benchmark:
    ---------
    Here is the benchmark data collected by turning on
    the "kernel.bpf_stats_enabled" sysctl.
    Two bpf progs are tested:

    One bpf prog with the usual bpf hashmap (max_entries = 8192) with the
    sk ptr as the key. (verifier is modified to support sk ptr as the key
    That should have shortened the key lookup time.)

    Another bpf prog is with the new BPF_MAP_TYPE_SK_STORAGE.

    Both are storing a "u32 cnt", do a lookup on "egress_skb/cgroup" for
    each egress skb and then bump the cnt. netperf is used to drive
    data with 4096 connected UDP sockets.

    BPF_MAP_TYPE_HASH with a modifier verifier (152ns per bpf run)
    27: cgroup_skb name egress_sk_map tag 74f56e832918070b run_time_ns 58280107540 run_cnt 381347633
    loaded_at 2019-04-15T13:46:39-0700 uid 0
    xlated 344B jited 258B memlock 4096B map_ids 16
    btf_id 5

    BPF_MAP_TYPE_SK_STORAGE in this patch (66ns per bpf run)
    30: cgroup_skb name egress_sk_stora tag d4aa70984cc7bbf6 run_time_ns 25617093319 run_cnt 390989739
    loaded_at 2019-04-15T13:47:54-0700 uid 0
    xlated 168B jited 156B memlock 4096B map_ids 17
    btf_id 6

    Here is a high-level picture on how are the objects organized:

    sk
    ┌──────┐
    │ │
    │ │
    │ │
    │*sk_bpf_storage─────▶ bpf_sk_storage
    └──────┘ ┌───────┐
    ┌───────────┤ list │
    │ │ │
    │ │ │
    │ │ │
    │ └───────┘

    │ elem
    │ ┌────────┐
    ├─▶│ snode │
    │ ├────────┤
    │ │ data │ bpf_map
    │ ├────────┤ ┌─────────┐
    │ │map_node│◀─┬─────┤ list │
    │ └────────┘ │ │ │
    │ │ │ │
    │ elem │ │ │
    │ ┌────────┐ │ └─────────┘
    └─▶│ snode │ │
    ├────────┤ │
    bpf_map │ data │ │
    ┌─────────┐ ├────────┤ │
    │ list ├───────▶│map_node│ │
    │ │ └────────┘ │
    │ │ │
    │ │ elem │
    └─────────┘ ┌────────┐ │
    ┌─▶│ snode │ │
    │ ├────────┤ │
    │ │ data │ │
    │ ├────────┤ │
    │ │map_node│◀─┘
    │ └────────┘


    │ ┌───────┐
    sk └──────────│ list │
    ┌──────┐ │ │
    │ │ │ │
    │ │ │ │
    │ │ └───────┘
    │*sk_bpf_storage───────▶bpf_sk_storage
    └──────┘

    Signed-off-by: Martin KaFai Lau
    Signed-off-by: Alexei Starovoitov

    Martin KaFai Lau
     

27 Apr, 2019

1 commit

  • This tests that:
    * a BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE cannot be attached if it
    uses either:
    * a variable offset to the tracepoint buffer, or
    * an offset beyond the size of the tracepoint buffer
    * a tracer can modify the buffer provided when attached to a writable
    tracepoint in bpf_prog_test_run

    Signed-off-by: Matt Mullins
    Acked-by: Yonghong Song
    Signed-off-by: Alexei Starovoitov

    Matt Mullins
     

24 Apr, 2019

3 commits

  • Now that we use skb-less flow dissector let's return true nhoff and
    thoff. We used to adjust them by ETH_HLEN because that's how it was
    done in the skb case. For VLAN tests that looks confusing: nhoff is
    pointing to vlan parts :-\

    Warning, this is an API change for BPF_PROG_TEST_RUN! Feel free to drop
    if you think that it's too late at this point to fix it.

    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     
  • Now that we have bpf_flow_dissect which can work on raw data,
    use it when doing BPF_PROG_TEST_RUN for flow dissector.

    Simplifies bpf_prog_test_run_flow_dissector and allows us to
    test no-skb mode.

    Note, that previously, with bpf_flow_dissect_skb we used to call
    eth_type_trans which pulled L2 (ETH_HLEN) header and we explicitly called
    skb_reset_network_header. That means flow_keys->nhoff would be
    initialized to 0 (skb_network_offset) in init_flow_keys.
    Now we call bpf_flow_dissect with nhoff set to ETH_HLEN and need
    to undo it once the dissection is done to preserve the existing behavior.

    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     
  • struct bpf_flow_dissector has a small subset of sk_buff fields that
    flow dissector BPF program is allowed to access and an optional
    pointer to real skb. Real skb is used only in bpf_skb_load_bytes
    helper to read non-linear data.

    The real motivation for this is to be able to call flow dissector
    from eth_get_headlen context where we don't have an skb and need
    to dissect raw bytes.

    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     

12 Apr, 2019

2 commits

  • This should allow us later to extend BPF_PROG_TEST_RUN for non-skb case
    and be sure that nobody is erroneously setting ctx_{in,out}.

    Fixes: b0b9395d865e ("bpf: support input __sk_buff context in BPF_PROG_TEST_RUN")
    Reported-by: Daniel Borkmann
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     
  • Commit b0b9395d865e ("bpf: support input __sk_buff context in
    BPF_PROG_TEST_RUN") started using bpf_check_uarg_tail_zero in
    BPF_PROG_TEST_RUN. However, bpf_check_uarg_tail_zero is not defined
    for !CONFIG_BPF_SYSCALL:

    net/bpf/test_run.c: In function ‘bpf_ctx_init’:
    net/bpf/test_run.c:142:9: error: implicit declaration of function ‘bpf_check_uarg_tail_zero’ [-Werror=implicit-function-declaration]
    err = bpf_check_uarg_tail_zero(data_in, max_size, size);
    ^~~~~~~~~~~~~~~~~~~~~~~~

    Let's not build net/bpf/test_run.c when CONFIG_BPF_SYSCALL is not set.

    Reported-by: kbuild test robot
    Fixes: b0b9395d865e ("bpf: support input __sk_buff context in BPF_PROG_TEST_RUN")
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     

11 Apr, 2019

1 commit

  • Add new set of arguments to bpf_attr for BPF_PROG_TEST_RUN:
    * ctx_in/ctx_size_in - input context
    * ctx_out/ctx_size_out - output context

    The intended use case is to pass some meta data to the test runs that
    operate on skb (this has being brought up on recent LPC).

    For programs that use bpf_prog_test_run_skb, support __sk_buff input and
    output. Initially, from input __sk_buff, copy _only_ cb and priority into
    skb, all other non-zero fields are prohibited (with EINVAL).
    If the user has set ctx_out/ctx_size_out, copy the potentially modified
    __sk_buff back to the userspace.

    We require all fields of input __sk_buff except the ones we explicitly
    support to be set to zero. The expectation is that in the future we might
    add support for more fields and we want to fail explicitly if the user
    runs the program on the kernel where we don't yet support them.

    The API is intentionally vague (i.e. we don't explicitly add __sk_buff
    to bpf_attr, but ctx_in) to potentially let other test_run types use
    this interface in the future (this can be xdp_md for xdp types for
    example).

    v4:
    * don't copy more than allowed in bpf_ctx_init [Martin]

    v3:
    * handle case where ctx_in is NULL, but ctx_out is not [Martin]
    * convert size==0 checks to ptr==NULL checks and add some extra ptr
    checks [Martin]

    v2:
    * Addressed comments from Martin Lau

    Signed-off-by: Stanislav Fomichev
    Acked-by: Martin KaFai Lau
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     

09 Mar, 2019

1 commit

  • Sparse warning below:

    sudo make C=2 CF=-D__CHECK_ENDIAN__ M=net/bpf/
    CHECK net/bpf//test_run.c
    net/bpf//test_run.c:19:77: warning: Using plain integer as NULL pointer
    ./include/linux/bpf-cgroup.h:295:77: warning: Using plain integer as NULL pointer

    Fixes: 8bad74f9840f ("bpf: extend cgroup bpf core to allow multiple cgroup storage types")
    Acked-by: Yonghong Song
    Signed-off-by: Bo YU
    Signed-off-by: Daniel Borkmann

    Bo YU
     

05 Mar, 2019

1 commit

  • Daniel Borkmann says:

    ====================
    pull-request: bpf-next 2019-03-04

    The following pull-request contains BPF updates for your *net-next* tree.

    The main changes are:

    1) Add AF_XDP support to libbpf. Rationale is to facilitate writing
    AF_XDP applications by offering higher-level APIs that hide many
    of the details of the AF_XDP uapi. Sample programs are converted
    over to this new interface as well, from Magnus.

    2) Introduce a new cant_sleep() macro for annotation of functions
    that cannot sleep and use it in BPF_PROG_RUN() to assert that
    BPF programs run under preemption disabled context, from Peter.

    3) Introduce per BPF prog stats in order to monitor the usage
    of BPF; this is controlled by kernel.bpf_stats_enabled sysctl
    knob where monitoring tools can make use of this to efficiently
    determine the average cost of programs, from Alexei.

    4) Split up BPF selftest's test_progs similarly as we already
    did with test_verifier. This allows to further reduce merge
    conflicts in future and to get more structure into our
    quickly growing BPF selftest suite, from Stanislav.

    5) Fix a bug in BTF's dedup algorithm which can cause an infinite
    loop in some circumstances; also various BPF doc fixes and
    improvements, from Andrii.

    6) Various BPF sample cleanups and migration to libbpf in order
    to further isolate the old sample loader code (so we can get
    rid of it at some point), from Jakub.

    7) Add a new BPF helper for BPF cgroup skb progs that allows
    to set ECN CE code point and a Host Bandwidth Manager (HBM)
    sample program for limiting the bandwidth used by v2 cgroups,
    from Lawrence.

    8) Enable write access to skb->queue_mapping from tc BPF egress
    programs in order to let BPF pick TX queue, from Jesper.

    9) Fix a bug in BPF spinlock handling for map-in-map which did
    not propagate spin_lock_off to the meta map, from Yonghong.

    10) Fix a bug in the new per-CPU BPF prog counters to properly
    initialize stats for each CPU, from Eric.

    11) Add various BPF helper prototypes to selftest's bpf_helpers.h,
    from Willem.

    12) Fix various BPF samples bugs in XDP and tracing progs,
    from Toke, Daniel and Yonghong.

    13) Silence preemption splat in test_bpf after BPF_PROG_RUN()
    enforces it now everywhere, from Anders.

    14) Fix a signedness bug in libbpf's btf_dedup_ref_type() to
    get error handling working, from Dan.

    15) Fix bpftool documentation and auto-completion with regards
    to stream_{verdict,parser} attach types, from Alban.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

26 Feb, 2019

1 commit

  • Syzbot found out that running BPF_PROG_TEST_RUN with repeat=0xffffffff
    makes process unkillable. The problem is that when CONFIG_PREEMPT is
    enabled, we never see need_resched() return true. This is due to the
    fact that preempt_enable() (which we do in bpf_test_run_one on each
    iteration) now handles resched if it's needed.

    Let's disable preemption for the whole run, not per test. In this case
    we can properly see whether resched is needed.
    Let's also properly return -EINTR to the userspace in case of a signal
    interrupt.

    This is a follow up for a recently fixed issue in bpf_test_run, see
    commit df1a2cb7c74b ("bpf/test_run: fix unkillable
    BPF_PROG_TEST_RUN").

    Reported-by: syzbot
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     

25 Feb, 2019

1 commit

  • Three conflicts, one of which, for marvell10g.c is non-trivial and
    requires some follow-up from Heiner or someone else.

    The issue is that Heiner converted the marvell10g driver over to
    use the generic c45 code as much as possible.

    However, in 'net' a bug fix appeared which makes sure that a new
    local mask (MDIO_AN_10GBT_CTRL_ADV_NBT_MASK) with value 0x01e0
    is cleared.

    Signed-off-by: David S. Miller

    David S. Miller
     

19 Feb, 2019

1 commit

  • Syzbot found out that running BPF_PROG_TEST_RUN with repeat=0xffffffff
    makes process unkillable. The problem is that when CONFIG_PREEMPT is
    enabled, we never see need_resched() return true. This is due to the
    fact that preempt_enable() (which we do in bpf_test_run_one on each
    iteration) now handles resched if it's needed.

    Let's disable preemption for the whole run, not per test. In this case
    we can properly see whether resched is needed.
    Let's also properly return -EINTR to the userspace in case of a signal
    interrupt.

    See recent discussion:
    http://lore.kernel.org/netdev/CAH3MdRWHr4N8jei8jxDppXjmw-Nw=puNDLbu1dQOFQHxfU2onA@mail.gmail.com

    I'll follow up with the same fix bpf_prog_test_run_flow_dissector in
    bpf-next.

    Reported-by: syzbot
    Signed-off-by: Stanislav Fomichev
    Signed-off-by: Daniel Borkmann

    Stanislav Fomichev
     

29 Jan, 2019

1 commit


11 Dec, 2018

1 commit

  • Daniel Borkmann says:

    ====================
    pull-request: bpf-next 2018-12-11

    The following pull-request contains BPF updates for your *net-next* tree.

    It has three minor merge conflicts, resolutions:

    1) tools/testing/selftests/bpf/test_verifier.c

    Take first chunk with alignment_prevented_execution.

    2) net/core/filter.c

    [...]
    case bpf_ctx_range_ptr(struct __sk_buff, flow_keys):
    case bpf_ctx_range(struct __sk_buff, wire_len):
    return false;
    [...]

    3) include/uapi/linux/bpf.h

    Take the second chunk for the two cases each.

    The main changes are:

    1) Add support for BPF line info via BTF and extend libbpf as well
    as bpftool's program dump to annotate output with BPF C code to
    facilitate debugging and introspection, from Martin.

    2) Add support for BPF_ALU | BPF_ARSH | BPF_{K,X} in interpreter
    and all JIT backends, from Jiong.

    3) Improve BPF test coverage on archs with no efficient unaligned
    access by adding an "any alignment" flag to the BPF program load
    to forcefully disable verifier alignment checks, from David.

    4) Add a new bpf_prog_test_run_xattr() API to libbpf which allows for
    proper use of BPF_PROG_TEST_RUN with data_out, from Lorenz.

    5) Extend tc BPF programs to use a new __sk_buff field called wire_len
    for more accurate accounting of packets going to wire, from Petar.

    6) Improve bpftool to allow dumping the trace pipe from it and add
    several improvements in bash completion and map/prog dump,
    from Quentin.

    7) Optimize arm64 BPF JIT to always emit movn/movk/movk sequence for
    kernel addresses and add a dedicated BPF JIT backend allocator,
    from Ard.

    8) Add a BPF helper function for IR remotes to report mouse movements,
    from Sean.

    9) Various cleanups in BPF prog dump e.g. to make UAPI bpf_prog_info
    member naming consistent with existing conventions, from Yonghong
    and Song.

    10) Misc cleanups and improvements in allowing to pass interface name
    via cmdline for xdp1 BPF example, from Matteo.

    11) Fix a potential segfault in BPF sample loader's kprobes handling,
    from Daniel T.

    12) Fix SPDX license in libbpf's README.rst, from Andrey.
    ====================

    Signed-off-by: David S. Miller

    David S. Miller
     

05 Dec, 2018

1 commit