Commit 81d8ed2
committed
Fix use-after-free in process scheduling lists
When `do_spawn` fails after `context_new` has been called,
`context_destroy` is invoked directly. `context_new` calls
`globalcontext_init_process` which adds the context to both
`processes_table` and `waiting_processes`, but `context_destroy`
only removed from `processes_table`. The freed context's node
remained linked in `waiting_processes`, causing a use-after-free
corruption of the scheduling list.
Fix by adding a spinlock-protected `list_remove` + `list_init`
of `processes_list_head` in `context_destroy`. The `list_init`
makes the node self-referential so that a second `list_remove`
(from callers like `scheduler_terminate` that already do the
removal before calling `context_destroy`) is a safe no-op.
Also remove the now-redundant explicit removal in the native
handler kill path of `scheduler_run`, since `context_destroy`
handles it.
Signed-off-by: Peter M <petermm@gmail.com>1 parent fde1fb3 commit 81d8ed2
2 files changed
+8
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
143 | 150 | | |
144 | 151 | | |
145 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
287 | 287 | | |
288 | 288 | | |
289 | 289 | | |
290 | | - | |
291 | | - | |
292 | | - | |
293 | 290 | | |
294 | 291 | | |
295 | 292 | | |
| |||
429 | 426 | | |
430 | 427 | | |
431 | 428 | | |
| 429 | + | |
432 | 430 | | |
433 | 431 | | |
434 | 432 | | |
| |||
0 commit comments