Skip to contentSkip to conversation

migration/rdma: fix nullptr-def in rdma_start_incoming_migration

PATCH In review Pan Nengyuan 4 participants 8 messages May 8, 2020 – May 29, 2020

lore
Share & tools
lore
#0 lore raw

cover migration/rdma: fix nullptr-def in rdma_start_incoming_migration

I fix a memleak in rdma_start_incoming_migration some time ago.
https://patchwork.kernel.org/patch/11498191/

I'm sorry that it may cause a null-pointer access, this patch fix that.

Since we are here, rdma_start_outgoing_migration has the similar memleak, fix it together.

Pan Nengyuan (2):
migration/rdma: fix potential nullptr access in
rdma_start_incoming_migration
migration/rdma: cleanup rdma context before g_free to avoid memleaks

 migration/rdma.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
Signature · 1 line
2.18.2
#1 lore raw

PATCH 1/2 migration/rdma: fix potential nullptr access in rdma_start_incoming_migration

'rdma' is NULL when taking the first error branch in rdma_start_incoming_migration. And it will cause a null pointer access in label 'err'. Fix that.

Fixes 59c59c67ee6b0327ae932deb303caa47919aeb1e
---
 migration/rdma.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
migration/rdma.c +3 -1
index 967fda5b0c..72e8b1c95b 100644
@@ -4056,7 +4056,9 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp)
     return;
 err:
     error_propagate(errp, local_err);
-    g_free(rdma->host);
+    if (rdma) {
+        g_free(rdma->host);
+    }
     g_free(rdma);
     g_free(rdma_return_path);
 }
Signature · 1 line
2.18.2
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] migration/rdma: fix potential nullptr access in rdma_start_incoming_migration

Quoted 5 lines · Pan Nengyuan

'rdma' is NULL when taking the first error branch in rdma_start_incoming_migration. And it will cause a null pointer access in label 'err'. Fix that.

Fixes 59c59c67ee6b0327ae932deb303caa47919aeb1e

good catch.

#3 lore raw

Re: [PATCH 1/2] migration/rdma: fix potential nullptr access in rdma_start_incoming_migration

Quoted 9 lines · Juan Quintela
Quoted 5 lines · Pan Nengyuan

'rdma' is NULL when taking the first error branch in rdma_start_incoming_migration. And it will cause a null pointer access in label 'err'. Fix that.

Fixes 59c59c67ee6b0327ae932deb303caa47919aeb1e

NB: this is CID 1428762.

thanks
-- PMM

#4 lore raw

Re: [PATCH 1/2] migration/rdma: fix potential nullptr access in rdma_start_incoming_migration

In reply to Juan Quintela
Quoted 10 lines · * Juan Quintela ([email protected]) wrote:
Quoted 5 lines · Pan Nengyuan

'rdma' is NULL when taking the first error branch in rdma_start_incoming_migration. And it will cause a null pointer access in label 'err'. Fix that.

Fixes 59c59c67ee6b0327ae932deb303caa47919aeb1e

good catch.

Thanks, Queued

Quoted 1 line

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK

#5 lore raw

PATCH 2/2 migration/rdma: cleanup rdma context before g_free to avoid memleaks

In reply to Pan Nengyuan

When error happen in initializing 'rdma_return_path', we should cleanup rdma context before g_free(rdma) to avoid some memleaks. This patch fix that.

---
 migration/rdma.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
migration/rdma.c +5 -3
index 72e8b1c95b..ec45d33ba3 100644
@@ -4094,20 +4094,20 @@ void rdma_start_outgoing_migration(void *opaque,
         rdma_return_path = qemu_rdma_data_init(host_port, errp);
 
         if (rdma_return_path == NULL) {
-            goto err;
+            goto return_path_err;
         }
 
         ret = qemu_rdma_source_init(rdma_return_path,
             s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL], errp);
 
         if (ret) {
-            goto err;
+            goto return_path_err;
         }
 
         ret = qemu_rdma_connect(rdma_return_path, errp);
 
         if (ret) {
-            goto err;
+            goto return_path_err;
         }
 
         rdma->return_path = rdma_return_path;
@@ -4120,6 +4120,8 @@ void rdma_start_outgoing_migration(void *opaque,
     s->to_dst_file = qemu_fopen_rdma(rdma, "wb");
     migrate_fd_connect(s, NULL);
     return;
+return_path_err:
+    qemu_rdma_cleanup(rdma);
 err:
     g_free(rdma);
     g_free(rdma_return_path);
Signature · 1 line
2.18.2
#7 lore raw

Re: [PATCH 2/2] migration/rdma: cleanup rdma context before g_free to avoid memleaks

In reply to Pan Nengyuan
Quoted 5 lines · * Pan Nengyuan ([email protected]) wrote:

When error happen in initializing 'rdma_return_path', we should cleanup rdma context before g_free(rdma) to avoid some memleaks. This patch fix that.

Queued.

Quoted 44 lines
---
 migration/rdma.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
migration/rdma.c +5 -3
index 72e8b1c95b..ec45d33ba3 100644
@@ -4094,20 +4094,20 @@ void rdma_start_outgoing_migration(void *opaque,
         rdma_return_path = qemu_rdma_data_init(host_port, errp);
 
         if (rdma_return_path == NULL) {
-            goto err;
+            goto return_path_err;
         }
 
         ret = qemu_rdma_source_init(rdma_return_path,
             s->enabled_capabilities[MIGRATION_CAPABILITY_RDMA_PIN_ALL], errp);
 
         if (ret) {
-            goto err;
+            goto return_path_err;
         }
 
         ret = qemu_rdma_connect(rdma_return_path, errp);
 
         if (ret) {
-            goto err;
+            goto return_path_err;
         }
 
         rdma->return_path = rdma_return_path;
@@ -4120,6 +4120,8 @@ void rdma_start_outgoing_migration(void *opaque,
     s->to_dst_file = qemu_fopen_rdma(rdma, "wb");
     migrate_fd_connect(s, NULL);
     return;
+return_path_err:
+    qemu_rdma_cleanup(rdma);
 err:
     g_free(rdma);
     g_free(rdma_return_path);
Signature · 1 line
2.18.2

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK