The branch main has been updated by chuck: URL: https://cgit.FreeBSD.org/src/commit/?id=10d5404adb11773969a600428d1abeb4308d98aa
commit 10d5404adb11773969a600428d1abeb4308d98aa Author: Chuck Tuffli <[email protected]> AuthorDate: 2026-02-19 22:27:49 +0000 Commit: Chuck Tuffli <[email protected]> CommitDate: 2026-02-19 22:27:49 +0000 bhyve: fix USB mouse requests USB HCI requests may not include HCI transfer block structures (i.e., xfer->data[] == NULL), but in several places, the USB mouse emulation code assumes one will exist. This can lead to a NULL pointer dereference and a SEGV in the bhyve process as observed via experiments with an Ubuntu guest and PyUSB code. Note that many of the cases processing other request types already checked for data == NULL. While in the neighborhood, fix a typo in the loop iterating over the usb_data_xfer_block array which used the wrong variable to check for valid data (idx vs. i). Reported by: [email protected] Obtained from: SmartOS MFC after: 1 week Relnotes: yes Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D54661 --- usr.sbin/bhyve/usb_mouse.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/usr.sbin/bhyve/usb_mouse.c b/usr.sbin/bhyve/usb_mouse.c index 5caad886e082..6c0b051c67f2 100644 --- a/usr.sbin/bhyve/usb_mouse.c +++ b/usr.sbin/bhyve/usb_mouse.c @@ -343,7 +343,7 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) idx = xfer->head; for (i = 0; i < xfer->ndata; i++) { xfer->data[idx].bdone = 0; - if (data == NULL && USB_DATA_OK(xfer,i)) { + if (data == NULL && USB_DATA_OK(xfer, idx)) { data = &xfer->data[idx]; udata = data->buf; } @@ -529,7 +529,9 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) case UREQ(UR_GET_STATUS, UT_READ_DEVICE): DPRINTF(("umouse: (UR_GET_STATUS, UT_READ_DEVICE)")); - if (data != NULL && len > 1) { + if (data == NULL) + break; + if (len > 1) { if (sc->hid.feature == UF_DEVICE_REMOTE_WAKEUP) USETW(udata, UDS_REMOTE_WAKEUP); else @@ -538,18 +540,20 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) data->bdone += 2; } - eshort = data != NULL && data->blen > 0; + eshort = data->blen > 0; break; case UREQ(UR_GET_STATUS, UT_READ_INTERFACE): case UREQ(UR_GET_STATUS, UT_READ_ENDPOINT): DPRINTF(("umouse: (UR_GET_STATUS, UT_READ_INTERFACE)")); - if (data != NULL && len > 1) { + if (data == NULL) + break; + if (len > 1) { USETW(udata, 0); data->blen = len - 2; data->bdone += 2; } - eshort = data != NULL && data->blen > 0; + eshort = data->blen > 0; break; case UREQ(UR_SET_ADDRESS, UT_WRITE_DEVICE): @@ -629,21 +633,25 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer) break; case UREQ(UMOUSE_GET_IDLE, UT_READ_CLASS_INTERFACE): - if (data != NULL && len > 0) { + if (data == NULL) + break; + if (len > 0) { *udata = sc->hid.idle; data->blen = len - 1; data->bdone += 1; } - eshort = data != NULL && data->blen > 0; + eshort = data->blen > 0; break; case UREQ(UMOUSE_GET_PROTOCOL, UT_READ_CLASS_INTERFACE): - if (data != NULL && len > 0) { + if (data == NULL) + break; + if (len > 0) { *udata = sc->hid.protocol; data->blen = len - 1; data->bdone += 1; } - eshort = data != NULL && data->blen > 0; + eshort = data->blen > 0; break; case UREQ(UMOUSE_SET_REPORT, UT_WRITE_CLASS_INTERFACE):
