1// SPDX-License-Identifier: GPL-2.0
2
3#include <test_progs.h>
4#include <linux/nbd.h>
5
6void 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	struct bpf_load_program_attr load_attr = {
22		.prog_type = BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
23		.license = "GPL v2",
24		.insns = program,
25		.insns_cnt = sizeof(program) / sizeof(struct bpf_insn),
26		.log_level = 2,
27	};
28
29	bpf_fd = bpf_load_program_xattr(&load_attr, error, sizeof(error));
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);
40out_bpffd:
41	close(bpf_fd);
42}
43