smbios: sanitize type from external type before checking have_fields_bitmap
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 5 Sep 2022 10:32:44 +0000 (12:32 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Sun, 18 Sep 2022 07:17:40 +0000 (09:17 +0200)
test_bit uses header->type as an offset; if the file incorrectly specifies a
type greater than 127, smbios_entry_add will read and write garbage.

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

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
hw/smbios/smbios.c

index 60349ee402719d55896658bf203c4caab2506a78..4c9f66483052771cda4c7eca7cab77f6ecbefa68 100644 (file)
@@ -1205,13 +1205,15 @@ void smbios_entry_add(QemuOpts *opts, Error **errp)
             return;
         }
 
-        if (test_bit(header->type, have_fields_bitmap)) {
-            error_setg(errp,
-                       "can't load type %d struct, fields already specified!",
-                       header->type);
-            return;
+        if (header->type <= SMBIOS_MAX_TYPE) {
+            if (test_bit(header->type, have_fields_bitmap)) {
+                error_setg(errp,
+                           "can't load type %d struct, fields already specified!",
+                           header->type);
+                return;
+            }
+            set_bit(header->type, have_binfile_bitmap);
         }
-        set_bit(header->type, have_binfile_bitmap);
 
         if (header->type == 4) {
             smbios_type4_count++;