Re: [PATCH v2 2/3] sched/fair: Fix panic if pick_eevdf() returns NULL

From: Peter Zijlstra
Date: Fri Nov 29 2024 - 04:18:59 EST


On Wed, Nov 27, 2024 at 05:56:09AM +0000, Adam Li wrote:
> pick_eevdf() may return NULL, which triggers NULL pointer
> dereference at pick_next_entity():
> struct sched_entity *se = pick_eevdf(cfs_rq);
> if (se->sched_delayed)
>
> [ 297.371198] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000051
> [ 297.406112] CPU: 116 UID: 0 PID: 10328 Comm: Grizzly-worker( Tainted: G W E 6.12.0.adam+ #1
> [ 297.597362] Call trace:
> [ 297.599795] pick_task_fair+0x50/0x150 (P)
> [ 297.603879] pick_task_fair+0x50/0x150 (L)
> [ 297.607963] pick_next_task_fair+0x30/0x3c0
> [ 297.612134] __pick_next_task+0x4c/0x220
> [ 297.616045] pick_next_task+0x44/0x980

Well, if you look at pick_task_fair() you'll see we'll not get there
unless cfs_rq->nr_running is non-zero, at which point pick_eevdf()
really should NOT be returning NULL.

If it does, something else is broken.