|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
| 2 | +/* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */ |
| 3 | +#include <linux/bpf.h> |
| 4 | +#include <linux/btf.h> |
| 5 | +#include <linux/init.h> |
| 6 | +#include <linux/module.h> |
| 7 | + |
| 8 | +struct bpf_test_no_cfi_ops { |
| 9 | + void (*fn_1)(void); |
| 10 | + void (*fn_2)(void); |
| 11 | +}; |
| 12 | + |
| 13 | +static int dummy_init(struct btf *btf) |
| 14 | +{ |
| 15 | + return 0; |
| 16 | +} |
| 17 | + |
| 18 | +static int dummy_init_member(const struct btf_type *t, |
| 19 | + const struct btf_member *member, |
| 20 | + void *kdata, const void *udata) |
| 21 | +{ |
| 22 | + return 0; |
| 23 | +} |
| 24 | + |
| 25 | +static int dummy_reg(void *kdata) |
| 26 | +{ |
| 27 | + return 0; |
| 28 | +} |
| 29 | + |
| 30 | +static void dummy_unreg(void *kdata) |
| 31 | +{ |
| 32 | +} |
| 33 | + |
| 34 | +static const struct bpf_verifier_ops dummy_verifier_ops; |
| 35 | + |
| 36 | +static void bpf_test_no_cfi_ops__fn_1(void) |
| 37 | +{ |
| 38 | +} |
| 39 | + |
| 40 | +static void bpf_test_no_cfi_ops__fn_2(void) |
| 41 | +{ |
| 42 | +} |
| 43 | + |
| 44 | +static struct bpf_test_no_cfi_ops __test_no_cif_ops = { |
| 45 | + .fn_1 = bpf_test_no_cfi_ops__fn_1, |
| 46 | + .fn_2 = bpf_test_no_cfi_ops__fn_2, |
| 47 | +}; |
| 48 | + |
| 49 | +static struct bpf_struct_ops test_no_cif_ops = { |
| 50 | + .verifier_ops = &dummy_verifier_ops, |
| 51 | + .init = dummy_init, |
| 52 | + .init_member = dummy_init_member, |
| 53 | + .reg = dummy_reg, |
| 54 | + .unreg = dummy_unreg, |
| 55 | + .name = "bpf_test_no_cfi_ops", |
| 56 | + .owner = THIS_MODULE, |
| 57 | +}; |
| 58 | + |
| 59 | +static int bpf_test_no_cfi_init(void) |
| 60 | +{ |
| 61 | + int ret; |
| 62 | + |
| 63 | + ret = register_bpf_struct_ops(&test_no_cif_ops, |
| 64 | + bpf_test_no_cfi_ops); |
| 65 | + if (!ret) |
| 66 | + return -EINVAL; |
| 67 | + |
| 68 | + test_no_cif_ops.cfi_stubs = &__test_no_cif_ops; |
| 69 | + ret = register_bpf_struct_ops(&test_no_cif_ops, |
| 70 | + bpf_test_no_cfi_ops); |
| 71 | + return ret; |
| 72 | +} |
| 73 | + |
| 74 | +static void bpf_test_no_cfi_exit(void) |
| 75 | +{ |
| 76 | +} |
| 77 | + |
| 78 | +module_init(bpf_test_no_cfi_init); |
| 79 | +module_exit(bpf_test_no_cfi_exit); |
| 80 | + |
| 81 | +MODULE_AUTHOR("Kuifeng Lee"); |
| 82 | +MODULE_DESCRIPTION("BPF no cfi_stubs test module"); |
| 83 | +MODULE_LICENSE("Dual BSD/GPL"); |
| 84 | + |
0 commit comments