diff options
-rw-r--r-- | kernel/bpf/Makefile | 3 | ||||
-rw-r--r-- | kernel/bpf/test_stub.c | 78 | ||||
-rw-r--r-- | samples/bpf/test_verifier.c | 5 |
3 files changed, 3 insertions, 83 deletions
diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile index a5ae60f0b0a2..e6983be12bd3 100644 --- a/kernel/bpf/Makefile +++ b/kernel/bpf/Makefile | |||
@@ -1,5 +1,2 @@ | |||
1 | obj-y := core.o | 1 | obj-y := core.o |
2 | obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o hashtab.o arraymap.o helpers.o | 2 | obj-$(CONFIG_BPF_SYSCALL) += syscall.o verifier.o hashtab.o arraymap.o helpers.o |
3 | ifdef CONFIG_TEST_BPF | ||
4 | obj-$(CONFIG_BPF_SYSCALL) += test_stub.o | ||
5 | endif | ||
diff --git a/kernel/bpf/test_stub.c b/kernel/bpf/test_stub.c deleted file mode 100644 index 0ceae1e6e8b5..000000000000 --- a/kernel/bpf/test_stub.c +++ /dev/null | |||
@@ -1,78 +0,0 @@ | |||
1 | /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com | ||
2 | * | ||
3 | * This program is free software; you can redistribute it and/or | ||
4 | * modify it under the terms of version 2 of the GNU General Public | ||
5 | * License as published by the Free Software Foundation. | ||
6 | */ | ||
7 | #include <linux/kernel.h> | ||
8 | #include <linux/types.h> | ||
9 | #include <linux/slab.h> | ||
10 | #include <linux/err.h> | ||
11 | #include <linux/bpf.h> | ||
12 | |||
13 | /* test stubs for BPF_MAP_TYPE_UNSPEC and for BPF_PROG_TYPE_UNSPEC | ||
14 | * to be used by user space verifier testsuite | ||
15 | */ | ||
16 | struct bpf_context { | ||
17 | u64 arg1; | ||
18 | u64 arg2; | ||
19 | }; | ||
20 | |||
21 | static const struct bpf_func_proto *test_func_proto(enum bpf_func_id func_id) | ||
22 | { | ||
23 | switch (func_id) { | ||
24 | case BPF_FUNC_map_lookup_elem: | ||
25 | return &bpf_map_lookup_elem_proto; | ||
26 | case BPF_FUNC_map_update_elem: | ||
27 | return &bpf_map_update_elem_proto; | ||
28 | case BPF_FUNC_map_delete_elem: | ||
29 | return &bpf_map_delete_elem_proto; | ||
30 | default: | ||
31 | return NULL; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | static const struct bpf_context_access { | ||
36 | int size; | ||
37 | enum bpf_access_type type; | ||
38 | } test_ctx_access[] = { | ||
39 | [offsetof(struct bpf_context, arg1)] = { | ||
40 | FIELD_SIZEOF(struct bpf_context, arg1), | ||
41 | BPF_READ | ||
42 | }, | ||
43 | [offsetof(struct bpf_context, arg2)] = { | ||
44 | FIELD_SIZEOF(struct bpf_context, arg2), | ||
45 | BPF_READ | ||
46 | }, | ||
47 | }; | ||
48 | |||
49 | static bool test_is_valid_access(int off, int size, enum bpf_access_type type) | ||
50 | { | ||
51 | const struct bpf_context_access *access; | ||
52 | |||
53 | if (off < 0 || off >= ARRAY_SIZE(test_ctx_access)) | ||
54 | return false; | ||
55 | |||
56 | access = &test_ctx_access[off]; | ||
57 | if (access->size == size && (access->type & type)) | ||
58 | return true; | ||
59 | |||
60 | return false; | ||
61 | } | ||
62 | |||
63 | static struct bpf_verifier_ops test_ops = { | ||
64 | .get_func_proto = test_func_proto, | ||
65 | .is_valid_access = test_is_valid_access, | ||
66 | }; | ||
67 | |||
68 | static struct bpf_prog_type_list tl_prog = { | ||
69 | .ops = &test_ops, | ||
70 | .type = BPF_PROG_TYPE_UNSPEC, | ||
71 | }; | ||
72 | |||
73 | static int __init register_test_ops(void) | ||
74 | { | ||
75 | bpf_register_prog_type(&tl_prog); | ||
76 | return 0; | ||
77 | } | ||
78 | late_initcall(register_test_ops); | ||
diff --git a/samples/bpf/test_verifier.c b/samples/bpf/test_verifier.c index b96175e90363..7b56b59fad8e 100644 --- a/samples/bpf/test_verifier.c +++ b/samples/bpf/test_verifier.c | |||
@@ -288,7 +288,8 @@ static struct bpf_test tests[] = { | |||
288 | BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -8), | 288 | BPF_LDX_MEM(BPF_DW, BPF_REG_2, BPF_REG_10, -8), |
289 | 289 | ||
290 | /* should be able to access R0 = *(R2 + 8) */ | 290 | /* should be able to access R0 = *(R2 + 8) */ |
291 | BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, 8), | 291 | /* BPF_LDX_MEM(BPF_DW, BPF_REG_0, BPF_REG_2, 8), */ |
292 | BPF_MOV64_REG(BPF_REG_0, BPF_REG_2), | ||
292 | BPF_EXIT_INSN(), | 293 | BPF_EXIT_INSN(), |
293 | }, | 294 | }, |
294 | .result = ACCEPT, | 295 | .result = ACCEPT, |
@@ -687,7 +688,7 @@ static int test(void) | |||
687 | } | 688 | } |
688 | printf("#%d %s ", i, tests[i].descr); | 689 | printf("#%d %s ", i, tests[i].descr); |
689 | 690 | ||
690 | prog_fd = bpf_prog_load(BPF_PROG_TYPE_UNSPEC, prog, | 691 | prog_fd = bpf_prog_load(BPF_PROG_TYPE_SOCKET_FILTER, prog, |
691 | prog_len * sizeof(struct bpf_insn), | 692 | prog_len * sizeof(struct bpf_insn), |
692 | "GPL"); | 693 | "GPL"); |
693 | 694 | ||