Skip to content

Commit c3e152f

Browse files
rizlikdanielinux
authored andcommitted
fsp: check that stage1 doesn't overlap with stage1 data
1 parent 64d0277 commit c3e152f

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/boot_x86_fsp.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,36 @@ static void change_stack_and_invoke(uint32_t new_stack,
161161
: "r"(new_stack), "r"(ptr), "r"(other_func)
162162
: "%eax");
163163
}
164+
static int range_overlaps(uint32_t start1, uint32_t end1, uint32_t start2,
165+
uint32_t end2)
166+
{
167+
return !(end1 <= start2 || end2 <= start1);
168+
}
169+
170+
static int check_memory_ranges()
171+
{
172+
uint32_t wb_start, wb_end;
173+
174+
wb_start = (uint32_t)WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE;
175+
wb_end = wb_start + (_wolfboot_flash_end - _wolfboot_flash_start);
176+
if (range_overlaps(wb_start, wb_end, (uint32_t)_start_data,
177+
(uint32_t)_end_data))
178+
return -1;
179+
if (range_overlaps(wb_start, wb_end, (uint32_t)_start_bss,
180+
(uint32_t)_end_bss))
181+
return -1;
182+
if (range_overlaps((uint32_t)wb_start_bss,
183+
(uint32_t)wb_end_bss,
184+
(uint32_t)_start_data,
185+
(uint32_t)_end_data))
186+
return -1;
187+
if (range_overlaps((uint32_t)wb_start_bss,
188+
(uint32_t)wb_end_bss,
189+
(uint32_t)_start_bss,
190+
(uint32_t)_end_bss))
191+
return -1;
192+
return 0;
193+
}
164194
/*!
165195
* \brief Load the WolfBoot bootloader into memory.
166196
*
@@ -170,6 +200,12 @@ static void change_stack_and_invoke(uint32_t new_stack,
170200
static void load_wolfboot(void)
171201
{
172202
size_t wolfboot_size, bss_size;
203+
204+
if (check_memory_ranges() != 0) {
205+
wolfBoot_printf("wolfboot overlaps with loader data...stop" ENDLINE);
206+
panic();
207+
}
208+
173209
wolfBoot_printf("loading wolfboot at %x..." ENDLINE,
174210
(uint32_t)WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE);
175211
wolfboot_size = _wolfboot_flash_end - _wolfboot_flash_start;

0 commit comments

Comments
 (0)