Skip to content

Commit 8d2b1a1

Browse files
oneukumdavem330
authored andcommitted
CDC-NCM: avoid overflow in sanity checking
A broken device may give an extreme offset like 0xFFF0 and a reasonable length for a fragment. In the sanity check as formulated now, this will create an integer overflow, defeating the sanity check. Both offset and offset + len need to be checked in such a manner that no overflow can occur. And those quantities should be unsigned. Signed-off-by: Oliver Neukum <oneukum@suse.com> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 7e5b6a5 commit 8d2b1a1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/net/usb/cdc_ncm.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,10 +1715,10 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
17151715
{
17161716
struct sk_buff *skb;
17171717
struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
1718-
int len;
1718+
unsigned int len;
17191719
int nframes;
17201720
int x;
1721-
int offset;
1721+
unsigned int offset;
17221722
union {
17231723
struct usb_cdc_ncm_ndp16 *ndp16;
17241724
struct usb_cdc_ncm_ndp32 *ndp32;
@@ -1790,8 +1790,8 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
17901790
break;
17911791
}
17921792

1793-
/* sanity checking */
1794-
if (((offset + len) > skb_in->len) ||
1793+
/* sanity checking - watch out for integer wrap*/
1794+
if ((offset > skb_in->len) || (len > skb_in->len - offset) ||
17951795
(len > ctx->rx_max) || (len < ETH_HLEN)) {
17961796
netif_dbg(dev, rx_err, dev->net,
17971797
"invalid frame detected (ignored) offset[%u]=%u, length=%u, skb=%p\n",

0 commit comments

Comments
 (0)