diff options
author | Nico Huber <nico.h@gmx.de> | 2024-01-11 18:59:24 +0100 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2024-08-11 17:07:32 +0000 |
commit | af0d4bce65df277b56e495892dff1c712ed76ddd (patch) | |
tree | 73aef7f8fb6301f0af8e08e3f7f78823d0ebdfe6 /src/drivers/spi/winbond.c | |
parent | 0e9830884c118735ad0122c81156473d91f57cf1 (diff) |
region: Introduce region_create() functions
We introduce two new functions to create region objects. They allow us
to check for integer overflows (region_create_untrusted()) or assert
their absence (region_create()).
This fixes potential overflows in region_overlap() checks in SMI
handlers, where we would wrongfully report MMIO as *not* overlapping
SMRAM.
Also, two cases of strtol() in parse_region() (cbfstool), where the
results were implicitly converted to `size_t`, are replaced with the
unsigned strtoul().
FIT payload support is left out, as it doesn't use the region API
(only the struct).
Change-Id: I4ae3e6274c981c9ab4fb1263c2a72fa68ef1c32b
Ticket: https://ticket.coreboot.org/issues/522
Found-by: Vadim Zaliva <lord@digamma.ai>
Signed-off-by: Nico Huber <nico.h@gmx.de>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/79905
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Diffstat (limited to 'src/drivers/spi/winbond.c')
-rw-r--r-- | src/drivers/spi/winbond.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c index 3137bfe8a7..3426d08e70 100644 --- a/src/drivers/spi/winbond.c +++ b/src/drivers/spi/winbond.c @@ -267,8 +267,7 @@ static void winbond_bpbits_to_region(const size_t granularity, tb = !tb; } - out->offset = tb ? 0 : flash_size - protected_size; - out->size = protected_size; + *out = region_create(tb ? 0 : flash_size - protected_size, protected_size); } /* @@ -525,8 +524,8 @@ winbond_set_write_protection(const struct spi_flash *flash, if (region_sz(&wp_region) > flash->size / 2) { cmp = 1; - wp_region.offset = tb ? 0 : region_sz(&wp_region); - wp_region.size = flash->size - region_sz(&wp_region); + wp_region = region_create(tb ? 0 : region_sz(&wp_region), + flash->size - region_sz(&wp_region)); tb = !tb; } else { cmp = 0; |