]> Git Repo - J-linux.git/commitdiff
comedi: ni_usb6501: fix NULL-deref in command paths
authorJohan Hovold <[email protected]>
Wed, 27 Oct 2021 09:35:28 +0000 (11:35 +0200)
committerGreg Kroah-Hartman <[email protected]>
Sat, 30 Oct 2021 08:54:47 +0000 (10:54 +0200)
The driver uses endpoint-sized USB transfer buffers but had no sanity
checks on the sizes. This can lead to zero-size-pointer dereferences or
overflowed transfer buffers in ni6501_port_command() and
ni6501_counter_command() if a (malicious) device has smaller max-packet
sizes than expected (or when doing descriptor fuzz testing).

Add the missing sanity checks to probe().

Fixes: a03bb00e50ab ("staging: comedi: add NI USB-6501 support")
Cc: [email protected] # 3.18
Cc: Luca Ellero <[email protected]>
Reviewed-by: Ian Abbott <[email protected]>
Signed-off-by: Johan Hovold <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
drivers/comedi/drivers/ni_usb6501.c

index 5b6d9d783b2f74339159a7bb814a78d9d8e77b26..c42987b74b1dcb6d3aec08aac574116c46c5dbca 100644 (file)
@@ -144,6 +144,10 @@ static const u8 READ_COUNTER_RESPONSE[]    = {0x00, 0x01, 0x00, 0x10,
                                           0x00, 0x00, 0x00, 0x02,
                                           0x00, 0x00, 0x00, 0x00};
 
+/* Largest supported packets */
+static const size_t TX_MAX_SIZE        = sizeof(SET_PORT_DIR_REQUEST);
+static const size_t RX_MAX_SIZE        = sizeof(READ_PORT_RESPONSE);
+
 enum commands {
        READ_PORT,
        WRITE_PORT,
@@ -501,6 +505,12 @@ static int ni6501_find_endpoints(struct comedi_device *dev)
        if (!devpriv->ep_rx || !devpriv->ep_tx)
                return -ENODEV;
 
+       if (usb_endpoint_maxp(devpriv->ep_rx) < RX_MAX_SIZE)
+               return -ENODEV;
+
+       if (usb_endpoint_maxp(devpriv->ep_tx) < TX_MAX_SIZE)
+               return -ENODEV;
+
        return 0;
 }
 
This page took 0.058701 seconds and 4 git commands to generate.