Skip to content

Commit f45ab27

Browse files
neosys007jgross1
authored andcommitted
ARM: xen: validate hypervisor compatible before parsing its version
fdt_find_hyper_node() reads the raw compatible property and then derives hyper_node.version from a prefix match before later printing it with %s. Flat DT properties are external boot input, and this path does not prove that the first compatible entry is NUL-terminated within the returned property length. Keep the existing flat-DT lookup path, but verify that the first compatible entry terminates within the returned property length before deriving the version suffix from it. Signed-off-by: Pengpeng Hou <pengpeng@iscas.ac.cn> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Signed-off-by: Juergen Gross <jgross@suse.com> Message-ID: <20260405094005.5-arm-xen-v2-pengpeng@iscas.ac.cn>
1 parent 591cd65 commit f45ab27

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

arch/arm/xen/enlighten.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,9 @@ static __initdata struct {
218218
static int __init fdt_find_hyper_node(unsigned long node, const char *uname,
219219
int depth, void *data)
220220
{
221-
const void *s = NULL;
221+
const char *s = NULL;
222222
int len;
223+
size_t prefix_len = strlen(hyper_node.prefix);
223224

224225
if (depth != 1 || strcmp(uname, "hypervisor") != 0)
225226
return 0;
@@ -228,9 +229,10 @@ static int __init fdt_find_hyper_node(unsigned long node, const char *uname,
228229
hyper_node.found = true;
229230

230231
s = of_get_flat_dt_prop(node, "compatible", &len);
231-
if (strlen(hyper_node.prefix) + 3 < len &&
232-
!strncmp(hyper_node.prefix, s, strlen(hyper_node.prefix)))
233-
hyper_node.version = s + strlen(hyper_node.prefix);
232+
if (s && len > 0 && strnlen(s, len) < len &&
233+
len > prefix_len + 3 &&
234+
!strncmp(hyper_node.prefix, s, prefix_len))
235+
hyper_node.version = s + prefix_len;
234236

235237
/*
236238
* Check if Xen supports EFI by checking whether there is the

0 commit comments

Comments
 (0)