From: Cheng-Yang Chou <yphbchou0911@gmail.com>
To: sched-ext@lists.linux.dev, Tejun Heo <tj@kernel.org>,
David Vernet <void@manifault.com>,
Andrea Righi <arighi@nvidia.com>,
Changwoo Min <changwoo@igalia.com>
Cc: Ching-Chun Huang <jserv@ccns.ncku.edu.tw>,
Chia-Ping Tsai <chia7712@gmail.com>,
yphbchou0911@gmail.com
Subject: [PATCH v2 sched_ext/for-7.1-fixes 0/2] sched_ext: Deny SCX kfuncs to non-SCX struct_ops programs
Date: Mon, 20 Apr 2026 17:28:46 +0800 [thread overview]
Message-ID: <20260420092913.440989-1-yphbchou0911@gmail.com> (raw)
As discussed in [1], scx_kfunc_context_filter() currently allows non-SCX
struct_ops programs (e.g. tcp_congestion_ops) to call SCX kfuncs that are
only meaningful inside an SCX scheduler. This is wrong for two reasons.
First, it is semantically incorrect: a TCP congestion control program
has no business calling SCX kfuncs such as scx_bpf_kick_cpu().
Second, with CONFIG_EXT_SUB_SCHED=y, kfuncs like scx_bpf_kick_cpu()
call scx_prog_sched(aux), which retrieves the struct_ops kdata via
bpf_prog_get_assoc_struct_ops() and casts it to struct sched_ext_ops *
before reading ops->priv. For a non-SCX struct_ops program the kdata
is far smaller than sched_ext_ops, turning the read into an
out-of-bounds access (confirmed with KASAN).
Patch 1 extends scx_kfunc_context_filter() to also cover
scx_kfunc_set_any and scx_kfunc_set_idle, and denies all SCX kfuncs to
any struct_ops program that is not the SCX struct_ops.
Patch 2 adds a selftest that loads a TCP congestion control program
calling scx_bpf_kick_cpu() and verifies the BPF verifier rejects it.
Note: the reload_loop bug [2] I posted before isn't related to this
patchset.
[1]: https://lore.kernel.org/r/f2ab3yg5niso6hxqe7sd4jmv5xzdizk3khcspm5bylfbn3mj44@tpyiezvs4cod/
[2]: https://lore.kernel.org/r/20260419174413.Gf28b@cchengyang.duckdns.org/
Changes in v2:
- Extend filter to also cover scx_kfunc_set_idle: add in_idle check and
set .filter on scx_kfunc_set_idle itself (Tejun Heo)
- Drop "context-sensitive" terminology; use "SCX kfuncs" throughout
(Tejun Heo)
- Break overlong early-exit line in scx_kfunc_context_filter()
(Tejun Heo)
- Link to v1:
https://lore.kernel.org/r/20260416064715.1008437-1-yphbchou0911@gmail.com/
Thanks,
Cheng-Yang
---
Cheng-Yang Chou (2):
sched_ext: Deny SCX kfuncs to non-SCX struct_ops programs
selftests/sched_ext: Add non_scx_kfunc_deny test
kernel/sched/ext.c | 32 +++++++------
kernel/sched/ext_idle.c | 1 +
kernel/sched/ext_idle.h | 1 +
tools/testing/selftests/sched_ext/Makefile | 1 +
.../sched_ext/non_scx_kfunc_deny.bpf.c | 44 +++++++++++++++++
.../selftests/sched_ext/non_scx_kfunc_deny.c | 47 +++++++++++++++++++
6 files changed, 112 insertions(+), 14 deletions(-)
create mode 100644 tools/testing/selftests/sched_ext/non_scx_kfunc_deny.bpf.c
create mode 100644 tools/testing/selftests/sched_ext/non_scx_kfunc_deny.c
--
2.48.1
next reply other threads:[~2026-04-20 9:29 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-20 9:28 Cheng-Yang Chou [this message]
2026-04-20 9:28 ` [PATCH v2 1/2] sched_ext: Deny SCX kfuncs to non-SCX struct_ops programs Cheng-Yang Chou
2026-04-20 9:28 ` [PATCH v2 2/2] selftests/sched_ext: Add non_scx_kfunc_deny test Cheng-Yang Chou
2026-04-20 18:02 ` [PATCH v2 sched_ext/for-7.1-fixes 0/2] sched_ext: Deny SCX kfuncs to non-SCX struct_ops programs Tejun Heo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260420092913.440989-1-yphbchou0911@gmail.com \
--to=yphbchou0911@gmail.com \
--cc=arighi@nvidia.com \
--cc=changwoo@igalia.com \
--cc=chia7712@gmail.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=sched-ext@lists.linux.dev \
--cc=tj@kernel.org \
--cc=void@manifault.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox