Blame SOURCES/0020-iscsi_reconnect-Fix-a-use-after-free.patch

a66d21
iscsi_reconnect: Fix a use-after-free
a66d21
a66d21
Message-id: <1383729402-27559-2-git-send-email-pbonzini@redhat.com>
a66d21
Patchwork-id: 55496
a66d21
O-Subject: [PATCH 01/11] iscsi_reconnect: Fix a use-after-free
a66d21
Bugzilla: 1026820
a66d21
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
a66d21
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
a66d21
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
a66d21
a66d21
From: Bart Van Assche <bvanassche@acm.org>
a66d21
a66d21
This patch fixes the following Valgrind complaint:
a66d21
a66d21
Invalid read of size 4
a66d21
   at 0x524A858: iscsi_reconnect (connect.c:378)
a66d21
   by 0x5258794: iscsi_service (socket.c:707)
a66d21
   by 0x52599C4: event_loop (sync.c:67)
a66d21
   by 0x525AFD7: iscsi_reserve6_sync (sync.c:1096)
a66d21
   by 0x40A40A: reserve6 (iscsi-support.c:3291)
a66d21
   by 0x422C95: test_reserve6_target_warm_reset (test_reserve6_target_warm_reset.c:39)
a66d21
   by 0x503B05F: ??? (in /usr/lib/libcunit.so.1.0.1)
a66d21
   by 0x503B375: ??? (in /usr/lib/libcunit.so.1.0.1)
a66d21
   by 0x503B69F: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
a66d21
   by 0x403171: main (iscsi-test-cu.c:1258)
a66d21
 Address 0x6443958 is 3,032 bytes inside a block of size 4,120 free'd
a66d21
   at 0x4C2B83A: free (vg_replace_malloc.c:468)
a66d21
   by 0x524A846: iscsi_reconnect (connect.c:374)
a66d21
   by 0x5258794: iscsi_service (socket.c:707)
a66d21
   by 0x52599C4: event_loop (sync.c:67)
a66d21
   by 0x525AFD7: iscsi_reserve6_sync (sync.c:1096)
a66d21
   by 0x40A40A: reserve6 (iscsi-support.c:3291)
a66d21
   by 0x422C95: test_reserve6_target_warm_reset (test_reserve6_target_warm_reset.c:39)
a66d21
   by 0x503B05F: ??? (in /usr/lib/libcunit.so.1.0.1)
a66d21
   by 0x503B375: ??? (in /usr/lib/libcunit.so.1.0.1)
a66d21
   by 0x503B69F: CU_run_all_tests (in /usr/lib/libcunit.so.1.0.1)
a66d21
   by 0x403171: main (iscsi-test-cu.c:1258)
a66d21
a66d21
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
a66d21
(cherry picked from commit 4653cd8df4c14f4eea37b6ce66277330774dd3d5)
a66d21
---
a66d21
 lib/connect.c | 4 ++--
a66d21
 1 file changed, 2 insertions(+), 2 deletions(-)
a66d21
diff --git a/lib/connect.c b/lib/connect.c
a66d21
index bcb9d3b..0d4c957 100644
a66d21
--- a/lib/connect.c
a66d21
+++ b/lib/connect.c
a66d21
@@ -356,13 +356,13 @@ try_again:
a66d21
 	iscsi->mallocs+=old_iscsi->mallocs;
a66d21
 	iscsi->frees+=old_iscsi->frees;
a66d21
 
a66d21
+	ISCSI_LOG(iscsi, 2, "reconnect was successful");
a66d21
+
a66d21
 	memcpy(old_iscsi, iscsi, sizeof(struct iscsi_context));
a66d21
-	memset(iscsi, 0, sizeof(struct iscsi_context));
a66d21
 	free(iscsi);
a66d21
 
a66d21
 	old_iscsi->is_reconnecting = 0;
a66d21
 	old_iscsi->last_reconnect = time(NULL);
a66d21
-	ISCSI_LOG(iscsi, 2, "reconnect was successful");
a66d21
 
a66d21
 	return 0;
a66d21
 }