Skip to content

Commit 69560ef

Browse files
oneukumgregkh
authored andcommitted
CDC-NCM: avoid overflow in sanity checking
commit 8d2b1a1 upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2aeba1e commit 69560ef

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎drivers/net/usb/cdc_ncm.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,10 +1702,10 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
17021702
{
17031703
struct sk_buff *skb;
17041704
struct cdc_ncm_ctx *ctx = (struct cdc_ncm_ctx *)dev->data[0];
1705-
int len;
1705+
unsigned int len;
17061706
int nframes;
17071707
int x;
1708-
int offset;
1708+
unsigned int offset;
17091709
union {
17101710
struct usb_cdc_ncm_ndp16 *ndp16;
17111711
struct usb_cdc_ncm_ndp32 *ndp32;
@@ -1777,8 +1777,8 @@ int cdc_ncm_rx_fixup(struct usbnet *dev, struct sk_buff *skb_in)
17771777
break;
17781778
}
17791779

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

0 commit comments

Comments
 (0)