Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2025 Microsoft */
3#include <test_progs.h>
4#include "kfunc_call_test.skel.h"
5#include "kfunc_call_test.lskel.h"
6#include "test_kernel_flag.skel.h"
7
8void test_kernel_flag(void)
9{
10 struct test_kernel_flag *lsm_skel;
11 struct kfunc_call_test *skel = NULL;
12 struct kfunc_call_test_lskel *lskel = NULL;
13 int ret;
14
15 lsm_skel = test_kernel_flag__open_and_load();
16 if (!ASSERT_OK_PTR(lsm_skel, "lsm_skel"))
17 return;
18
19 lsm_skel->bss->monitored_tid = sys_gettid();
20
21 ret = test_kernel_flag__attach(lsm_skel);
22 if (!ASSERT_OK(ret, "test_kernel_flag__attach"))
23 goto close_prog;
24
25 /* Test with skel. This should pass the gatekeeper */
26 skel = kfunc_call_test__open_and_load();
27 if (!ASSERT_OK_PTR(skel, "skel"))
28 goto close_prog;
29
30 /* Test with lskel. This should fail due to blocking kernel-based bpf() invocations */
31 lskel = kfunc_call_test_lskel__open_and_load();
32 if (!ASSERT_ERR_PTR(lskel, "lskel"))
33 goto close_prog;
34
35close_prog:
36 if (skel)
37 kfunc_call_test__destroy(skel);
38 if (lskel)
39 kfunc_call_test_lskel__destroy(lskel);
40
41 lsm_skel->bss->monitored_tid = 0;
42 test_kernel_flag__destroy(lsm_skel);
43}