1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <test_progs.h>
4 #include <linux/nbd.h>
5 #include "bpf_util.h"
6
test_raw_tp_writable_reject_nbd_invalid(void)7 void test_raw_tp_writable_reject_nbd_invalid(void)
8 {
9 __u32 duration = 0;
10 char error[4096];
11 int bpf_fd = -1, tp_fd = -1;
12
13 const struct bpf_insn program[] = {
14 /* r6 is our tp buffer */
15 BPF_LDX_MEM(BPF_DW, BPF_REG_6, BPF_REG_1, 0),
16 /* one byte beyond the end of the nbd_request struct */
17 BPF_LDX_MEM(BPF_B, BPF_REG_0, BPF_REG_6,
18 sizeof(struct nbd_request)),
19 BPF_EXIT_INSN(),
20 };
21
22 LIBBPF_OPTS(bpf_prog_load_opts, opts,
23 .log_level = 2,
24 .log_buf = error,
25 .log_size = sizeof(error),
26 );
27
28 bpf_fd = bpf_prog_load(BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, NULL, "GPL v2",
29 program, ARRAY_SIZE(program),
30 &opts);
31 if (CHECK(bpf_fd < 0, "bpf_raw_tracepoint_writable load",
32 "failed: %d errno %d\n", bpf_fd, errno))
33 return;
34
35 tp_fd = bpf_raw_tracepoint_open("nbd_send_request", bpf_fd);
36 if (CHECK(tp_fd >= 0, "bpf_raw_tracepoint_writable open",
37 "erroneously succeeded\n"))
38 goto out_bpffd;
39
40 close(tp_fd);
41 out_bpffd:
42 close(bpf_fd);
43 }
44