Skip to contentSkip to conversation

smbios: Fix buffer overrun when using path= option

PATCH In review Daan De Meyer 6 participants 11 messages Mar 23, 2025 – Apr 8, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 smbios: Fix buffer overrun when using path= option

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
 hw/smbios/smbios.c | 3 +++
 1 file changed, 3 insertions(+)
hw/smbios/smbios.c +3 -0
index 02a09eb9cd..ad4cd6721e 100644
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
             g_byte_array_append(data, (guint8 *)buf, ret);
         }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
         qemu_close(fd);
 
         *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);
Signature · 1 line
2.49.0
#1 lore raw
Quoted 16 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
  hw/smbios/smbios.c | 3 +++
  1 file changed, 3 insertions(+)
hw/smbios/smbios.c +0 -0
index 02a09eb9cd..ad4cd6721e 100644

hw/smbios/smbios.c static int save_opt_one(void *opaque, · line 1293

Quoted 9 lines
hw/smbios/smbios.c +3 -0
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
              g_byte_array_append(data, (guint8 *)buf, ret);
          }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
          qemu_close(fd);
 
          *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);

Please make sure to put the maintainers on CC: (done now, for the next time please see the MAINTAINERS file or use the scripts/get_maintainers.pl script), otherwise your patch might go unnoticed.

Thomas

#2 lore raw
Quoted 12 lines · Thomas Huth
Quoted 11 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
  hw/smbios/smbios.c | 3 +++
  1 file changed, 3 insertions(+)
Quoted 16 lines

hw/smbios/smbios.c static int save_opt_one(void *opaque, · line 1291

Quoted 12 lines
hw/smbios/smbios.c +3 -0
index 02a09eb9cd..ad4cd6721e 100644
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
              g_byte_array_append(data, (guint8 *)buf, ret);
          }
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
          qemu_close(fd);
          *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);

Please make sure to put the maintainers on CC: (done now, for the next time please see the MAINTAINERS file or use the scripts/get_maintainers.pl script), otherwise your patch might go unnoticed.

Michael, Igor, Ani: This patch is needed for QEMU 10.0. You are the maintainers, please review this patch.

Thanks!

Stefan

Reviewed-by on v1 1/1
#3 lore raw
In reply to Daan De Meyer
Quoted 16 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
 hw/smbios/smbios.c | 3 +++
 1 file changed, 3 insertions(+)
hw/smbios/smbios.c +0 -0
index 02a09eb9cd..ad4cd6721e 100644

hw/smbios/smbios.c static int save_opt_one(void *opaque, · line 1293

Quoted 9 lines
hw/smbios/smbios.c +3 -0
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
             g_byte_array_append(data, (guint8 *)buf, ret);
         }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
         qemu_close(fd);
 
         *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#4 lore raw

CC qemu-stable - this needs cherry-picking into all active stable branches once accepted.

Quoted 25 lines · Daniel P. Berrangé
Quoted 24 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
 hw/smbios/smbios.c | 3 +++
 1 file changed, 3 insertions(+)
hw/smbios/smbios.c +3 -0
index 02a09eb9cd..ad4cd6721e 100644
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
             g_byte_array_append(data, (guint8 *)buf, ret);
         }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
         qemu_close(fd);
 
Quoted 12 lines

hw/smbios/smbios.c static int save_opt_one(void *opaque, · line 1293

Quoted 1 line
hw/smbios/smbios.c +0 -0
         *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#5 lore raw
In reply to Daan De Meyer

+Valentin

Quoted 25 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
  hw/smbios/smbios.c | 3 +++
  1 file changed, 3 insertions(+)
hw/smbios/smbios.c +3 -0
index 02a09eb9cd..ad4cd6721e 100644
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
              g_byte_array_append(data, (guint8 *)buf, ret);
          }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
          qemu_close(fd);
 
          *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);
#6 lore raw
In reply to Daan De Meyer

Hi,

Unless I'm missing something, I don't think the patch has been merged yet. Any chance it might have been missed?

Cheers,

Daan

Quoted 29 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
 hw/smbios/smbios.c | 3 +++
 1 file changed, 3 insertions(+)
hw/smbios/smbios.c +3 -1
index 02a09eb9cd..ad4cd6721e 100644
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
             g_byte_array_append(data, (guint8 *)buf, ret);
         }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
         qemu_close(fd);
 
         *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);
--

2.49.0

#7 lore raw

Hi Daan,

Quoted 4 lines · Daan De Meyer

Hi,

Unless I'm missing something, I don't think the patch has been merged yet. Any chance it might have been missed?

I have it tagged, as sensible enough, in case nobody else takes it. IIRC it was sent the same day I posted my latest pull request, so it'd go in the next one, due before next Tuesday. Also I was hoping I could get feedback from Valentin.

Quoted 36 lines

Cheers,

Daan

Quoted 29 lines · Daan De Meyer

We have to make sure the array of bytes read from the path= file is null-terminated, otherwise we run into a buffer overrun later on.

Fixes bb99f4772f54017490e3356ecbb3df25c5d4537f ("hw/smbios: support loading OEM strings values from a file")

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2879

---
  hw/smbios/smbios.c | 3 +++
  1 file changed, 3 insertions(+)
hw/smbios/smbios.c +3 -1
index 02a09eb9cd..ad4cd6721e 100644
@@ -1285,6 +1285,9 @@ static int save_opt_one(void *opaque,
              g_byte_array_append(data, (guint8 *)buf, ret);
          }
 
+        buf[0] = '\0';
+        g_byte_array_append(data, (guint8 *)buf, 1);
+
          qemu_close(fd);
 
          *opt->dest = g_renew(char *, *opt->dest, (*opt->ndest) + 1);
--

2.49.0

#8 lore raw
Quoted 3 lines · Philippe Mathieu-Daudé

Also I was hoping I could get feedback from Valentin.

Sorry, I did not realize that you wanted my feedback. Daan's patch looks fine to me. I have manually tested it and it fixes my issue.

#10 lore raw

Yes.

Quoted 15 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Valentin David

On Thu, Apr 3, 2025 at 9:37 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

Also I was hoping I could get feedback from Valentin.

Sorry, I did not realize that you wanted my feedback. Daan's patch looks fine to me. I have manually tested it and it fixes my issue.

Thanks! Might I add your tag then?