From 27179c493623b7758aead29955e96a6c52248502 Mon Sep 17 00:00:00 2001 From: tangbinzy Date: Wed, 4 Sep 2024 07:56:16 +0000 Subject: [PATCH] smbios: sanitize type from external type before checking have_fields_bitmap mainline inclusion commit 57e3069641d057a9ca90bb603c86477d5b331ecd category: bugfix --------------------------------------------------------------- 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 Signed-off-by: tangbinzy --- hw/smbios/smbios.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c index f73b9417c8..d506fd4e7e 100644 --- a/hw/smbios/smbios.c +++ b/hw/smbios/smbios.c @@ -1171,13 +1171,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++; -- 2.41.0.windows.1