Commit Graph

11 Commits

Author SHA1 Message Date
Viktor Malik f37aad2a44
libbpf: feature-detect arg:ctx tag support in kernel
JIRA: https://issues.redhat.com/browse/RHEL-23644

commit 01b55f4f0cd6ad1a16eca6c43a3190005892ef91
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Jan 17 19:31:39 2024 -0800

    libbpf: feature-detect arg:ctx tag support in kernel
    
    Add feature detector of kernel-side arg:ctx (__arg_ctx) tag support. If
    this is detected, libbpf will avoid doing any __arg_ctx-related BTF
    rewriting and checks in favor of letting kernel handle this completely.
    
    test_global_funcs/ctx_arg_rewrite subtest is adjusted to do the same
    feature detection (albeit in much simpler, though round-about and
    inefficient, way), and skip the tests. This is done to still be able to
    execute this test on older kernels (like in libbpf CI).
    
    Note, BPF token series ([0]) does a major refactor and code moving of
    libbpf-internal feature detection "framework", so to avoid unnecessary
    conflicts we keep newly added feature detection stand-alone with ad-hoc
    result caching. Once things settle, there will be a small follow up to
    re-integrate everything back and move code into its final place in
    newly-added (by BPF token series) features.c file.
    
      [0] https://patchwork.kernel.org/project/netdevbpf/list/?series=814209&state=*
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20240118033143.3384355-2-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-06-25 11:07:41 +02:00
Viktor Malik 0a21e24b1e
selftests/bpf: add __arg_ctx BTF rewrite test
JIRA: https://issues.redhat.com/browse/RHEL-23644

commit 95226f5a36695fd5740e130016d9ed697cfb2bad
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Jan 3 17:38:47 2024 -0800

    selftests/bpf: add __arg_ctx BTF rewrite test
    
    Add a test validating that libbpf uploads BTF and func_info with
    rewritten type information for arguments of global subprogs that are
    marked with __arg_ctx tag.
    
    Suggested-by: Eduard Zingerman <eddyz87@gmail.com>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/r/20240104013847.3875810-10-andrii@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2024-06-25 11:07:38 +02:00
Viktor Malik bc75d83a5a selftests/bpf: Add global subprog context passing tests
Bugzilla: https://bugzilla.redhat.com/2178930

commit e2b5cfc978f871996d1f8667515c0e06b33e620e
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Feb 15 20:59:54 2023 -0800

    selftests/bpf: Add global subprog context passing tests
    
    Add tests validating that it's possible to pass context arguments into
    global subprogs for various types of programs, including a particularly
    tricky KPROBE programs (which cover kprobes, uprobes, USDTs, a vast and
    important class of programs).
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Stanislav Fomichev <sdf@google.com>
    Link: https://lore.kernel.org/bpf/20230216045954.3002473-4-andrii@kernel.org

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-06-13 22:45:41 +02:00
Viktor Malik 14e536ad8e selftests/bpf: Convert test_global_funcs test to test_loader framework
Bugzilla: https://bugzilla.redhat.com/2178930

commit 95ebb376176c52382293e05e63f142114a5e40ef
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Feb 15 20:59:53 2023 -0800

    selftests/bpf: Convert test_global_funcs test to test_loader framework
    
    Convert 17 test_global_funcs subtests into test_loader framework for
    easier maintenance and more declarative way to define expected
    failures/successes.
    
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Acked-by: Stanislav Fomichev <sdf@google.com>
    Link: https://lore.kernel.org/bpf/20230216045954.3002473-3-andrii@kernel.org

Signed-off-by: Viktor Malik <vmalik@redhat.com>
2023-06-13 22:45:41 +02:00
Artem Savkov fbd9cfcd5b selftests/bpf: Store BPF object files with .bpf.o extension
Bugzilla: https://bugzilla.redhat.com/2166911

commit afef88e65554c3e8691513b8350d6445e292560e
Author: Daniel Müller <deso@posteo.net>
Date:   Thu Sep 1 22:22:53 2022 +0000

    selftests/bpf: Store BPF object files with .bpf.o extension
    
    BPF object files are, in a way, the final artifact produced as part of
    the ahead-of-time compilation process. That makes them somewhat special
    compared to "regular" object files, which are a intermediate build
    artifacts that can typically be removed safely. As such, it can make
    sense to name them differently to make it easier to spot this difference
    at a glance.
    
    Among others, libbpf-bootstrap [0] has established the extension .bpf.o
    for BPF object files. It seems reasonable to follow this example and
    establish the same denomination for selftest build artifacts. To that
    end, this change adjusts the corresponding part of the build system and
    the test programs loading BPF object files to work with .bpf.o files.
    
      [0] https://github.com/libbpf/libbpf-bootstrap
    
    Suggested-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Daniel Müller <deso@posteo.net>
    Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
    Link: https://lore.kernel.org/bpf/20220901222253.1199242-1-deso@posteo.net

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2023-03-06 14:54:06 +01:00
Yauheni Kaliuta febd1199f1 selftests/bpf: Test passing rdonly mem to global func
Bugzilla: https://bugzilla.redhat.com/2120968

commit 7cb29b1c99f4244c3f1de04e88eb9aed842a0cba
Author: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Date:   Sat Mar 19 13:38:26 2022 +0530

    selftests/bpf: Test passing rdonly mem to global func
    
    Add two test cases, one pass read only map value pointer to global
    func, which should be rejected. The same code checks it for kfunc, so
    that is covered as well. Second one tries to use the missing check for
    PTR_TO_MEM's MEM_RDONLY flag and tries to write to a read only memory
    pointer. Without prior patches, both of these tests fail.
    
    Reviewed-by: Hao Luo <haoluo@google.com>
    Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
    Link: https://lore.kernel.org/r/20220319080827.73251-5-memxor@gmail.com
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-11-28 16:48:57 +02:00
Artem Savkov f23fbe053c selftests/bpf: Remove all the uses of deprecated bpf_prog_load_xattr()
Bugzilla: https://bugzilla.redhat.com/2069046

Upstream Status: git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

commit 186d1a86003ddcf0ec9e85e17ece868663106639
Author: Andrii Nakryiko <andrii@kernel.org>
Date:   Wed Dec 1 15:28:21 2021 -0800

    selftests/bpf: Remove all the uses of deprecated bpf_prog_load_xattr()

    Migrate all the selftests that were still using bpf_prog_load_xattr().
    Few are converted to skeleton, others will use bpf_object__open_file()
    API.

    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>
    Link: https://lore.kernel.org/bpf/20211201232824.3166325-7-andrii@kernel.org

Signed-off-by: Artem Savkov <asavkov@redhat.com>
2022-08-24 12:53:44 +02:00
Dmitrii Banshchikov 8b08807d03 selftests/bpf: Add unit tests for pointers in global functions
test_global_func9  - check valid pointer's scenarios
test_global_func10 - check that a smaller type cannot be passed as a
                     larger one
test_global_func11 - check that CTX pointer cannot be passed
test_global_func12 - check access to a null pointer
test_global_func13 - check access to an arbitrary pointer value
test_global_func14 - check that an opaque pointer cannot be passed
test_global_func15 - check that a variable has an unknown value after
		     it was passed to a global function by pointer
test_global_func16 - check access to uninitialized stack memory

test_global_func_args - check read and write operations through a pointer

Signed-off-by: Dmitrii Banshchikov <me@ubique.spb.ru>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210212205642.620788-5-me@ubique.spb.ru
2021-02-12 17:37:23 -08:00
Dmitrii Banshchikov f782e2c300 bpf: Relax return code check for subprograms
Currently verifier enforces return code checks for subprograms in the
same manner as it does for program entry points. This prevents returning
arbitrary scalar values from subprograms. Scalar type of returned values
is checked by btf_prepare_func_args() and hence it should be safe to
allow only scalars for now. Relax return code checks for subprograms and
allow any correct scalar values.

Fixes: 51c39bb1d5 (bpf: Introduce function-by-function verification)
Signed-off-by: Dmitrii Banshchikov <me@ubique.spb.ru>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20201113171756.90594-1-me@ubique.spb.ru
2020-11-14 08:17:27 -08:00
Yauheni Kaliuta c210773d6c bpf: selftests: global_funcs: Check err_str before strstr
The error path in libbpf.c:load_program() has calls to pr_warn()
which ends up for global_funcs tests to
test_global_funcs.c:libbpf_debug_print().

For the tests with no struct test_def::err_str initialized with a
string, it causes call of strstr() with NULL as the second argument
and it segfaults.

Fix it by calling strstr() only for non-NULL err_str.

Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200820115843.39454-1-yauheni.kaliuta@redhat.com
2020-08-20 14:31:14 -07:00
Alexei Starovoitov 360301a6c2 selftests/bpf: Add unit tests for global functions
test_global_func[12] - check 512 stack limit.
test_global_func[34] - check 8 frame call chain limit.
test_global_func5    - check that non-ctx pointer cannot be passed into
                       a function that expects context.
test_global_func6    - check that ctx pointer is unmodified.
test_global_func7    - check that global function returns scalar.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20200110064124.1760511-7-ast@kernel.org
2020-01-10 17:20:07 +01:00