Skip to contentSkip to conversation

vhost: check for vhost_ops before using.

PATCH In review Ilya Maximets 2 participants 3 messages Aug 3, 2016 – Aug 9, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: check for vhost_ops before using.

'vhost_set_vring_enable()' tries to call function using pointer to 'vhost_ops' which can be already zeroized in 'vhost_dev_cleanup()' while vhost disconnection.

Fix that by checking 'vhost_ops' before using. This fixes QEMU crash on calling 'ethtool -L eth0 combined 2' if vhost disconnected.

---
 hw/net/vhost_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/vhost_net.c +1 -1
index dc61dc1..f2d49ad 100644
@@ -428,7 +428,7 @@ int vhost_set_vring_enable(NetClientState *nc, int enable)
 
     nc->vring_enable = enable;
 
-    if (vhost_ops->vhost_set_vring_enable) {
+    if (vhost_ops && vhost_ops->vhost_set_vring_enable) {
         return vhost_ops->vhost_set_vring_enable(&net->dev, enable);
     }
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw

Hi

Quoted 18 lines · Ilya Maximets

'vhost_set_vring_enable()' tries to call function using pointer to 'vhost_ops' which can be already zeroized in 'vhost_dev_cleanup()' while vhost disconnection.

Fix that by checking 'vhost_ops' before using. This fixes QEMU crash on calling 'ethtool -L eth0 combined 2' if vhost disconnected.

---
 hw/net/vhost_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/vhost_net.c +0 -0
index dc61dc1..f2d49ad 100644

hw/net/vhost_net.c int vhost_set_vring_enable(NetClientState *nc, int · line 434

Quoted 8 lines
hw/net/vhost_net.c +1 -1
@@ -428,7 +428,7 @@ int vhost_set_vring_enable(NetClientState *nc, int
 enable)
 
     nc->vring_enable = enable;
 
-    if (vhost_ops->vhost_set_vring_enable) {
+    if (vhost_ops && vhost_ops->vhost_set_vring_enable) {
         return vhost_ops->vhost_set_vring_enable(&net->dev, enable);
     }

would be nice for 2.7,

Quoted 6 lines

--
2.7.4

--

Marc-André Lureau

#2 lore raw

Hi

Quoted 26 lines · Marc-André Lureau

Hi

Quoted 21 lines · Ilya Maximets

'vhost_set_vring_enable()' tries to call function using pointer to 'vhost_ops' which can be already zeroized in 'vhost_dev_cleanup()' while vhost disconnection.

Fix that by checking 'vhost_ops' before using. This fixes QEMU crash on calling 'ethtool -L eth0 combined 2' if vhost disconnected.

---
 hw/net/vhost_net.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/net/vhost_net.c +0 -0
index dc61dc1..f2d49ad 100644
@@ -428,7 +428,7 @@ int vhost_set_vring_enable(NetClientState *nc, int
 enable)
 
     nc->vring_enable = enable;
 
Quoted 8 lines

hw/net/vhost_net.c int vhost_set_vring_enable(NetClientState *nc, int enable) · line 433

Quoted 5 lines
hw/net/vhost_net.c +1 -1
-    if (vhost_ops->vhost_set_vring_enable) {
+    if (vhost_ops && vhost_ops->vhost_set_vring_enable) {
         return vhost_ops->vhost_set_vring_enable(&net->dev, enable);
     }

would be nice for 2.7,

Michael, could you pick the fix for 2.7? thanks

Quoted 11 lines
Quoted 6 lines

--
2.7.4

--

Marc-André Lureau

Signature · 1 line
Marc-André Lureau