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 --- util/cbfstool/cbfstool.c | 8 ++++---- util/cbfstool/cse_serger.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'util') diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index cc8dbb5e3c..25f48478d2 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -423,9 +423,9 @@ static bool create_mmap_windows(void) &mmap_window_table[j].flash_space)) { ERROR("Flash space windows (base=0x%zx, limit=0x%zx) and (base=0x%zx, limit=0x%zx) overlap!\n", region_offset(&mmap_window_table[i].flash_space), - region_end(&mmap_window_table[i].flash_space), + region_last(&mmap_window_table[i].flash_space), region_offset(&mmap_window_table[j].flash_space), - region_end(&mmap_window_table[j].flash_space)); + region_last(&mmap_window_table[j].flash_space)); return false; } @@ -433,9 +433,9 @@ static bool create_mmap_windows(void) &mmap_window_table[j].host_space)) { ERROR("Host space windows (base=0x%zx, limit=0x%zx) and (base=0x%zx, limit=0x%zx) overlap!\n", region_offset(&mmap_window_table[i].flash_space), - region_end(&mmap_window_table[i].flash_space), + region_last(&mmap_window_table[i].flash_space), region_offset(&mmap_window_table[j].flash_space), - region_end(&mmap_window_table[j].flash_space)); + region_last(&mmap_window_table[j].flash_space)); return false; } } diff --git a/util/cbfstool/cse_serger.c b/util/cbfstool/cse_serger.c index 006a01e9be..9d74a120c3 100644 --- a/util/cbfstool/cse_serger.c +++ b/util/cbfstool/cse_serger.c @@ -647,7 +647,7 @@ static size_t get_cse_region_end_offset(void) size_t end_offset; for (size_t i = 0; i < BP_TOTAL; i++) { - end_offset = region_end(¶ms.layout_regions[i]); + end_offset = region_last(¶ms.layout_regions[i]) + 1; if (end_offset > offset) offset = end_offset; } -- cgit v1.2.3