aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGordon Tetlow <gordon@FreeBSD.org>2021-08-24 17:33:35 +0000
committerGordon Tetlow <gordon@FreeBSD.org>2021-08-24 17:33:35 +0000
commitec08bc89d4b3a94ff676e8e9ce6663508f18148b (patch)
tree747150d62185c9dae10a2b3c2a18eeab8b236d8d
parent4f590ee3ed7eb15cb3583f5fa1af75f0f45a475c (diff)
Fix missing error handling in bhyve(8) device models.
Approved by: so Security: SA-21:13.bhyve Security: CVE-2021-29631
-rw-r--r--usr.sbin/bhyve/pci_virtio_9p.c4
-rw-r--r--usr.sbin/bhyve/pci_virtio_console.c7
-rw-r--r--usr.sbin/bhyve/pci_virtio_rnd.c5
-rw-r--r--usr.sbin/bhyve/pci_virtio_scsi.c10
4 files changed, 16 insertions, 10 deletions
diff --git a/usr.sbin/bhyve/pci_virtio_9p.c b/usr.sbin/bhyve/pci_virtio_9p.c
index 7e8542a46e05..7e11fba649b7 100644
--- a/usr.sbin/bhyve/pci_virtio_9p.c
+++ b/usr.sbin/bhyve/pci_virtio_9p.c
@@ -195,13 +195,15 @@ pci_vt9p_notify(void *vsc, struct vqueue_info *vq)
struct iovec iov[VT9P_MAX_IOV];
struct pci_vt9p_softc *sc;
struct pci_vt9p_request *preq;
- uint16_t idx, n, i;
+ int n;
+ uint16_t idx, i;
uint16_t flags[VT9P_MAX_IOV];
sc = vsc;
while (vq_has_descs(vq)) {
n = vq_getchain(vq, &idx, iov, VT9P_MAX_IOV, flags);
+ assert(n >= 1 && n <= VT9P_MAX_IOV);
preq = calloc(1, sizeof(struct pci_vt9p_request));
preq->vsr_sc = sc;
preq->vsr_idx = idx;
diff --git a/usr.sbin/bhyve/pci_virtio_console.c b/usr.sbin/bhyve/pci_virtio_console.c
index 133902ccb129..2f87220a0e4f 100644
--- a/usr.sbin/bhyve/pci_virtio_console.c
+++ b/usr.sbin/bhyve/pci_virtio_console.c
@@ -421,6 +421,7 @@ pci_vtcon_sock_rx(int fd __unused, enum ev_type t __unused, void *arg)
do {
n = vq_getchain(vq, &idx, &iov, 1, NULL);
+ assert(n == 1);
len = readv(sock->vss_conn_fd, &iov, n);
if (len == 0 || (len < 0 && errno == EWOULDBLOCK)) {
@@ -561,7 +562,6 @@ pci_vtcon_control_send(struct pci_vtcon_softc *sc,
return;
n = vq_getchain(vq, &idx, &iov, 1, NULL);
-
assert(n == 1);
memcpy(iov.iov_base, ctrl, sizeof(struct pci_vtcon_control));
@@ -580,7 +580,8 @@ pci_vtcon_notify_tx(void *vsc, struct vqueue_info *vq)
struct pci_vtcon_softc *sc;
struct pci_vtcon_port *port;
struct iovec iov[1];
- uint16_t idx, n;
+ int n;
+ uint16_t idx;
uint16_t flags[8];
sc = vsc;
@@ -588,7 +589,7 @@ pci_vtcon_notify_tx(void *vsc, struct vqueue_info *vq)
while (vq_has_descs(vq)) {
n = vq_getchain(vq, &idx, iov, 1, flags);
- assert(n >= 1);
+ assert(n == 1);
if (port != NULL)
port->vsp_cb(port, port->vsp_arg, iov, 1);
diff --git a/usr.sbin/bhyve/pci_virtio_rnd.c b/usr.sbin/bhyve/pci_virtio_rnd.c
index 10ba9ddfbfaf..46267c6e4c84 100644
--- a/usr.sbin/bhyve/pci_virtio_rnd.c
+++ b/usr.sbin/bhyve/pci_virtio_rnd.c
@@ -113,7 +113,7 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq)
{
struct iovec iov;
struct pci_vtrnd_softc *sc;
- int len;
+ int len, n;
uint16_t idx;
sc = vsc;
@@ -124,7 +124,8 @@ pci_vtrnd_notify(void *vsc, struct vqueue_info *vq)
}
while (vq_has_descs(vq)) {
- vq_getchain(vq, &idx, &iov, 1, NULL);
+ n = vq_getchain(vq, &idx, &iov, 1, NULL);
+ assert(n == 1);
len = read(sc->vrsc_fd, iov.iov_base, iov.iov_len);
diff --git a/usr.sbin/bhyve/pci_virtio_scsi.c b/usr.sbin/bhyve/pci_virtio_scsi.c
index 92a3311b6924..a2b83b77148e 100644
--- a/usr.sbin/bhyve/pci_virtio_scsi.c
+++ b/usr.sbin/bhyve/pci_virtio_scsi.c
@@ -557,15 +557,16 @@ pci_vtscsi_controlq_notify(void *vsc, struct vqueue_info *vq)
{
struct pci_vtscsi_softc *sc;
struct iovec iov[VTSCSI_MAXSEG];
- uint16_t idx, n;
+ uint16_t idx;
void *buf = NULL;
size_t bufsize;
- int iolen;
+ int iolen, n;
sc = vsc;
while (vq_has_descs(vq)) {
n = vq_getchain(vq, &idx, iov, VTSCSI_MAXSEG, NULL);
+ assert(n >= 1 && n <= VTSCSI_MAXSEG);
bufsize = iov_to_buf(iov, n, &buf);
iolen = pci_vtscsi_control_handle(sc, buf, bufsize);
buf_to_iov(buf + bufsize - iolen, iolen, iov, n,
@@ -595,8 +596,8 @@ pci_vtscsi_requestq_notify(void *vsc, struct vqueue_info *vq)
struct pci_vtscsi_request *req;
struct iovec iov[VTSCSI_MAXSEG];
uint16_t flags[VTSCSI_MAXSEG];
- uint16_t idx, n, i;
- int readable;
+ uint16_t idx, i;
+ int readable, n;
sc = vsc;
q = &sc->vss_queues[vq->vq_num - 2];
@@ -604,6 +605,7 @@ pci_vtscsi_requestq_notify(void *vsc, struct vqueue_info *vq)
while (vq_has_descs(vq)) {
readable = 0;
n = vq_getchain(vq, &idx, iov, VTSCSI_MAXSEG, flags);
+ assert(n >= 1 && n <= VTSCSI_MAXSEG);
/* Count readable descriptors */
for (i = 0; i < n; i++) {