Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests/sched_ext: Add non_scx_kfunc_deny test

Verify that the BPF verifier rejects a non-SCX struct_ops program
(tcp_congestion_ops) that attempts to call an SCX kfunc (scx_bpf_kick_cpu).
The test expects the load to fail with -EACCES from scx_kfunc_context_filter.

Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>

authored by

Cheng-Yang Chou and committed by
Tejun Heo
5897ca15 2d2b026c

+92
+1
tools/testing/selftests/sched_ext/Makefile
··· 175 175 maximal \ 176 176 maybe_null \ 177 177 minimal \ 178 + non_scx_kfunc_deny \ 178 179 numa \ 179 180 allowed_cpus \ 180 181 peek_dsq \
+44
tools/testing/selftests/sched_ext/non_scx_kfunc_deny.bpf.c
··· 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 <vmlinux.h> 13 + #include <bpf/bpf_helpers.h> 14 + #include <bpf/bpf_tracing.h> 15 + 16 + /* SCX kfunc from scx_kfunc_ids_any set */ 17 + void scx_bpf_kick_cpu(s32 cpu, u64 flags) __ksym; 18 + 19 + SEC("struct_ops/ssthresh") 20 + __u32 BPF_PROG(tcp_ca_ssthresh, struct sock *sk) 21 + { 22 + /* 23 + * This call should be rejected by the verifier because this is a 24 + * TCP congestion control program (non-SCX struct_ops). 25 + */ 26 + scx_bpf_kick_cpu(0, 0); 27 + return 2; 28 + } 29 + 30 + SEC("struct_ops/cong_avoid") 31 + void BPF_PROG(tcp_ca_cong_avoid, struct sock *sk, __u32 ack, __u32 acked) {} 32 + 33 + SEC("struct_ops/undo_cwnd") 34 + __u32 BPF_PROG(tcp_ca_undo_cwnd, struct sock *sk) { return 2; } 35 + 36 + SEC(".struct_ops") 37 + struct tcp_congestion_ops tcp_non_scx_ca = { 38 + .ssthresh = (void *)tcp_ca_ssthresh, 39 + .cong_avoid = (void *)tcp_ca_cong_avoid, 40 + .undo_cwnd = (void *)tcp_ca_undo_cwnd, 41 + .name = "tcp_kfunc_deny", 42 + }; 43 + 44 + char _license[] SEC("license") = "GPL";
+47
tools/testing/selftests/sched_ext/non_scx_kfunc_deny.c
··· 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 + 20 + static 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)