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

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

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ 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 #include <test_progs.h>
  3 
  4 /* TODO: corrupts other tests uses connect() */
  5 void serial_test_probe_user(void)
  6 {
  7         static const char *const prog_names[] = {
  8                 "handle_sys_connect",
  9 #if defined(__s390x__)
 10                 "handle_sys_socketcall",
 11 #endif
 12         };
 13         enum { prog_count = ARRAY_SIZE(prog_names) };
 14         const char *obj_file = "./test_probe_user.bpf.o";
 15         DECLARE_LIBBPF_OPTS(bpf_object_open_opts, opts, );
 16         int err, results_map_fd, sock_fd, duration = 0;
 17         struct sockaddr curr, orig, tmp;
 18         struct sockaddr_in *in = (struct sockaddr_in *)&curr;
 19         struct bpf_link *kprobe_links[prog_count] = {};
 20         struct bpf_program *kprobe_progs[prog_count];
 21         struct bpf_object *obj;
 22         static const int zero = 0;
 23         size_t i;
 24 
 25         obj = bpf_object__open_file(obj_file, &opts);
 26         if (!ASSERT_OK_PTR(obj, "obj_open_file"))
 27                 return;
 28 
 29         for (i = 0; i < prog_count; i++) {
 30                 kprobe_progs[i] =
 31                         bpf_object__find_program_by_name(obj, prog_names[i]);
 32                 if (CHECK(!kprobe_progs[i], "find_probe",
 33                           "prog '%s' not found\n", prog_names[i]))
 34                         goto cleanup;
 35         }
 36 
 37         err = bpf_object__load(obj);
 38         if (CHECK(err, "obj_load", "err %d\n", err))
 39                 goto cleanup;
 40 
 41         results_map_fd = bpf_find_map(__func__, obj, "test_pro.bss");
 42         if (CHECK(results_map_fd < 0, "find_bss_map",
 43                   "err %d\n", results_map_fd))
 44                 goto cleanup;
 45 
 46         for (i = 0; i < prog_count; i++) {
 47                 kprobe_links[i] = bpf_program__attach(kprobe_progs[i]);
 48                 if (!ASSERT_OK_PTR(kprobe_links[i], "attach_kprobe"))
 49                         goto cleanup;
 50         }
 51 
 52         memset(&curr, 0, sizeof(curr));
 53         in->sin_family = AF_INET;
 54         in->sin_port = htons(5555);
 55         in->sin_addr.s_addr = inet_addr("255.255.255.255");
 56         memcpy(&orig, &curr, sizeof(curr));
 57 
 58         sock_fd = socket(AF_INET, SOCK_STREAM, 0);
 59         if (CHECK(sock_fd < 0, "create_sock_fd", "err %d\n", sock_fd))
 60                 goto cleanup;
 61 
 62         connect(sock_fd, &curr, sizeof(curr));
 63         close(sock_fd);
 64 
 65         err = bpf_map_lookup_elem(results_map_fd, &zero, &tmp);
 66         if (CHECK(err, "get_kprobe_res",
 67                   "failed to get kprobe res: %d\n", err))
 68                 goto cleanup;
 69 
 70         in = (struct sockaddr_in *)&tmp;
 71         if (CHECK(memcmp(&tmp, &orig, sizeof(orig)), "check_kprobe_res",
 72                   "wrong kprobe res from probe read: %s:%u\n",
 73                   inet_ntoa(in->sin_addr), ntohs(in->sin_port)))
 74                 goto cleanup;
 75 
 76         memset(&tmp, 0xab, sizeof(tmp));
 77 
 78         in = (struct sockaddr_in *)&curr;
 79         if (CHECK(memcmp(&curr, &tmp, sizeof(tmp)), "check_kprobe_res",
 80                   "wrong kprobe res from probe write: %s:%u\n",
 81                   inet_ntoa(in->sin_addr), ntohs(in->sin_port)))
 82                 goto cleanup;
 83 cleanup:
 84         for (i = 0; i < prog_count; i++)
 85                 bpf_link__destroy(kprobe_links[i]);
 86         bpf_object__close(obj);
 87 }
 88 

~ [ 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