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
This commit is contained in:
Norman Feske 2014-11-03 14:07:59 +01:00 committed by Christian Helmuth
parent 8b0f9fd82a
commit e4c636b0a0
1 changed files with 4 additions and 1 deletions

View File

@ -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) {