]> xenbits.xensource.com Git - xen.git/commitdiff
tools/libs/light: Fix nic->vlan memory allocation
authorLeigh Brown <leigh@solinno.co.uk>
Thu, 20 Jun 2024 10:09:02 +0000 (12:09 +0200)
committerJan Beulich <jbeulich@suse.com>
Thu, 20 Jun 2024 10:09:02 +0000 (12:09 +0200)
After the following commit:
3bc14e4fa4b9 ("tools/libs/light: Add vlan field to libxl_device_nic")
xl list -l aborts with a double free error if a domain has at least
one vif defined:

  $ sudo xl list -l
  free(): double free detected in tcache 2
  Aborted

Orginally, the vlan field was called vid and was defined as an integer.
It was appropriate to call libxl__xs_read_checked() with gc passed as
the string data was copied to a different variable.  However, the final
version uses a string data type and the call should have been changed
to use NOGC instead of gc to allow that data to live past the gc
controlled lifetime, in line with the other string fields.

This patch makes the change to pass NOGC instead of gc and moves the
new code to be next to the other string fields (fixing a couple of
errant tabs along the way), as recommended by Jason.

Fixes: 3bc14e4fa4b9 ("tools/libs/light: Add vlan field to libxl_device_nic")
Signed-off-by: Leigh Brown <leigh@solinno.co.uk>
Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
Release-acked-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
tools/libs/light/libxl_nic.c

index d861e3726db26081fbb4c66b6a09f6084df87b13..300a96a8b1aa9f52ca450bbfac96b062903ed8cd 100644 (file)
@@ -318,11 +318,6 @@ static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path,
         nic->mtu = LIBXL_DEVICE_NIC_MTU_DEFAULT;
     }
 
-    rc = libxl__xs_read_checked(gc, XBT_NULL,
-                                GCSPRINTF("%s/vlan", libxl_path),
-                               (const char **)(&nic->vlan));
-    if (rc) goto out;
-
     rc = libxl__xs_read_checked(gc, XBT_NULL,
                                 GCSPRINTF("%s/mac", libxl_path), &tmp);
     if (rc) goto out;
@@ -345,6 +340,10 @@ static int libxl__nic_from_xenstore(libxl__gc *gc, const char *libxl_path,
                                 GCSPRINTF("%s/script", libxl_path),
                                 (const char **)(&nic->script));
     if (rc) goto out;
+    rc = libxl__xs_read_checked(NOGC, XBT_NULL,
+                                GCSPRINTF("%s/vlan", libxl_path),
+                                (const char **)(&nic->vlan));
+    if (rc) goto out;
     rc = libxl__xs_read_checked(NOGC, XBT_NULL,
                                 GCSPRINTF("%s/forwarddev", libxl_path),
                                 (const char **)(&nic->coloft_forwarddev));