1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2024 Meta Platforms, Inc. and affiliates. */
3 #include <test_progs.h>
4 #include <testing_helpers.h>
5 
load_bpf_test_no_cfi(void)6 static void load_bpf_test_no_cfi(void)
7 {
8 	int fd;
9 	int err;
10 
11 	fd = open("bpf_test_no_cfi.ko", O_RDONLY);
12 	if (!ASSERT_GE(fd, 0, "open"))
13 		return;
14 
15 	/* The module will try to register a struct_ops type without
16 	 * cfi_stubs and with cfi_stubs.
17 	 *
18 	 * The one without cfi_stub should fail. The module will be loaded
19 	 * successfully only if the result of the registration is as
20 	 * expected, or it fails.
21 	 */
22 	err = finit_module(fd, "", 0);
23 	close(fd);
24 	if (!ASSERT_OK(err, "finit_module"))
25 		return;
26 
27 	err = delete_module("bpf_test_no_cfi", 0);
28 	ASSERT_OK(err, "delete_module");
29 }
30 
test_struct_ops_no_cfi(void)31 void test_struct_ops_no_cfi(void)
32 {
33 	if (test__start_subtest("load_bpf_test_no_cfi"))
34 		load_bpf_test_no_cfi();
35 }
36