diff mbox series

dmi: dmicheck: return from dmi_table_smbios*() functions if signature test fails

Message ID BN8PR10MB40838292CB3400388CC285C299469@BN8PR10MB4083.namprd10.prod.outlook.com
State Deferred
Headers show
Series dmi: dmicheck: return from dmi_table_smbios*() functions if signature test fails | expand

Commit Message

James Puthukattukaran April 22, 2021, 7 p.m. UTC
If the dmi_table_smbios*() functions don't match the signature for the paticular
table, then return.

Signed-off-by: James Puthukattukaran <james.puthukattukaran@oracle.com>
---
 src/dmi/dmicheck/dmicheck.c | 46 +++++++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 18 deletions(-)

        }
+       free(table);
+

        mem = fwts_mmap(addr, length);
        if (mem != FWTS_MAP_FAILED) {
@@ -418,16 +421,19 @@ static void* dmi_table_smbios30(fwts_framework *fw, fwts_s
mbios30_entry *entry)
        }

        if (dmi_load_file("/sys/firmware/dmi/tables/smbios_entry_point", anchor,
 5) == FWTS_OK
-                       && strncmp(anchor, "_SM3_", 5) == 0) {
-               table = malloc(length);
-               if (!table)
-                       return NULL;
-               if (dmi_load_file_variable_size("/sys/firmware/dmi/tables/DMI",
table, &length) == FWTS_OK) {
-                       fwts_log_info(fw, "SMBIOS30 table loaded from /sys/firmw
are/dmi/tables/DMI");
-                       return table;
-               }
-               free(table);
+                       && strncmp(anchor, "_SM3_", 5) != 0)
+               return NULL;
+
+
+       table = malloc(length);
+       if (!table)
+               return NULL;
+       if (dmi_load_file_variable_size("/sys/firmware/dmi/tables/DMI", table, &
length) == FWTS_OK) {
+               fwts_log_info(fw, "SMBIOS30 table loaded from /sys/firmware/dmi/
tables/DMI");
+               return table;
        }
+       free(table);
+

        mem = fwts_mmap(addr, length);
        if (mem != FWTS_MAP_FAILED) {
@@ -648,6 +654,8 @@ static int smbios_entry_check(fwts_framework *fw)
                 */
                if (dmi_sane(fw, &entry) == FWTS_OK)
                        fwts_passed(fw, "SMBIOS Table Entry Structure Table Addr
ess and Length looks valid.");
+               else
+                       return FWTS_ERROR;
        }

        return FWTS_OK;
@@ -769,6 +777,8 @@ static int smbios30_entry_check(fwts_framework *fw)
                 */
                if (dmi_smbios30_sane(fw, &entry) == FWTS_OK)
                        fwts_passed(fw, "SMBIOS 3.0 Table Entry Structure Table
Address and Length looks valid.");
+               else
+                       return FWTS_ERROR;
        }

        return FWTS_OK;
--
1.8.3.1

Comments

Colin Ian King May 14, 2021, 9:16 a.m. UTC | #1
On 22/04/2021 20:00, James Puthukattukaran wrote:
> If the dmi_table_smbios*() functions don't match the signature for the paticular
> table, then return.
> 
> Signed-off-by: James Puthukattukaran <james.puthukattukaran@oracle.com>
> ---
>  src/dmi/dmicheck/dmicheck.c | 46 +++++++++++++++++++++++++++------------------
>  1 file changed, 28 insertions(+), 18 deletions(-)
> 
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index a240365..99cb893 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -370,16 +370,19 @@ static void* dmi_table_smbios(fwts_framework *fw, fwts_smb
> ios_entry *entry)
>         }
> 
>         if (dmi_load_file("/sys/firmware/dmi/tables/smbios_entry_point", anchor,
>  4) == FWTS_OK
> -                       && strncmp(anchor, "_SM_", 4) == 0) {
> -               table = malloc(length);
> -               if (!table)
> -                       return NULL;
> -               if (dmi_load_file("/sys/firmware/dmi/tables/DMI", table, length)
>  == FWTS_OK) {
> -                       fwts_log_info(fw, "SMBIOS table loaded from /sys/firmwar
> e/dmi/tables/DMI");
> -                       return table;
> -               }
> -               free(table);
> +                       && strncmp(anchor, "_SM_", 4) != 0)
> +               return NULL;
> +
> +
> +       table = malloc(length);
> +       if (!table)
> +               return NULL;
> +       if (dmi_load_file("/sys/firmware/dmi/tables/DMI", table, length) == FWTS
> _OK) {
> +               fwts_log_info(fw, "SMBIOS table loaded from /sys/firmware/dmi/ta
> bles/DMI");
> +               return table;
>         }
> +       free(table);
> +
> 
>         mem = fwts_mmap(addr, length);
>         if (mem != FWTS_MAP_FAILED) {
> @@ -418,16 +421,19 @@ static void* dmi_table_smbios30(fwts_framework *fw, fwts_s
> mbios30_entry *entry)
>         }
> 
>         if (dmi_load_file("/sys/firmware/dmi/tables/smbios_entry_point", anchor,
>  5) == FWTS_OK
> -                       && strncmp(anchor, "_SM3_", 5) == 0) {
> -               table = malloc(length);
> -               if (!table)
> -                       return NULL;
> -               if (dmi_load_file_variable_size("/sys/firmware/dmi/tables/DMI",
> table, &length) == FWTS_OK) {
> -                       fwts_log_info(fw, "SMBIOS30 table loaded from /sys/firmw
> are/dmi/tables/DMI");
> -                       return table;
> -               }
> -               free(table);
> +                       && strncmp(anchor, "_SM3_", 5) != 0)
> +               return NULL;
> +
> +
> +       table = malloc(length);
> +       if (!table)
> +               return NULL;
> +       if (dmi_load_file_variable_size("/sys/firmware/dmi/tables/DMI", table, &
> length) == FWTS_OK) {
> +               fwts_log_info(fw, "SMBIOS30 table loaded from /sys/firmware/dmi/
> tables/DMI");
> +               return table;
>         }
> +       free(table);
> +
> 
>         mem = fwts_mmap(addr, length);
>         if (mem != FWTS_MAP_FAILED) {
> @@ -648,6 +654,8 @@ static int smbios_entry_check(fwts_framework *fw)
>                  */
>                 if (dmi_sane(fw, &entry) == FWTS_OK)
>                         fwts_passed(fw, "SMBIOS Table Entry Structure Table Addr
> ess and Length looks valid.");
> +               else
> +                       return FWTS_ERROR;
>         }
> 
>         return FWTS_OK;
> @@ -769,6 +777,8 @@ static int smbios30_entry_check(fwts_framework *fw)
>                  */
>                 if (dmi_smbios30_sane(fw, &entry) == FWTS_OK)
>                         fwts_passed(fw, "SMBIOS 3.0 Table Entry Structure Table
> Address and Length looks valid.");
> +               else
> +                       return FWTS_ERROR;
>         }
> 
>         return FWTS_OK;
> --
> 1.8.3.1
> 

I can't seem to apply this patch:

git am
dmi-dmicheck-return-from-dmi_table_smbios-functions-if-signature-test-fails.patch
Applying: dmi: dmicheck: return from dmi_table_smbios*() functions if
signature test fails
error: patch fragment without header at line 11: @@ -418,16 +421,19 @@
static void* dmi_table_smbios30(fwts_framework *fw, fwts_s
Patch failed at 0001 dmi: dmicheck: return from dmi_table_smbios*()
functions if signature test fails
hint: Use 'git am --show-current-patch=diff' to see the failed patch
diff mbox series

Patch

diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
index a240365..99cb893 100644
--- a/src/dmi/dmicheck/dmicheck.c
+++ b/src/dmi/dmicheck/dmicheck.c
@@ -370,16 +370,19 @@  static void* dmi_table_smbios(fwts_framework *fw, fwts_smb
ios_entry *entry)
        }

        if (dmi_load_file("/sys/firmware/dmi/tables/smbios_entry_point", anchor,
 4) == FWTS_OK
-                       && strncmp(anchor, "_SM_", 4) == 0) {
-               table = malloc(length);
-               if (!table)
-                       return NULL;
-               if (dmi_load_file("/sys/firmware/dmi/tables/DMI", table, length)
 == FWTS_OK) {
-                       fwts_log_info(fw, "SMBIOS table loaded from /sys/firmwar
e/dmi/tables/DMI");
-                       return table;
-               }
-               free(table);
+                       && strncmp(anchor, "_SM_", 4) != 0)
+               return NULL;
+
+
+       table = malloc(length);
+       if (!table)
+               return NULL;
+       if (dmi_load_file("/sys/firmware/dmi/tables/DMI", table, length) == FWTS
_OK) {
+               fwts_log_info(fw, "SMBIOS table loaded from /sys/firmware/dmi/ta
bles/DMI");
+               return table;