~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/bpf/prog_tests/kfunc_dynptr_param.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 
  3 /*
  4  * Copyright (c) 2022 Facebook
  5  * Copyright (C) 2022 Huawei Technologies Duesseldorf GmbH
  6  *
  7  * Author: Roberto Sassu <roberto.sassu@huawei.com>
  8  */
  9 
 10 #include <test_progs.h>
 11 #include "test_kfunc_dynptr_param.skel.h"
 12 
 13 static struct {
 14         const char *prog_name;
 15         int expected_runtime_err;
 16 } kfunc_dynptr_tests[] = {
 17         {"dynptr_data_null", -EBADMSG},
 18 };
 19 
 20 static bool kfunc_not_supported;
 21 
 22 static int libbpf_print_cb(enum libbpf_print_level level, const char *fmt,
 23                            va_list args)
 24 {
 25         if (strcmp(fmt, "libbpf: extern (func ksym) '%s': not found in kernel or module BTFs\n"))
 26                 return 0;
 27 
 28         if (strcmp(va_arg(args, char *), "bpf_verify_pkcs7_signature"))
 29                 return 0;
 30 
 31         kfunc_not_supported = true;
 32         return 0;
 33 }
 34 
 35 static bool has_pkcs7_kfunc_support(void)
 36 {
 37         struct test_kfunc_dynptr_param *skel;
 38         libbpf_print_fn_t old_print_cb;
 39         int err;
 40 
 41         skel = test_kfunc_dynptr_param__open();
 42         if (!ASSERT_OK_PTR(skel, "test_kfunc_dynptr_param__open"))
 43                 return false;
 44 
 45         kfunc_not_supported = false;
 46 
 47         old_print_cb = libbpf_set_print(libbpf_print_cb);
 48         err = test_kfunc_dynptr_param__load(skel);
 49         libbpf_set_print(old_print_cb);
 50 
 51         if (err < 0 && kfunc_not_supported) {
 52                 fprintf(stderr,
 53                   "%s:SKIP:bpf_verify_pkcs7_signature() kfunc not supported\n",
 54                   __func__);
 55                 test_kfunc_dynptr_param__destroy(skel);
 56                 return false;
 57         }
 58 
 59         test_kfunc_dynptr_param__destroy(skel);
 60 
 61         return true;
 62 }
 63 
 64 static void verify_success(const char *prog_name, int expected_runtime_err)
 65 {
 66         struct test_kfunc_dynptr_param *skel;
 67         struct bpf_program *prog;
 68         struct bpf_link *link;
 69         __u32 next_id;
 70         int err;
 71 
 72         skel = test_kfunc_dynptr_param__open();
 73         if (!ASSERT_OK_PTR(skel, "test_kfunc_dynptr_param__open"))
 74                 return;
 75 
 76         skel->bss->pid = getpid();
 77 
 78         err = test_kfunc_dynptr_param__load(skel);
 79 
 80         if (!ASSERT_OK(err, "test_kfunc_dynptr_param__load"))
 81                 goto cleanup;
 82 
 83         prog = bpf_object__find_program_by_name(skel->obj, prog_name);
 84         if (!ASSERT_OK_PTR(prog, "bpf_object__find_program_by_name"))
 85                 goto cleanup;
 86 
 87         link = bpf_program__attach(prog);
 88         if (!ASSERT_OK_PTR(link, "bpf_program__attach"))
 89                 goto cleanup;
 90 
 91         err = bpf_prog_get_next_id(0, &next_id);
 92 
 93         bpf_link__destroy(link);
 94 
 95         if (!ASSERT_OK(err, "bpf_prog_get_next_id"))
 96                 goto cleanup;
 97 
 98         ASSERT_EQ(skel->bss->err, expected_runtime_err, "err");
 99 
100 cleanup:
101         test_kfunc_dynptr_param__destroy(skel);
102 }
103 
104 void test_kfunc_dynptr_param(void)
105 {
106         int i;
107 
108         if (!has_pkcs7_kfunc_support())
109                 return;
110 
111         for (i = 0; i < ARRAY_SIZE(kfunc_dynptr_tests); i++) {
112                 if (!test__start_subtest(kfunc_dynptr_tests[i].prog_name))
113                         continue;
114 
115                 verify_success(kfunc_dynptr_tests[i].prog_name,
116                         kfunc_dynptr_tests[i].expected_runtime_err);
117         }
118         RUN_TESTS(test_kfunc_dynptr_param);
119 }
120 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php