[PATCH] lib: fwts_smbios: use fwts_safe_memcpy to read SMBIOS entry

Naresh Bhat naresh.bhat at linaro.org
Fri Aug 11 15:14:39 UTC 2017


Thanks Colin,

On 11 August 2017 at 19:11, Colin King <colin.king at canonical.com> wrote:

> From: Colin Ian King <colin.king at canonical.com>
>
> Use fwts_safe_memcpy rather than a fwts_safe_memread and then an
> un-safe copy as a micro optimisation.  Also throw an error and
> return a NULL address if the memcpy failed because the memory is
> unreadable.  Fixes a bug on aarch64 systems where this entry is
> non-readable and causes a BUS error.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/lib/src/fwts_smbios.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_smbios.c b/src/lib/src/fwts_smbios.c
> index b3773aa2..abef4eb6 100644
> --- a/src/lib/src/fwts_smbios.c
> +++ b/src/lib/src/fwts_smbios.c
> @@ -56,13 +56,14 @@ static void *fwts_smbios_find_entry_uefi(fwts_framework
> *fw, fwts_smbios_entry *
>                 const size_t size = sizeof(fwts_smbios_entry);
>
>                 if ((mapped_entry = fwts_mmap((off_t)addr, size)) !=
> FWTS_MAP_FAILED) {
> -                       if (fwts_safe_memread(mapped_entry, size) ==
> FWTS_OK) {
> -                               *entry = *mapped_entry;
> +                       if (fwts_safe_memcpy(entry, mapped_entry, size) ==
> FWTS_OK) {
>                                 (void)fwts_munmap(mapped_entry, size);
>                                 *type  = FWTS_SMBIOS;
>                                 return addr;
>                         } else {
> +                               fwts_log_error(fw, "Cannot read mmap'd
> SMBIOS entry at 0x%p\n", addr);
>                                 (void)fwts_munmap(mapped_entry, size);
> +                               addr = NULL;
>                         }
>                 }
>
> @@ -73,7 +74,7 @@ static void *fwts_smbios_find_entry_uefi(fwts_framework
> *fw, fwts_smbios_entry *
>                         return addr;
>                 }
>
> -               fwts_log_error(fw, "Cannot mmap SMBIOS entry at %p\n",
> addr);
> +               fwts_log_error(fw, "Cannot mmap SMBIOS entry at 0x%p\n",
> addr);
>         }
>         return NULL;
>  }
> --
> 2.11.0
>

I have tested this patch on Cavium ThunderX2 hardware.

Reviewed-By/Tested-By: Naresh Bhat <naresh.bhat at linaro.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/fwts-devel/attachments/20170811/5147566d/attachment.html>


More information about the fwts-devel mailing list