qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] smbios: sanitize type from external type before checking have_fields_bitmap
@ 2022-09-05 10:36 Paolo Bonzini
  2022-09-05 14:32 ` Philippe Mathieu-Daudé via
  0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2022-09-05 10:36 UTC (permalink / raw)
  To: qemu-devel

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.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 hw/smbios/smbios.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
index 60349ee402..485fa15202 100644
--- a/hw/smbios/smbios.c
+++ b/hw/smbios/smbios.c
@@ -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);
-- 
2.37.2



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] smbios: sanitize type from external type before checking have_fields_bitmap
  2022-09-05 10:36 [PATCH] smbios: sanitize type from external type before checking have_fields_bitmap Paolo Bonzini
@ 2022-09-05 14:32 ` Philippe Mathieu-Daudé via
  0 siblings, 0 replies; 2+ messages in thread
From: Philippe Mathieu-Daudé via @ 2022-09-05 14:32 UTC (permalink / raw)
  To: Paolo Bonzini, qemu-devel

On 5/9/22 12:36, Paolo Bonzini wrote:
> 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.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   hw/smbios/smbios.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/smbios/smbios.c b/hw/smbios/smbios.c
> index 60349ee402..485fa15202 100644
> --- a/hw/smbios/smbios.c
> +++ b/hw/smbios/smbios.c
> @@ -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().


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-09-05 14:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-05 10:36 [PATCH] smbios: sanitize type from external type before checking have_fields_bitmap Paolo Bonzini
2022-09-05 14:32 ` Philippe Mathieu-Daudé via

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).