Skip to contentSkip to conversation

net/colo-compare.c: Fix a crash in COLO Primary.

PATCH Applied Lukas Straub 4 participants 6 messages Apr 20, 2019 – May 7, 2019 Networking

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net/colo-compare.c: Fix a crash in COLO Primary.

From: Lukas Straub <[email protected]>
Because event_unhandled_count may be accessed concurrently, it needs to be protected by taking the lock. However the assert is outside the lock, probably causing it to read garbage and aborting Qemu erroneously.

The Bug only happens when running Qemu in COLO mode.

This Patch fixes the following bug: https://bugs.launchpad.net/qemu/+bug/1824622

---
 net/colo-compare.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/colo-compare.c +1 -2
index bf10526f05..fcb491121b 100644
@@ -813,9 +813,8 @@ static void colo_compare_handle_event(void *opaque)
         break;
     }
 
-    assert(event_unhandled_count > 0);
-
     qemu_mutex_lock(&event_mtx);
+    assert(event_unhandled_count > 0);
     event_unhandled_count--;
     qemu_cond_broadcast(&event_complete_cond);
     qemu_mutex_unlock(&event_mtx);

--
2.20.1

Reviewed-by on v2 1/1
#1 lore raw
Quoted 30 lines · Lukas Straub

From: Lukas Straub <[email protected]>
Because event_unhandled_count may be accessed concurrently, it needs to be protected by taking the lock. However the assert is outside the lock, probably causing it to read garbage and aborting Qemu erroneously.

The Bug only happens when running Qemu in COLO mode.

This Patch fixes the following bug: https://bugs.launchpad.net/qemu/+bug/1824622

---
 net/colo-compare.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/colo-compare.c +1 -3
index bf10526f05..fcb491121b 100644
@@ -813,9 +813,8 @@ static void colo_compare_handle_event(void *opaque)
         break;
     }
 
-    assert(event_unhandled_count > 0);
-
     qemu_mutex_lock(&event_mtx);
+    assert(event_unhandled_count > 0);
     event_unhandled_count--;
     qemu_cond_broadcast(&event_complete_cond);
     qemu_mutex_unlock(&event_mtx);
--
Quoted 3 lines

2.20.1

Reviewed-by on v2 1/1
#2 lore raw
In reply to Lukas Straub
Quoted 13 lines

-----Original Message-----
From: Lukas Straub [mailto:[email protected]]
Sent: Sunday, April 21, 2019 1:14 AM
To: [email protected]
Cc: Zhang, Chen <[email protected]>
Subject: [PATCH v2] net/colo-compare.c: Fix a crash in COLO Primary.

From: Lukas Straub <[email protected]> Because event_unhandled_count may be accessed concurrently, it needs to be protected by taking the lock. However the assert is outside the lock, probably causing it to read garbage and aborting Qemu erroneously.

Quoted 6 lines

The Bug only happens when running Qemu in COLO mode.

This Patch fixes the following bug:
https://bugs.launchpad.net/qemu/+bug/1824622

Looks good for me.

Thanks
Zhang Chen

Quoted 21 lines
---
 net/colo-compare.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/colo-compare.c index renamed from net/colo-compare.c +0 -0

bf10526f05..fcb491121b 100644

net/colo-compare.c +1 -3
@@ -813,9 +813,8 @@ static void colo_compare_handle_event(void *opaque)
         break;
     }
 
-    assert(event_unhandled_count > 0);
-
     qemu_mutex_lock(&event_mtx);
+    assert(event_unhandled_count > 0);
     event_unhandled_count--;
     qemu_cond_broadcast(&event_complete_cond);
     qemu_mutex_unlock(&event_mtx);
--

2.20.1

#3 lore raw
In reply to Lukas Straub
Quoted 21 lines · On Sat, 20 Apr 2019 19:14:25 +0200 Lukas Straub <[email protected]> wrote:

From: Lukas Straub <[email protected]>
Because event_unhandled_count may be accessed concurrently, it needs to be protected by taking the lock. However the assert is outside the lock, probably causing it to read garbage and aborting Qemu erroneously.

The Bug only happens when running Qemu in COLO mode.

This Patch fixes the following bug:
https://bugs.launchpad.net/qemu/+bug/1824622

---
 net/colo-compare.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/colo-compare.c +0 -0
index bf10526f05..fcb491121b 100644

net/colo-compare.c static void colo_compare_handle_event(void · line 820

Quoted 10 lines
net/colo-compare.c +1 -2
@@ -813,9 +813,8 @@ static void colo_compare_handle_event(void
 *opaque) break;
     }
 
-    assert(event_unhandled_count > 0);
-
     qemu_mutex_lock(&event_mtx);
+    assert(event_unhandled_count > 0);
     event_unhandled_count--;
     qemu_cond_broadcast(&event_complete_cond);
     qemu_mutex_unlock(&event_mtx);

Ping.

Regards,
Lukas Straub

#5 lore raw
In reply to Lukas Straub

Cc'ing Paolo & Stefan

Quoted 33 lines · Lukas Straub

From: Lukas Straub <[email protected]>
Because event_unhandled_count may be accessed concurrently, it needs to be protected by taking the lock. However the assert is outside the lock, probably causing it to read garbage and aborting Qemu erroneously.

The Bug only happens when running Qemu in COLO mode.

This Patch fixes the following bug: https://bugs.launchpad.net/qemu/+bug/1824622

---
 net/colo-compare.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/colo-compare.c +1 -3
index bf10526f05..fcb491121b 100644
@@ -813,9 +813,8 @@ static void colo_compare_handle_event(void *opaque)
         break;
     }
 
-    assert(event_unhandled_count > 0);
-
     qemu_mutex_lock(&event_mtx);
+    assert(event_unhandled_count > 0);
     event_unhandled_count--;
     qemu_cond_broadcast(&event_complete_cond);
     qemu_mutex_unlock(&event_mtx);
--

2.20.1

Applied
#4 lore raw
In reply to Lukas Straub
Quoted 36 lines · Lukas Straub
Quoted 21 lines · On Sat, 20 Apr 2019 19:14:25 +0200 Lukas Straub <[email protected]> wrote:

From: Lukas Straub <[email protected]>
Because event_unhandled_count may be accessed concurrently, it needs to be protected by taking the lock. However the assert is outside the lock, probably causing it to read garbage and aborting Qemu erroneously.

The Bug only happens when running Qemu in COLO mode.

This Patch fixes the following bug:
https://bugs.launchpad.net/qemu/+bug/1824622

---
  net/colo-compare.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
net/colo-compare.c +0 -0
index bf10526f05..fcb491121b 100644

net/colo-compare.c static void colo_compare_handle_event(void · line 820

Quoted 10 lines
net/colo-compare.c +1 -2
@@ -813,9 +813,8 @@ static void colo_compare_handle_event(void
 *opaque) break;
      }
 
-    assert(event_unhandled_count > 0);
-
      qemu_mutex_lock(&event_mtx);
+    assert(event_unhandled_count > 0);
      event_unhandled_count--;
      qemu_cond_broadcast(&event_complete_cond);
      qemu_mutex_unlock(&event_mtx);

Ping.

Quoted 2 lines

Regards,
Lukas Straub

Applied.

Thanks

Quoted 1 line