Skip to contentSkip to conversation

hw/virtio/virtio-pci: add defensive check for vector_irqfd

PATCH In review [email protected] 3 participants 3 messages Aug 14, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/virtio/virtio-pci: add defensive check for vector_irqfd

From: Denis Rastyogin <[email protected]>

Add a NULL check for proxy->vector_irqfd in virtio_pci_one_vector_unmask() before taking the irqfd path. This prevents potential access to uninitialized state if vector_irqfd is absent.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
 hw/virtio/virtio-pci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +5 -1
index 767216d795..07904f6f9b 100644
@@ -1015,7 +1015,11 @@ static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy,
             event_notifier_set(n);
         }
     } else {
-        ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
+        if (proxy->vector_irqfd) {
+            ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
+        } else {
+            ret = -EFAULT;
+        }
     }
     return ret;
 }
Signature · 1 line
2.42.2
#1 lore raw

Hi Denis,

Quoted 20 lines · On 14/8/25 13:08, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

Add a NULL check for proxy->vector_irqfd in virtio_pci_one_vector_unmask() before taking the irqfd path. This prevents potential access to uninitialized state if vector_irqfd is absent.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

---
  hw/virtio/virtio-pci.c | 6 +++++-
  1 file changed, 5 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +0 -0
index 767216d795..07904f6f9b 100644

hw/virtio/virtio-pci.c static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy, · line 1018

Quoted 5 lines
hw/virtio/virtio-pci.c +1 -1
@@ -1015,7 +1015,11 @@ static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy,
              event_notifier_set(n);
          }
      } else {
-        ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
+        if (proxy->vector_irqfd) {

Why check the callers and not once in the callee?

Quoted 7 lines
hw/virtio/virtio-pci.c +4 -0
+            ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
+        } else {
+            ret = -EFAULT;
+        }
      }
      return ret;
  }
#2 lore raw
In reply to [email protected]
Quoted 11 lines · On Thu, Aug 14, 2025 at 02:08:08PM +0300, [email protected] wrote:

From: Denis Rastyogin <[email protected]>

Add a NULL check for proxy->vector_irqfd in virtio_pci_one_vector_unmask() before taking the irqfd path. This prevents potential access to uninitialized state if vector_irqfd is absent.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

I don't really understand what this description means. defensive against what? found in what sense? what is the uninitialized state accessed? when is the potential for this access?

Quoted 23 lines
---
 hw/virtio/virtio-pci.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
hw/virtio/virtio-pci.c +5 -1
index 767216d795..07904f6f9b 100644
@@ -1015,7 +1015,11 @@ static int virtio_pci_one_vector_unmask(VirtIOPCIProxy *proxy,
             event_notifier_set(n);
         }
     } else {
-        ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
+        if (proxy->vector_irqfd) {
+            ret = kvm_virtio_pci_irqfd_use(proxy, n, vector);
+        } else {
+            ret = -EFAULT;
+        }
     }
     return ret;
 }
Signature · 1 line
2.42.2