From 5bdc88bf57d66155e45d2da56e1d0f3ccf9f5a96 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 1 Feb 2023 14:51:54 +0100 Subject: [PATCH] base-hw scheduler: sanitize access to invalid head Issue #4755 --- repos/base-hw/src/core/kernel/cpu.h | 2 +- repos/base-hw/src/core/kernel/cpu_scheduler.cc | 7 +++++-- repos/base-hw/src/core/kernel/cpu_scheduler.h | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/repos/base-hw/src/core/kernel/cpu.h b/repos/base-hw/src/core/kernel/cpu.h index e47d1adf73..35ab1b0014 100644 --- a/repos/base-hw/src/core/kernel/cpu.h +++ b/repos/base-hw/src/core/kernel/cpu.h @@ -171,7 +171,7 @@ class Kernel::Cpu : public Genode::Cpu, private Irq::Pool, private Timeout /** * Returns the currently active job */ - Job & scheduled_job() const { + Job & scheduled_job() { return *static_cast(&_scheduler.head())->helping_destination(); } unsigned id() const { return _id; } diff --git a/repos/base-hw/src/core/kernel/cpu_scheduler.cc b/repos/base-hw/src/core/kernel/cpu_scheduler.cc index fd600e73d2..c97d49285d 100644 --- a/repos/base-hw/src/core/kernel/cpu_scheduler.cc +++ b/repos/base-hw/src/core/kernel/cpu_scheduler.cc @@ -313,9 +313,12 @@ void Cpu_scheduler::quota(Share &s, unsigned const q) } -Cpu_share &Cpu_scheduler::head() const +Cpu_share &Cpu_scheduler::head() { - assert(_head); + if (!_head) { + Genode::error("attempt to access invalid scheduler head"); + update(_last_time); + } return *_head; } diff --git a/repos/base-hw/src/core/kernel/cpu_scheduler.h b/repos/base-hw/src/core/kernel/cpu_scheduler.h index a1e4a0770f..4699292f40 100644 --- a/repos/base-hw/src/core/kernel/cpu_scheduler.h +++ b/repos/base-hw/src/core/kernel/cpu_scheduler.h @@ -233,7 +233,7 @@ class Kernel::Cpu_scheduler * Accessors */ - Share &head() const; + Share &head(); unsigned head_quota() const { return Genode::min(_head_quota, _residual); } unsigned quota() const { return _quota; }