git: fb12aee5f42c - stable/15 - bhyve: check paddr_guest2host return in _vq_record

From: Bojan Novković <bnovkov_at_FreeBSD.org>
Date: Tue, 17 Nov 2026 16:35:40 UTC
The branch stable/15 has been updated by bnovkov:

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

commit fb12aee5f42c8f598cfe18588fad9a7fd1240b56
Author:     Osvaldo Janeri Filho <ojaneri@amd.com>
AuthorDate: 2026-11-04 16:11:02 +0000
Commit:     Bojan Novković <bnovkov@FreeBSD.org>
CommitDate: 2026-11-17 16:34:48 +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
    
    (cherry picked from commit d67c363e85e7c720b1e0ac16e30cb64317c0dc2f)
---
 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 fa3c5f8e63a7..317c4e6d5eb4 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