From e4c636b0a0dd9f05c98431cc16845b7bf72865d6 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 3 Nov 2014 14:07:59 +0100 Subject: [PATCH] init: clamp priority values to valid range This patch ensures that priority values passed as session arguments are within the valid range of priorities. Without the clamping, a child could specify a priority of a lower priority band than the one assigned to the subsystem. Thanks to Johannes Schlatow for reporting this issue. Fixes #1279 --- repos/os/include/init/child_policy.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/repos/os/include/init/child_policy.h b/repos/os/include/init/child_policy.h index f0a3b4d2ed..1d98f1233f 100644 --- a/repos/os/include/init/child_policy.h +++ b/repos/os/include/init/child_policy.h @@ -105,7 +105,10 @@ namespace Init { if (Genode::strcmp(service, "CPU") || _prio_levels_log2 == 0) return; - long priority = Arg_string::find_arg(args, "priority").long_value(0); + unsigned long priority = Arg_string::find_arg(args, "priority").long_value(0); + + /* clamp priority value to valid range */ + priority = min((unsigned)Cpu_session::PRIORITY_LIMIT - 1, priority); long discarded_prio_lsb_bits_mask = (1 << _prio_levels_log2) - 1; if (priority & discarded_prio_lsb_bits_mask) {