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