[PATCH 0/2] sched_ext: two more context-safety fixes found in the NMI kfunc audit

Wanwu Li posted 2 patches 3 weeks, 2 days ago
kernel/sched/ext/idle.c     | 14 ++++++++++++--
kernel/sched/ext/internal.h |  9 +++++++++
2 files changed, 21 insertions(+), 2 deletions(-)
[PATCH 0/2] sched_ext: two more context-safety fixes found in the NMI kfunc audit
Posted by Wanwu Li 3 weeks, 2 days ago
Continuing the audit that the sashiko bot kicked off on the NMI-reject
series, I went through every kfunc exposed to BPF_PROG_TYPE_TRACING
(the any / idle / cid context-filter sets). Two more context-safety
issues came out of it; this pair addresses both.

 - Patch 1 fixes the scx_locked_rq() class (three "any"-category kfuncs
   read scx_locked_rq() and take an unsafe fast path on a non-NULL
   return from NMI). scx_locked_rq() gains an in_nmi() test at the
   source that returns NULL from NMI, so the three callers fall onto
   their unlocked paths. This supersedes guarding them individually.

 - Patch 2 fixes an IRQ re-entrancy race on the per-CPU
   per_cpu_unvisited nodemask scratch in the idle path. The search
   scratch is protected only by preempt_disable(), which doesn't mask
   IRQs; switch to irqsave instead. The NMI case is left as-is (a
   misuse with no legitimate use and no crash risk).

Wanwu Li (2):
  sched_ext: Make scx_locked_rq() return NULL from NMI
  sched_ext: Protect the idle-search scratch nodemask with irqsave

 kernel/sched/ext/idle.c     | 14 ++++++++++++--
 kernel/sched/ext/internal.h |  9 +++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

-- 
2.25.1
Re: [PATCH 0/2] sched_ext: two more context-safety fixes found in the NMI kfunc audit
Posted by Tejun Heo 3 weeks, 1 day ago
> Wanwu Li (2):
>   sched_ext: Make scx_locked_rq() return NULL from NMI
>   sched_ext: Protect the idle-search scratch nodemask with irqsave

Applied 1-2 to sched_ext/for-7.4.

Thanks.

--
tejun