From 41feb32559d574e7e08f42742dc4ef8abc3ddd46 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sun, 14 Jan 2024 14:26:37 +0100 Subject: region: Turn region_end() into an inclusive region_last() The current region_end() implementation is susceptible to overflow if the region is at the end of the addressable space. A common case with the memory-mapped flash of x86 directly below the 32-bit limit. Note: This patch also changes console output to inclusive limits. IMO, to the better. Change-Id: Ic4bd6eced638745b7e845504da74542e4220554a Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/coreboot/+/79946 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/cpu/x86/smm/smm_module_loader.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/cpu/x86/smm') diff --git a/src/cpu/x86/smm/smm_module_loader.c b/src/cpu/x86/smm/smm_module_loader.c index 979fa485ab..c6d0753c6b 100644 --- a/src/cpu/x86/smm/smm_module_loader.c +++ b/src/cpu/x86/smm/smm_module_loader.c @@ -341,7 +341,7 @@ static void setup_smihandler_params(struct smm_runtime *mod_params, } for (int i = 0; i < loader_params->num_cpus; i++) - mod_params->save_state_top[i] = region_end(&cpus[i].ss); + mod_params->save_state_top[i] = region_last(&cpus[i].ss) + 1; if (CONFIG(RUNTIME_CONFIGURABLE_SMM_LOGLEVEL)) mod_params->smm_log_level = mainboard_set_smm_log_level(); @@ -371,7 +371,7 @@ static void setup_smihandler_params(struct smm_runtime *mod_params, static void print_region(const char *name, const struct region region) { printk(BIOS_DEBUG, "%-12s [0x%zx-0x%zx]\n", name, region_offset(®ion), - region_end(®ion)); + region_last(®ion)); } /* STM + Handler + (Stub + Save state) * CONFIG_MAX_CPUS + stacks + page tables*/ @@ -482,7 +482,7 @@ int smm_load_module(const uintptr_t smram_base, const size_t smram_size, return -1; const struct region smram = region_create(smram_base, smram_size); - const uintptr_t smram_top = region_end(&smram); + const uintptr_t smram_top = region_last(&smram) + 1; const size_t stm_size = CONFIG(STM) ? CONFIG_MSEG_SIZE + CONFIG_BIOS_RESOURCE_LIST_SIZE : 0; -- cgit v1.2.3