diff mbox

[3/5] bios: ebdadump: ensure mmap'd memory is readable before accessing it

Message ID 20170712125334.20176-4-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King July 12, 2017, 12:53 p.m. UTC
From: Colin Ian King <colin.king@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@canonical.com>
---
 src/bios/ebdadump/ebdadump.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Alex Hung July 12, 2017, 3:43 p.m. UTC | #1
On 2017-07-12 05:53 AM, Colin King wrote:
> From: Colin Ian King <colin.king@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@canonical.com>
> ---
>   src/bios/ebdadump/ebdadump.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/bios/ebdadump/ebdadump.c b/src/bios/ebdadump/ebdadump.c
> index 437f225a..94f9376c 100644
> --- a/src/bios/ebdadump/ebdadump.c
> +++ b/src/bios/ebdadump/ebdadump.c
> @@ -66,7 +66,10 @@ static int ebdadump_test1(fwts_framework *fw)
>   		BIOS_ROM_START,
>   		len);
>   
> -	ebdadump_data(fw, mem, ebda_addr, len);
> +	if (fwts_safe_memread((void *)mem, len) != FWTS_OK)
> +		fwts_log_info(fw, "EBDA region at cannot be read");
> +	else
> +		ebdadump_data(fw, mem, ebda_addr, len);
>           (void)fwts_munmap(mem, len);
>   
>   	fwts_infoonly(fw);
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu July 13, 2017, 2:17 a.m. UTC | #2
On 07/12/2017 08:53 PM, Colin King wrote:
> From: Colin Ian King <colin.king@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@canonical.com>
> ---
>   src/bios/ebdadump/ebdadump.c | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/src/bios/ebdadump/ebdadump.c b/src/bios/ebdadump/ebdadump.c
> index 437f225a..94f9376c 100644
> --- a/src/bios/ebdadump/ebdadump.c
> +++ b/src/bios/ebdadump/ebdadump.c
> @@ -66,7 +66,10 @@ static int ebdadump_test1(fwts_framework *fw)
>   		BIOS_ROM_START,
>   		len);
>   
> -	ebdadump_data(fw, mem, ebda_addr, len);
> +	if (fwts_safe_memread((void *)mem, len) != FWTS_OK)
> +		fwts_log_info(fw, "EBDA region at cannot be read");
> +	else
> +		ebdadump_data(fw, mem, ebda_addr, len);
>           (void)fwts_munmap(mem, len);
>   
>   	fwts_infoonly(fw);
> 


Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox

Patch

diff --git a/src/bios/ebdadump/ebdadump.c b/src/bios/ebdadump/ebdadump.c
index 437f225a..94f9376c 100644
--- a/src/bios/ebdadump/ebdadump.c
+++ b/src/bios/ebdadump/ebdadump.c
@@ -66,7 +66,10 @@  static int ebdadump_test1(fwts_framework *fw)
 		BIOS_ROM_START,
 		len);
 
-	ebdadump_data(fw, mem, ebda_addr, len);
+	if (fwts_safe_memread((void *)mem, len) != FWTS_OK)
+		fwts_log_info(fw, "EBDA region at cannot be read");
+	else
+		ebdadump_data(fw, mem, ebda_addr, len);
         (void)fwts_munmap(mem, len);
 
 	fwts_infoonly(fw);