From 61b22cb930388510d057cdd79392529660fa4a8c Mon Sep 17 00:00:00 2001 From: Arthur Heymans Date: Tue, 8 Jan 2019 23:25:04 +0100 Subject: drivers/intel/fsp1_1: Add stack guards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This allows to check if stack overflows the car globals. Change-Id: I369b2d846f35914facb3e69cc762f7e555271bec Signed-off-by: Arthur Heymans Reviewed-on: https://review.coreboot.org/c/30751 Tested-by: build bot (Jenkins) Reviewed-by: Kyösti Mälkki Reviewed-by: Paul Menzel --- src/drivers/intel/fsp1_1/car.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/drivers/intel/fsp1_1/car.c b/src/drivers/intel/fsp1_1/car.c index 13161d66d5..63c5042776 100644 --- a/src/drivers/intel/fsp1_1/car.c +++ b/src/drivers/intel/fsp1_1/car.c @@ -35,6 +35,21 @@ static inline void set_fih_car(FSP_INFO_HEADER *fih) asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params) { + int i; + const int num_guards = 4; + const u32 stack_guard = 0xdeadbeef; + u32 *stack_base; + u32 size; + + /* Size of unallocated CAR. */ + size = _car_region_end - _car_relocatable_data_end; + size = ALIGN_DOWN(size, 16); + + stack_base = (u32 *) (_car_region_end - size); + + for (i = 0; i < num_guards; i++) + stack_base[i] = stack_guard; + /* Initialize timestamp book keeping only once. */ timestamp_init(car_params->tsc); @@ -63,6 +78,13 @@ asmlinkage void *cache_as_ram_main(struct cache_as_ram_params *car_params) set_fih_car(car_params->fih); + /* Check the stack. */ + for (i = 0; i < num_guards; i++) { + if (stack_base[i] == stack_guard) + continue; + printk(BIOS_DEBUG, "Smashed stack detected in romstage!\n"); + } + /* Return new stack value in RAM back to assembly stub. */ return cache_as_ram_stage_main(car_params->fih); } -- cgit v1.2.3