1 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
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.
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>
13 /* test stubs for BPF_MAP_TYPE_UNSPEC and for BPF_PROG_TYPE_UNSPEC
14 * to be used by user space verifier testsuite
21 static const struct bpf_func_proto
*test_func_proto(enum bpf_func_id 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
;
35 static const struct bpf_context_access
{
37 enum bpf_access_type type
;
38 } test_ctx_access
[] = {
39 [offsetof(struct bpf_context
, arg1
)] = {
40 FIELD_SIZEOF(struct bpf_context
, arg1
),
43 [offsetof(struct bpf_context
, arg2
)] = {
44 FIELD_SIZEOF(struct bpf_context
, arg2
),
49 static bool test_is_valid_access(int off
, int size
, enum bpf_access_type type
)
51 const struct bpf_context_access
*access
;
53 if (off
< 0 || off
>= ARRAY_SIZE(test_ctx_access
))
56 access
= &test_ctx_access
[off
];
57 if (access
->size
== size
&& (access
->type
& type
))
63 static struct bpf_verifier_ops test_ops
= {
64 .get_func_proto
= test_func_proto
,
65 .is_valid_access
= test_is_valid_access
,
68 static struct bpf_prog_type_list tl_prog
= {
70 .type
= BPF_PROG_TYPE_UNSPEC
,
73 static int __init
register_test_ops(void)
75 bpf_register_prog_type(&tl_prog
);
78 late_initcall(register_test_ops
);