1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Verify that context-sensitive SCX kfuncs (even "unlocked" ones) are 4 * restricted to only SCX struct_ops programs. Non-SCX struct_ops programs, 5 * such as TCP congestion control programs, should be rejected by the BPF 6 * verifier when attempting to call these kfuncs. 7 * 8 * Copyright (C) 2026 Ching-Chun (Jim) Huang <jserv@ccns.ncku.edu.tw> 9 * Copyright (C) 2026 Cheng-Yang Chou <yphbchou0911@gmail.com> 10 */ 11 12 #include <bpf/bpf.h> 13 #include <scx/common.h> 14 #include <unistd.h> 15 #include <errno.h> 16 #include <stdio.h> 17 #include "non_scx_kfunc_deny.bpf.skel.h" 18 #include "scx_test.h" 19 run(void * ctx)20static enum scx_test_status run(void *ctx) 21 { 22 struct non_scx_kfunc_deny *skel; 23 int err; 24 25 skel = non_scx_kfunc_deny__open(); 26 if (!skel) { 27 SCX_ERR("Failed to open skel"); 28 return SCX_TEST_FAIL; 29 } 30 31 err = non_scx_kfunc_deny__load(skel); 32 non_scx_kfunc_deny__destroy(skel); 33 34 if (err == 0) { 35 SCX_ERR("non-SCX BPF program loaded when it should have been rejected"); 36 return SCX_TEST_FAIL; 37 } 38 39 return SCX_TEST_PASS; 40 } 41 42 struct scx_test non_scx_kfunc_deny = { 43 .name = "non_scx_kfunc_deny", 44 .description = "Verify that non-SCX struct_ops programs cannot call SCX kfuncs", 45 .run = run, 46 }; 47 REGISTER_SCX_TEST(&non_scx_kfunc_deny) 48