The branch stable/15 has been updated by chuck:

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

commit d329a91dc3e9c21044d6d25b8e07e0094fc0fbc5
Author:     Chuck Tuffli <[email protected]>
AuthorDate: 2026-02-19 22:27:49 +0000
Commit:     Chuck Tuffli <[email protected]>
CommitDate: 2026-03-01 15:42:26 +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).
    
    (cherry picked from commit 10d5404adb11773969a600428d1abeb4308d98aa)
---
 usr.sbin/bhyve/usb_mouse.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/usr.sbin/bhyve/usb_mouse.c b/usr.sbin/bhyve/usb_mouse.c
index 82b1159d5f61..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
@@ -544,7 +546,9 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer)
        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;
@@ -629,7 +633,9 @@ 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;
@@ -638,7 +644,9 @@ umouse_request(void *scarg, struct usb_data_xfer *xfer)
                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;

Reply via email to