From a188dbbf55e768f881359ec1135c0a6d49a038f0 Mon Sep 17 00:00:00 2001 From: Hesham Almatary Date: Mon, 31 Jul 2023 14:44:01 +0100 Subject: [PATCH] Fix: NULL-terminate existing_frames[] array libsel4utils/reserve_initial_task_regions iterates over existing_frames and expects it to be null-terminated. Without this commit, the behaviour will rely on whatever the stack had before allocating existing_frames[] in the stack, and subsequent calls may fail, hang, or reserve incorrect frames; depending on the stack values. Sponsored by: DARPA. Signed-off-by: Hesham Almatary --- apps/sel4test-tests/src/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/sel4test-tests/src/main.c b/apps/sel4test-tests/src/main.c index 53cf39b2..d77a5423 100644 --- a/apps/sel4test-tests/src/main.c +++ b/apps/sel4test-tests/src/main.c @@ -119,13 +119,14 @@ static void init_allocator(env_t env, test_init_data_t *init_data) arch_init_allocator(env, init_data); /* create a vspace */ - void *existing_frames[init_data->stack_pages + 2]; + void *existing_frames[init_data->stack_pages + 3]; existing_frames[0] = (void *) init_data; existing_frames[1] = seL4_GetIPCBuffer(); assert(init_data->stack_pages > 0); for (int i = 0; i < init_data->stack_pages; i++) { existing_frames[i + 2] = init_data->stack + (i * PAGE_SIZE_4K); } + existing_frames[init_data->stack_pages + 2] = NULL; error = sel4utils_bootstrap_vspace(&env->vspace, &alloc_data, init_data->page_directory, &env->vka, NULL, NULL, existing_frames);