|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 2/2] tools/xl: fix overflow when parsing llc_colors ranges
The number of colors in a range is computed as (end - start) + 1 using
uint32_t arithmetic, and the loop that fills the array compares the
color with end. Both break when end is UINT32_MAX:
- "0-4294967295" makes the count wrap to 0, so the array is not grown
and the loop writes through a NULL pointer.
- "4294967290-4294967295" has a valid count, but k <= end is always
true, so the loop never terminates and writes past the end of the
array.
The total can also exceed INT_MAX, which is the limit of
num_llc_colors.
Reject a range if it would make the total exceed INT_MAX, and loop over
the offset from start instead of over the color itself. After the
check, end - start is below INT_MAX, so the loop always terminates.
The hypervisor's own parser for the same syntax, in
xen/common/llc-coloring.c, already checks for this.
Fixes: 748bd725fbec ("tools: add support for cache coloring configuration")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Bala Andegue François Lionnel
<balaandeguefrancoislionnel@xxxxxxxxx>
---
Notes:
Tested in a nested setup (Xen built from staging, busybox dom0 under
QEMU/KVM) with "xl -N create" and three values of llc_colors:
- [ "0-3", "8", "10-12" ]: 0,1,2,3,8,10,11,12, both before and after.
- [ "4294967290-4294967295" ]: segfault before, six colors after.
- [ "0-4294967295" ]: segfault before, "xl: Too many LLC colors" after.
tools/xl/xl_parse.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c
index 4aa29f75f3d5..d95e7b55d2c4 100644
--- a/tools/xl/xl_parse.c
+++ b/tools/xl/xl_parse.c
@@ -1554,12 +1554,17 @@ void parse_config_data(const char *config_source,
exit(1);
}
+ if (end - start >= INT_MAX - b_info->num_llc_colors) {
+ fprintf(stderr, "xl: Too many LLC colors: %s\n", buf);
+ exit(1);
+ }
+
b_info->num_llc_colors += (end - start) + 1;
b_info->llc_colors = xrealloc(b_info->llc_colors,
sizeof(*b_info->llc_colors) * b_info->num_llc_colors);
- for (k = start; k <= end; k++)
- b_info->llc_colors[cur_index++] = k;
+ for (k = 0; k <= end - start; k++)
+ b_info->llc_colors[cur_index++] = start + k;
}
}
--
2.39.2
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |