From: sashiko-bot@kernel.org
To: "Cheng-Yang Chou" <yphbchou0911@gmail.com>
Cc: sched-ext@lists.linux.dev
Subject: Re: [PATCH 2/3] sched_ext: Add dispatch transaction API
Date: Fri, 15 May 2026 17:59:05 +0000 [thread overview]
Message-ID: <20260515175906.5FCBEC2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260515172807.254804-3-yphbchou0911@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double Fetch / TOCTOU vulnerability in `scx_bpf_dsq_insert_commit()` when accessing `args` fields.
- [High] Unprotected state modification (`p->scx.slice`) causing a data race on actively running or migrated tasks.
--
commit c413431466d2cd2f8ef609dabb82ff0b92ea46d2
Author: Cheng-Yang Chou <yphbchou0911@gmail.com>
sched_ext: Add dispatch transaction API
This commit introduces scx_bpf_dsq_insert_begin() and
scx_bpf_dsq_insert_commit() kfuncs to allow a dispatch transaction. This
mechanism extends the race detection window for schedulers that queue tasks
in ops.enqueue() but do not implement properly synchronized ops.dequeue().
Link: https://lore.kernel.org/r/20260203230639.1259869-1-arighi@nvidia.com/
> diff --git a/kernel/sched/ext.c b/kernel/sched/ext.c
> index 0dadda97ef57c..2dfcfc3c885bb 100644
> --- a/kernel/sched/ext.c
> +++ b/kernel/sched/ext.c
[ ... ]
> @@ -8518,6 +8530,92 @@ __bpf_kfunc void scx_bpf_dsq_insert_vtime(struct task_struct *p, u64 dsq_id,
[ ... ]
> +__bpf_kfunc bool scx_bpf_dsq_insert_commit(struct task_struct *p,
> + struct scx_bpf_dsq_insert_commit_args *args,
> + u64 token,
> + const struct bpf_prog_aux *aux)
> +{
> + struct scx_sched *sch;
> + u64 enq_flags = args->enq_flags;
> +
> + guard(rcu)();
> + sch = scx_prog_sched(aux);
> + if (unlikely(!sch))
> + return false;
> +
> + if (args->dsq_id != SCX_DSQ_LOCAL &&
> + (args->dsq_id & SCX_DSQ_LOCAL_ON) != SCX_DSQ_LOCAL_ON) {
Since pointer arguments to BPF kfuncs like args can point to shared memory
such as BPF map values, which can be concurrently modified by userspace or
other BPF programs, is it possible for args->dsq_id to change between reads?
If args->dsq_id changes to a global DSQ ID after this local-only check passes,
could it bypass the constraint during the subsequent scx_dsq_insert_preamble()
and scx_dsq_insert_stage() calls?
> + scx_error(sch, "scx_bpf_dsq_insert_commit() may only target local DSQs");
> + return false;
> + }
> +
> + if (!scx_dsq_insert_preamble(sch, p, args->dsq_id, &enq_flags))
> + return false;
> +
> + if (args->slice)
> + p->scx.slice = args->slice;
> + else
> + p->scx.slice = p->scx.slice ?: 1;
Could a concurrent modification to args->slice between the condition check
and the assignment result in setting the task's slice to 0, bypassing the
fallback logic?
Would it be safer to fetch args->dsq_id and args->slice exactly once into
local variables at the beginning of the function, similar to how
args->enq_flags is handled?
Additionally, since scx_bpf_dsq_insert_commit() is intended for schedulers
where p may have been dequeued or migrated to another CPU after the dispatch
token was captured, the current CPU might not hold p's runqueue lock here.
Could modifying p->scx.slice without synchronization cause a data race if
the task is actively running or queued on another CPU?
Even if the stale token is later detected and discarded by finish_dispatch(),
it appears the corruption to p->scx.slice would already have occurred. Is
there a way to defer this write or synchronize it so the active state is not
modified?
> +
> + scx_dsq_insert_stage(sch, p, args->dsq_id, enq_flags, token);
> +
> + return true;
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260515172807.254804-1-yphbchou0911@gmail.com?part=2
next prev parent reply other threads:[~2026-05-15 17:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-15 17:27 [PATCH v4 sched_ext/for-7.2 0/3] sched_ext: Add dispatch transaction API Cheng-Yang Chou
2026-05-15 17:27 ` [PATCH 1/3] sched_ext: Rename scx_dsq_insert_commit() to scx_dsq_insert_stage() Cheng-Yang Chou
2026-05-15 17:27 ` [PATCH 2/3] sched_ext: Add dispatch transaction API Cheng-Yang Chou
2026-05-15 17:59 ` sashiko-bot [this message]
2026-05-15 17:27 ` [PATCH 3/3] selftests/sched_ext: Add dispatch_cookie test Cheng-Yang Chou
2026-05-15 18:19 ` sashiko-bot
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=20260515175906.5FCBEC2BCB0@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=sched-ext@lists.linux.dev \
--cc=yphbchou0911@gmail.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