From: Tao Cui scx_bpf_cid_node() is documented to return NUMA_NO_NODE when @cid is invalid or there is no scheduler. Its implementation goes through scx_cid_to_cpu(), whose cid_valid() calls scx_error() on an invalid value, so an invalid @cid does end at NUMA_NO_NODE, but only after flagging the whole scheduler for exit. Bounds-check @cid in the kfunc instead, keeping the documented benign return and leaving the aborting validation to the paths whose contracts call for it. Fixes: 5cadf7545cc6 ("sched_ext: Add a CID NUMA node lookup kfunc") Signed-off-by: Tao Cui --- kernel/sched/ext/cid.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel/sched/ext/cid.c b/kernel/sched/ext/cid.c index 8e04a8494e11..b09b2c73ccec 100644 --- a/kernel/sched/ext/cid.c +++ b/kernel/sched/ext/cid.c @@ -690,6 +690,16 @@ __bpf_kfunc s32 scx_bpf_cid_node(s32 cid, const struct bpf_prog_aux *aux) sch = scx_prog_sched(aux); if (unlikely(!sch)) return NUMA_NO_NODE; + + /* + * Bounds-check @cid here rather than letting scx_cid_to_cpu() do it: + * its cid_valid() aborts the scheduler on an invalid value, while + * this kfunc is documented as a benign lookup that returns + * NUMA_NO_NODE. + */ + if (cid < 0 || cid >= num_possible_cpus()) + return NUMA_NO_NODE; + cpu = scx_cid_to_cpu(sch, cid); return cpu < 0 ? NUMA_NO_NODE : cpu_to_node(cpu); } -- 2.53.0 base-commit: 5b740a72b55c4267ba4d8010f17dde26b26f52d3