Skip to content

sched_ext: Deny SCX kfuncs to non-SCX struct_ops programs

Cheng-Yang Chou sched-ext 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 1 replyIn review
  2. v12 patches 2 repliesSuperseded

Changes in v2 from the cover letter

- 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/[email protected]/

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2sched_ext: Deny SCX kfuncs to non-SCX struct_ops programskernel/sched/ext.c kernel/sched/ext_idle.c kernel/sched/ext_idle.h+20 -140 replies
2/2selftests/sched_ext: Add non_scx_kfunc_deny testtools/testing/selftests/sched_ext/Makefile tools/testing/selftests/sched_ext/non_scx_kfunc_deny.bpf.c tools/testing/selftests/sched_ext/non_scx_kfunc_deny.c+92 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v2 yet.

Read the v2 thread

Cover letter [PATCH v2 sched_ext/for-7.1-fixes 0/2] sched_ext: Deny SCX kfuncs to non-SCX struct_ops programs

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/[email protected]/

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/[email protected]/

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
Signature · 1 line
2.48.1