[PATCH 4/5] bios: romdump: ensure mmap'd memory is readable before accessing it

Colin King colin.king at canonical.com
Wed Jul 12 12:53:33 UTC 2017


From: Colin Ian King <colin.king at canonical.com>

We need to check we don't get SIGSEGV or SIGBUS errors when reading
the mmap'd data before we try and access it. Use the fwts_safe_memread
check on the data to sanity check these mappings.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/bios/romdump/romdump.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/bios/romdump/romdump.c b/src/bios/romdump/romdump.c
index 4cf85256..a392d25e 100644
--- a/src/bios/romdump/romdump.c
+++ b/src/bios/romdump/romdump.c
@@ -52,6 +52,10 @@ static int romdump_test1(fwts_framework *fw)
 	}
 
 	for (i = 0; i < BIOS_ROM_REGION_SIZE; i += 512) {
+		/* Ensure we can safely read the memory */
+		if (fwts_safe_memread(mem + i, 512) != FWTS_OK)
+			continue;
+
 		if ((*(mem+i) == 0x55) && (*(mem+i+1) == 0xaa)) {
 			int length = *(mem+i+2) << 9;
 
-- 
2.11.0




More information about the fwts-devel mailing list