Skip to contentSkip to conversation

virtio/vhost-user: Fix wrong vhost notifier GPtrArray size

PATCH In review Yajun Wu 3 participants 4 messages May 26, 2022 – Jun 15, 2022

lore
Share & tools
lore

Yajun Wu

author
#0 lore raw

PATCH 1/1 virtio/vhost-user: Fix wrong vhost notifier GPtrArray size

In fetch_or_create_notifier, idx begins with 0. So the GPtrArray size should be idx + 1 and g_ptr_array_set_size should be called with idx + 1.

This wrong GPtrArray size causes fetch_or_create_notifier return an invalid address. Passing this invalid pointer to vhost_user_host_notifier_remove causes assert fail:

qemu/include/qemu/int128.h:27: int128_get64: Assertion `r == a' failed.
shutting down, reason=crashed

Backends like dpdk-vdpa which sends out vhost notifier requests almost always hit qemu crash.

Fixes 503e355465 ("virtio/vhost-user: dynamically assign VhostUserHostNotifiers")
Change-Id I87e0f7591ca9a59d210879b260704a2d9e9d6bcd
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c +1 -1
index b040c1ad2b..dbc690d16c 100644
@@ -1525,7 +1525,7 @@ static VhostUserHostNotifier *fetch_or_create_notifier(VhostUserState *u,
 {
     VhostUserHostNotifier *n = NULL;
     if (idx >= u->notifiers->len) {
-        g_ptr_array_set_size(u->notifiers, idx);
+        g_ptr_array_set_size(u->notifiers, idx + 1);
     }
 
     n = g_ptr_array_index(u->notifiers, idx);
Signature · 1 line
2.36.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yajun Wu

In fetch_or_create_notifier, idx begins with 0. So the GPtrArray size should be idx + 1 and g_ptr_array_set_size should be called with idx + 1.

This wrong GPtrArray size causes fetch_or_create_notifier return an invalid address. Passing this invalid pointer to vhost_user_host_notifier_remove causes assert fail:

Quoted 5 lines

qemu/include/qemu/int128.h:27: int128_get64: Assertion `r == a' failed.
shutting down, reason=crashed

Backends like dpdk-vdpa which sends out vhost notifier requests almost always hit qemu crash.

My bad. I was looking for ways to exercise this code but the internal tests didn't do it. I guess I should look at getting a test setup for dpdk. Anyway:

Quoted 22 lines
Fixes 503e355465 ("virtio/vhost-user: dynamically assign VhostUserHostNotifiers")
Change-Id I87e0f7591ca9a59d210879b260704a2d9e9d6bcd
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c +1 -1
index b040c1ad2b..dbc690d16c 100644
@@ -1525,7 +1525,7 @@ static VhostUserHostNotifier *fetch_or_create_notifier(VhostUserState *u,
 {
     VhostUserHostNotifier *n = NULL;
     if (idx >= u->notifiers->len) {
-        g_ptr_array_set_size(u->notifiers, idx);
+        g_ptr_array_set_size(u->notifiers, idx + 1);
     }
 
     n = g_ptr_array_index(u->notifiers, idx);
Signature · 1 line
Alex Bennée
author Reviewed-by Alex Bennée
#2 lore raw

Hi Michael,

User space vhost clients are broken for few weeks now without this fix. With Alex's review, can you please merge it if there are no further comments?

Thanks.

-----Original Message-----
From: Alex Bennée <[email protected]>
Sent: Thursday, May 26, 2022 3:09 PM
To: Yajun Wu <[email protected]>
Cc: [email protected]; [email protected]; Parav Pandit <[email protected]>
Subject: Re: [PATCH] virtio/vhost-user: Fix wrong vhost notifier GPtrArray size

External email: Use caution opening links or attachments

Quoted 7 lines · Yajun Wu

In fetch_or_create_notifier, idx begins with 0. So the GPtrArray size should be idx + 1 and g_ptr_array_set_size should be called with idx + 1.

This wrong GPtrArray size causes fetch_or_create_notifier return an invalid address. Passing this invalid pointer to vhost_user_host_notifier_remove causes assert fail:

Quoted 5 lines

qemu/include/qemu/int128.h:27: int128_get64: Assertion `r == a' failed.
shutting down, reason=crashed

Backends like dpdk-vdpa which sends out vhost notifier requests almost always hit qemu crash.

My bad. I was looking for ways to exercise this code but the internal tests didn't do it. I guess I should look at getting a test setup for dpdk. Anyway:

Quoted 15 lines
Fixes 503e355465 ("virtio/vhost-user: dynamically assign

VhostUserHostNotifiers")

Change-Id I87e0f7591ca9a59d210879b260704a2d9e9d6bcd
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c index renamed from hw/virtio/vhost-user.c +0 -0

b040c1ad2b..dbc690d16c 100644

hw/virtio/vhost-user.c static VhostUserHostNotifier · line 1531

Quoted 8 lines
hw/virtio/vhost-user.c +1 -1
@@ -1525,7 +1525,7 @@ static VhostUserHostNotifier 
 *fetch_or_create_notifier(VhostUserState *u,  {
     VhostUserHostNotifier *n = NULL;
     if (idx >= u->notifiers->len) {
-        g_ptr_array_set_size(u->notifiers, idx);
+        g_ptr_array_set_size(u->notifiers, idx + 1);
     }
 
     n = g_ptr_array_index(u->notifiers, idx);

--
Alex Bennée

Reviewed-by on v1 1/1
#3 lore raw
In reply to Yajun Wu
Quoted 47 lines

-----Original Message-----
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Yajun Wu
Sent: Wednesday, May 25, 2022 8:49 PM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: Parav Pandit <[email protected]>
Subject: [PATCH] virtio/vhost-user: Fix wrong vhost notifier GPtrArray size

In fetch_or_create_notifier, idx begins with 0. So the GPtrArray size should be idx + 1 and g_ptr_array_set_size should be called with idx + 1.

This wrong GPtrArray size causes fetch_or_create_notifier return an invalid address. Passing this invalid pointer to vhost_user_host_notifier_remove causes assert fail:

qemu/include/qemu/int128.h:27: int128_get64: Assertion `r == a' failed.
shutting down, reason=crashed

Backends like dpdk-vdpa which sends out vhost notifier requests almost always hit qemu crash.

Fixes 503e355465 ("virtio/vhost-user: dynamically assign

VhostUserHostNotifiers")

Change-Id I87e0f7591ca9a59d210879b260704a2d9e9d6bcd
---
 hw/virtio/vhost-user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/virtio/vhost-user.c index renamed from hw/virtio/vhost-user.c +0 -0

b040c1ad2b..dbc690d16c 100644

hw/virtio/vhost-user.c +1 -2
@@ -1525,7 +1525,7 @@ static VhostUserHostNotifier
 *fetch_or_create_notifier(VhostUserState *u,  {
     VhostUserHostNotifier *n = NULL;
     if (idx >= u->notifiers->len) {
-        g_ptr_array_set_size(u->notifiers, idx);
+        g_ptr_array_set_size(u->notifiers, idx + 1);
     }
 
     n = g_ptr_array_index(u->notifiers, idx);
--

2.36.0