smbios: sanitize type from external type before checking have_fields_bitmap
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
@@ -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
Quoted 16 lines · Paolo Bonzini
test_bitusesheader->typeas an offset; if the file incorrectly specifies a type greater than 127,smbios_entry_addwill read 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 <[email protected]>--- hw/smbios/smbios.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/smbios/smbios.c +0
-0
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().