Re: [PATCH v2] sched/core: Fix a TOCTOU bug in sched_non_preferred_cpu_push_stop()

From: fushuai . wang

Date: Thu Nov 19 2026 - 22:18:56 EST


2026年11月19日 17:07, "Peter Zijlstra" <peterz@xxxxxxxxxxxxx mailto:peterz@xxxxxxxxxxxxx?to=%22Peter%20Zijlstra%22%20%3Cpeterz%40infradead.org%3E > 写到:

> >
> > kernel/sched/core.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> > index 5ed660f099a5..6f9374aa3f19 100644
> > --- a/kernel/sched/core.c
> > +++ b/kernel/sched/core.c
> > @@ -11314,7 +11314,8 @@ static int sched_non_preferred_cpu_push_stop(void *arg)
> > rq->npc_push_work_pending = false;
> > update_rq_clock(rq);
> >
> > - if (task_rq(p) == rq && task_on_rq_queued(p)) {
> > + if (task_rq(p) == rq && task_on_rq_queued(p) &&
> > + !is_migration_disabled(p)) {
> > struct rq *dest_rq = __migrate_task(rq, &rf, p, cpu);
> >
> > if (rq != dest_rq)
> >
> I think I like a comment with this. Perhaps add something like:
>
> /*
> * Racy: is_migration_disabled(current) isn't stable.
> */
> if (is_migration_disabled(push_task))
> return;
>
> in sched_push_current_non_preferred_cpu().

Hi, Peter

Will add it in v3.

>
> Also, I wonder if you'd find more of this if you stick something like:
>
> lockdep_assert(!task_on_cpu(p) || in_task());
>
> inside is_migration_disabled().
>

I'll add it and run more tests.

Regards,
Fushuai.