Commit 9becd707841207652449a8dfd90fe9c476d88546

Authored by Bjørn Mork
Committed by David S. Miller
1 parent 9d4619c492

net: cdc_ncm: fix buffer overflow

Commit 4d619f625a60 ("net: cdc_ncm: no point in filling up the NTBs
if we send ZLPs") changed the padding logic for devices with the ZLP
flag set.  This meant that frames of any size will be sent without
additional padding, except for the single byte added if the size is
a multiple of the USB packet size. But if the unpadded size is
identical to the maximum frame size, and the maximum size is a
multiplum of the USB packet size, then this one-byte padding will
overflow the buffer.

Prevent padding if already at maximum frame size, letting usbnet
transmit a ZLP instead in this case.

Fixes: 4d619f625a60 ("net: cdc_ncm: no point in filling up the NTBs if we send ZLPs")
Reported by: Yu-an Shih <yshih@nvidia.com>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 1 changed file with 1 additions and 1 deletions Side-by-side Diff

drivers/net/usb/cdc_ncm.c
... ... @@ -785,7 +785,7 @@
785 785 skb_out->len > CDC_NCM_MIN_TX_PKT)
786 786 memset(skb_put(skb_out, ctx->tx_max - skb_out->len), 0,
787 787 ctx->tx_max - skb_out->len);
788   - else if ((skb_out->len % dev->maxpacket) == 0)
  788 + else if (skb_out->len < ctx->tx_max && (skb_out->len % dev->maxpacket) == 0)
789 789 *skb_put(skb_out, 1) = 0; /* force short packet */
790 790  
791 791 /* set final frame length */