mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
sched_ext: Reject internal enq_flags in the dsq move kfuncs
The dsq insert kfuncs reject __SCX_ENQ_INTERNAL_MASK bits in scx_dsq_insert_preamble() instead of scx_vet_enq_flags(). A scheduler can smuggle internal flags such as SCX_ENQ_CLEAR_OPSS through the dsq move kfuncs and corrupt the dispatch protocol. Move the rejection into scx_vet_enq_flags(). The vtime move wrapper OR'd the internal SCX_ENQ_DSQ_PRIQ bit into enq_flags before the vet; the bit now goes in inside scx_dsq_move() after the vet. Signed-off-by: Tejun Heo <tj@kernel.org> Reviewed-by: Andrea Righi <arighi@nvidia.com>
This commit is contained in:
parent
f82b16b8e8
commit
1fd50778b1
|
|
@ -8394,6 +8394,11 @@ static bool scx_vet_enq_flags(struct scx_sched *sch, u64 dsq_id, u64 *enq_flags)
|
|||
bool is_local = dsq_id == SCX_DSQ_LOCAL ||
|
||||
(dsq_id & SCX_DSQ_LOCAL_ON) == SCX_DSQ_LOCAL_ON;
|
||||
|
||||
if (unlikely(*enq_flags & __SCX_ENQ_INTERNAL_MASK)) {
|
||||
scx_error(sch, "invalid enq_flags 0x%llx", *enq_flags);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (*enq_flags & SCX_ENQ_IMMED) {
|
||||
if (unlikely(!is_local)) {
|
||||
scx_error(sch, "SCX_ENQ_IMMED on a non-local DSQ 0x%llx", dsq_id);
|
||||
|
|
@ -8416,11 +8421,6 @@ static bool scx_dsq_insert_preamble(struct scx_sched *sch, struct task_struct *p
|
|||
return false;
|
||||
}
|
||||
|
||||
if (unlikely(*enq_flags & __SCX_ENQ_INTERNAL_MASK)) {
|
||||
scx_error(sch, "invalid enq_flags 0x%llx", *enq_flags);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* see SCX_EV_INSERT_NOT_OWNED definition */
|
||||
if (unlikely(!scx_task_on_sched(sch, p))) {
|
||||
__scx_add_event(sch, SCX_EV_INSERT_NOT_OWNED, 1);
|
||||
|
|
@ -8652,7 +8652,8 @@ static const struct btf_kfunc_id_set scx_kfunc_set_enqueue_dispatch = {
|
|||
};
|
||||
|
||||
static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit,
|
||||
struct task_struct *p, u64 dsq_id, u64 enq_flags)
|
||||
struct task_struct *p, u64 dsq_id, u64 enq_flags,
|
||||
bool priq)
|
||||
{
|
||||
struct scx_dispatch_q *src_dsq = kit->dsq, *dst_dsq;
|
||||
struct scx_sched *sch;
|
||||
|
|
@ -8674,6 +8675,10 @@ static bool scx_dsq_move(struct bpf_iter_scx_dsq_kern *kit,
|
|||
if (!scx_vet_enq_flags(sch, dsq_id, &enq_flags))
|
||||
return false;
|
||||
|
||||
/* internal bit, can only go in after @enq_flags is vetted */
|
||||
if (priq)
|
||||
enq_flags |= SCX_ENQ_DSQ_PRIQ;
|
||||
|
||||
/*
|
||||
* If the BPF scheduler keeps calling this function repeatedly, it can
|
||||
* cause similar live-lock conditions as scx_consume_dispatch_q().
|
||||
|
|
@ -8930,7 +8935,7 @@ __bpf_kfunc bool scx_bpf_dsq_move(struct bpf_iter_scx_dsq *it__iter,
|
|||
u64 enq_flags)
|
||||
{
|
||||
return scx_dsq_move((struct bpf_iter_scx_dsq_kern *)it__iter,
|
||||
p, dsq_id, enq_flags);
|
||||
p, dsq_id, enq_flags, false);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -8955,7 +8960,7 @@ __bpf_kfunc bool scx_bpf_dsq_move_vtime(struct bpf_iter_scx_dsq *it__iter,
|
|||
u64 enq_flags)
|
||||
{
|
||||
return scx_dsq_move((struct bpf_iter_scx_dsq_kern *)it__iter,
|
||||
p, dsq_id, enq_flags | SCX_ENQ_DSQ_PRIQ);
|
||||
p, dsq_id, enq_flags, true);
|
||||
}
|
||||
|
||||
__bpf_kfunc_end_defs();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user