llc-coloring: improve checking while parsing

We can easily avoid the risk of wrapping UINT_MAX <-> 0 by applying a
check against the compile-time-constant maximum number of colors.

Additionally the overflow checks suffered from an off-by-1, as the parsed
ranges are inclusive (e.g. end == start being possible, requiring 1 array
slot, while availability of 0 slots was checked in that case).

Fixes: 6cdea3444e ("xen/arm: add Dom0 cache coloring support")
Reported-by: Mykola Kvach <xakep.amatop@gmail.com>
Reported-by: Kamil Frankowicz <kamil.frankowicz@cert.pl>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
Jan Beulich committed 2026-04-07 13:52:44 +02:00
1 parent 97bd7f26f6
commit cba8a584de
1 file changed
+3 -2
+3 -2
View File
@@ -76,8 +76,9 @@ static int __init parse_color_config(const char *buf, unsigned int colors[],
else /* Single value */
end = start;
if ( start > end || (end - start) > (UINT_MAX - *num_colors) ||
(*num_colors + (end - start)) >= max_num_colors )
if ( end >= NR_LLC_COLORS || start > end ||
(end - start) >= (UINT_MAX - *num_colors) ||
(*num_colors + (end - start + 1)) >= max_num_colors )
return -EINVAL;
/* Colors are range checked in check_colors() */
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.