Skip to contentSkip to conversation

smbios: sanitize type from external type before checking have_fields_bitmap

PATCH Superseded Paolo Bonzini 2 participants 2 messages Sep 5, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smbios: sanitize type from external type before checking have_fields_bitmap

test_bit uses header->type as an offset; if the file incorrectly specifies a type greater than 127, smbios_entry_add will read garbage.

To fix this, just pass the smbios data through, assuming the user knows what to do. Reported by Coverity as CID 1487255.

---
 hw/smbios/smbios.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/smbios/smbios.c +2 -1
index 60349ee402..485fa15202 100644
@@ -1205,7 +1205,8 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)
             return;
         }
 
-        if (test_bit(header->type, have_fields_bitmap)) {
+        if (header->type <= SMBIOS_MAX_TYPE &&
+            test_bit(header->type, have_fields_bitmap)) {
             error_setg(errp,
                        "can't load type %d struct, fields already specified!",
                        header->type);
Signature · 1 line
2.37.2
#1 lore raw
Quoted 16 lines · Paolo Bonzini

test_bit uses header->type as an offset; if the file incorrectly specifies a type greater than 127, smbios_entry_add will read garbage.

To fix this, just pass the smbios data through, assuming the user knows what to do. Reported by Coverity as CID 1487255.

---
  hw/smbios/smbios.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/smbios/smbios.c +0 -0
index 60349ee402..485fa15202 100644

hw/smbios/smbios.c void smbios_entry_add(QemuOpts *opts, Error **errp) · line 1212

Quoted 9 lines
hw/smbios/smbios.c +2 -1
@@ -1205,7 +1205,8 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)
              return;
          }
 
-        if (test_bit(header->type, have_fields_bitmap)) {
+        if (header->type <= SMBIOS_MAX_TYPE &&
+            test_bit(header->type, have_fields_bitmap)) {
              error_setg(errp,
                         "can't load type %d struct, fields already specified!",
                         header->type);

Completing the diff:

            return;
        }
        set_bit(header->type, have_binfile_bitmap);

Same problem here ^^^

It seems safer to check header->type range before load_image_size().