Skip to contentSkip to conversation

tools/libxl: Fix leaking ssid_label in libxl_name_to_domid

PATCH In review Tamas K Lengyel 2 participants 4 messages Jan 27, 2019 – Jan 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/libxl: Fix leaking ssid_label in libxl_name_to_domid

On systems with XSM enabled libxl_name_to_domid leaks memory allocated for ssid_label:

==2693== 53 bytes in 2 blocks are definitely lost in loss record 4 of 8

==2693==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==2693==    by 0x6C0A3B9: strdup (strdup.c:42)
==2693==    by 0x5108294: libxl_flask_sid_to_context (libxl_flask.c:39)
==2693==    by 0x50C2B64: libxl__xcinfo2xlinfo (libxl_domain.c:267)
==2693==    by 0x50C2E02: libxl_list_domain (libxl_domain.c:308)
==2693==    by 0x508A3C5: libxl_name_to_domid (libxl_utils.c:77)
---
 tools/libxl/libxl_utils.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_utils.c +2 -0
index e50e094c48..99abfa5497 100644
@@ -79,6 +79,8 @@ int libxl_name_to_domid(libxl_ctx *ctx, const char *name,
         return ERROR_NOMEM;
 
     for (i = 0; i < nb_domains; i++) {
+        if (dominfo[i].ssid_label)
+            free(dominfo[i].ssid_label);
         domname = libxl_domid_to_name(ctx, dominfo[i].domid);
         if (!domname)
             continue;
Signature · 7 lines
2.20.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw
Quoted 23 lines · Tamas K Lengyel

On systems with XSM enabled libxl_name_to_domid leaks memory allocated for ssid_label:

==2693== 53 bytes in 2 blocks are definitely lost in loss record 4 of 8

==2693==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==2693==    by 0x6C0A3B9: strdup (strdup.c:42)
==2693==    by 0x5108294: libxl_flask_sid_to_context (libxl_flask.c:39)
==2693==    by 0x50C2B64: libxl__xcinfo2xlinfo (libxl_domain.c:267)
==2693==    by 0x50C2E02: libxl_list_domain (libxl_domain.c:308)
==2693==    by 0x508A3C5: libxl_name_to_domid (libxl_utils.c:77)
---
 tools/libxl/libxl_utils.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_utils.c +0 -0
index e50e094c48..99abfa5497 100644

tools/libxl/libxl_utils.c int libxl_name_to_domid(libxl_ctx *ctx, const char *name, · line 86

Quoted 8 lines
tools/libxl/libxl_utils.c +2 -0
@@ -79,6 +79,8 @@ int libxl_name_to_domid(libxl_ctx *ctx, const char *name,
         return ERROR_NOMEM;
 
     for (i = 0; i < nb_domains; i++) {
+        if (dominfo[i].ssid_label)
+            free(dominfo[i].ssid_label);
         domname = libxl_domid_to_name(ctx, dominfo[i].domid);
         if (!domname)
             continue;

Thanks for reporting this issue. I think your patch isn't future-proof.

Can you try the following patch?

---8<---
From fc9f9ad912cb61085a5bfb60aef3643dcd82a496 Mon Sep 17 00:00:00 2001
From: Wei Liu <[email protected]>
Date: Mon, 28 Jan 2019 12:10:12 +0000
Subject: [PATCH] libxl: correctly dispose of dominfo list in
libxl_name_to_domid

Tamas reported ssid_label was leaked. Use the designated function to free dominfo list to fix the leakage.

---
 tools/libxl/libxl_utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_utils.c +1 -1
index e50e094c48..f360f5e228 100644
@@ -90,7 +90,7 @@ int libxl_name_to_domid(libxl_ctx *ctx, const char *name,
         }
         free(domname);
     }
-    free(dominfo);
+    libxl_dominfo_list_free(dominfo, nb_domains);
     return ret;
 }
 
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw
Quoted 36 lines · Wei Liu
Quoted 23 lines · Tamas K Lengyel

On systems with XSM enabled libxl_name_to_domid leaks memory allocated for ssid_label:

==2693== 53 bytes in 2 blocks are definitely lost in loss record 4 of 8

==2693==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==2693==    by 0x6C0A3B9: strdup (strdup.c:42)
==2693==    by 0x5108294: libxl_flask_sid_to_context (libxl_flask.c:39)
==2693==    by 0x50C2B64: libxl__xcinfo2xlinfo (libxl_domain.c:267)
==2693==    by 0x50C2E02: libxl_list_domain (libxl_domain.c:308)
==2693==    by 0x508A3C5: libxl_name_to_domid (libxl_utils.c:77)
---
 tools/libxl/libxl_utils.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_utils.c +0 -0
index e50e094c48..99abfa5497 100644

tools/libxl/libxl_utils.c int libxl_name_to_domid(libxl_ctx *ctx, const char *name, · line 86

Quoted 8 lines
tools/libxl/libxl_utils.c +2 -0
@@ -79,6 +79,8 @@ int libxl_name_to_domid(libxl_ctx *ctx, const char *name,
         return ERROR_NOMEM;
 
     for (i = 0; i < nb_domains; i++) {
+        if (dominfo[i].ssid_label)
+            free(dominfo[i].ssid_label);
         domname = libxl_domid_to_name(ctx, dominfo[i].domid);
         if (!domname)
             continue;

Thanks for reporting this issue. I think your patch isn't future-proof.

Quoted 1 line

Can you try the following patch?

Works too.

Thanks,
Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 37 lines · Tamas K Lengyel
Quoted 36 lines · Wei Liu
Quoted 23 lines · Tamas K Lengyel

On systems with XSM enabled libxl_name_to_domid leaks memory allocated for ssid_label:

==2693== 53 bytes in 2 blocks are definitely lost in loss record 4 of 8

==2693==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
==2693==    by 0x6C0A3B9: strdup (strdup.c:42)
==2693==    by 0x5108294: libxl_flask_sid_to_context (libxl_flask.c:39)
==2693==    by 0x50C2B64: libxl__xcinfo2xlinfo (libxl_domain.c:267)
==2693==    by 0x50C2E02: libxl_list_domain (libxl_domain.c:308)
==2693==    by 0x508A3C5: libxl_name_to_domid (libxl_utils.c:77)
---
 tools/libxl/libxl_utils.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_utils.c +0 -0
index e50e094c48..99abfa5497 100644

tools/libxl/libxl_utils.c int libxl_name_to_domid(libxl_ctx *ctx, const char *name, · line 86

Quoted 8 lines
tools/libxl/libxl_utils.c +2 -0
@@ -79,6 +79,8 @@ int libxl_name_to_domid(libxl_ctx *ctx, const char *name,
         return ERROR_NOMEM;
 
     for (i = 0; i < nb_domains; i++) {
+        if (dominfo[i].ssid_label)
+            free(dominfo[i].ssid_label);
         domname = libxl_domid_to_name(ctx, dominfo[i].domid);
         if (!domname)
             continue;

Thanks for reporting this issue. I think your patch isn't future-proof.

Quoted 3 lines
Quoted 1 line

Can you try the following patch?

Works too.

Thank you. I will add you reported-by and tested-by and submit this patch properly.

Wei.

Quoted 3 lines

Thanks,
Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel