ACK: [PATCH] lib: fwts_safe_mem: add SIGBUS handling

Alex Hung alex.hung at canonical.com
Tue Jun 6 18:14:04 UTC 2017


On 2017-06-05 07:15 AM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
> 
> We should also add SIGBUS protection on unsafe memory reads; we're
> seeing these occur on ARM64 platforms and we don't want fwts to break
> because of SIGBUS crashes.
> 
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/src/fwts_safe_mem.c | 18 +++++++++++-------
>   1 file changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/src/lib/src/fwts_safe_mem.c b/src/lib/src/fwts_safe_mem.c
> index fe71d5a8..a25d389a 100644
> --- a/src/lib/src/fwts_safe_mem.c
> +++ b/src/lib/src/fwts_safe_mem.c
> @@ -23,18 +23,19 @@
>   #include "fwts.h"
>   
>   static sigjmp_buf jmpbuf;
> -static struct sigaction old_action;
> +static struct sigaction old_segv_action, old_bus_action;
>   
>   /*
> - *  If we hit a SIGSEGV then the port read
> + *  If we hit a SIGSEGV or SIGBUS then the read
>    *  failed and we longjmp back and return
>    *  FWTS_ERROR
>    */
> -static void segv_handler(int dummy)
> +static void sig_handler(int dummy)
>   {
>   	FWTS_UNUSED(dummy);
>   
> -	fwts_sig_handler_restore(SIGSEGV, &old_action);
> +	fwts_sig_handler_restore(SIGSEGV, &old_segv_action);
> +	fwts_sig_handler_restore(SIGBUS, &old_bus_action);
>   	siglongjmp(jmpbuf, 1);
>   }
>   
> @@ -42,16 +43,19 @@ static void segv_handler(int dummy)
>    *  fwts_safe_memcpy()
>    *	memcpy that catches segfaults. to be used when
>    *	attempting to read BIOS tables from memory which
> - *	may segfault if the src address is corrupt
> + *	may segfault or throw a bus error if the src
> + *	address is corrupt
>    */
>   int fwts_safe_memcpy(void *dst, const void *src, const size_t n)
>   {
>   	if (sigsetjmp(jmpbuf, 1) != 0)
>   		return FWTS_ERROR;
>   	
> -	fwts_sig_handler_set(SIGSEGV, segv_handler, &old_action);
> +	fwts_sig_handler_set(SIGSEGV, sig_handler, &old_segv_action);
> +	fwts_sig_handler_set(SIGBUS, sig_handler, &old_bus_action);
>   	memcpy(dst, src, n);
> -	fwts_sig_handler_restore(SIGSEGV, &old_action);
> +	fwts_sig_handler_restore(SIGSEGV, &old_segv_action);
> +	fwts_sig_handler_restore(SIGBUS, &old_bus_action);
>   
>   	return FWTS_OK;
>   }
> 


Acked-by: Alex Hung <alex.hung at canonical.com>



More information about the fwts-devel mailing list