git: d67c363e85e7 - main - bhyve: check paddr_guest2host return in _vq_record

From: Bojan Novković <bnovkov_at_FreeBSD.org>
Date: Wed, 04 Nov 2026 16:53:54 UTC
The branch main has been updated by bnovkov:

URL: https://cgit.FreeBSD.org/src/commit/?id=d67c363e85e7c720b1e0ac16e30cb64317c0dc2f

commit d67c363e85e7c720b1e0ac16e30cb64317c0dc2f
Author:     Osvaldo Janeri Filho <ojaneri@amd.com>
AuthorDate: 2026-11-04 16:11:02 +0000
Commit:     Bojan Novković <bnovkov@FreeBSD.org>
CommitDate: 2026-11-04 16:53:03 +0000

    bhyve: check paddr_guest2host return in _vq_record
    
    _vq_record() stored the result of paddr_guest2host() without checking for
    NULL. A guest descriptor with an invalid address causes a NULL dereference
    in every virtio driver. Return early on failure; the caller sees zero
    descriptors and discards the chain.
    
    The indirect path already performs this check (line 357).
    
    Reviewed by:    bnovkov
    Differential Revision:  https://reviews.freebsd.org/D60870
    MFC after:      1 week
---
 usr.sbin/bhyve/virtio.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/usr.sbin/bhyve/virtio.c b/usr.sbin/bhyve/virtio.c
index c0122238b457..f1b0e41d21df 100644
--- a/usr.sbin/bhyve/virtio.c
+++ b/usr.sbin/bhyve/virtio.c
@@ -48,6 +48,8 @@
 #endif
 #include "virtio.h"
 
+#define WPRINTF(params) PRINTLN params
+
 /*
  * Functions for dealing with generalized "virtual devices" as
  * defined by <https://www.google.com/#output=search&q=virtio+spec>
@@ -230,6 +232,11 @@ _vq_record(int i, struct vring_desc *vd, struct vmctx *ctx, struct iovec *iov,
 	addr = atomic_load_64(&vd->addr);
 	iov[i].iov_len = len;
 	iov[i].iov_base = paddr_guest2host(ctx, addr, len);
+	if (iov[i].iov_base == NULL) {
+		WPRINTF(("%s: invalid guest address 0x%lx len %u\n",
+		    __func__, addr, len));
+		return;
+	}
 	if ((vd->flags & VRING_DESC_F_WRITE) == 0)
 		reqp->readable++;
 	else