Message ID | 20210103143602.95343-1-jks@iki.fi |
---|---|
State | New |
Headers | show |
Series | [net,stable] net: cdc_ncm: correct overhead in delayed_ndp_size | expand |
Jouni Seppänen <jks@iki.fi> writes: > + delayed_ndp_size = ctx->max_ndp_size + > + max(ctx->tx_ndp_modulus, > + ctx->tx_modulus + ctx->tx_remainder) - 1; You'll probably have to use something like max_t(u32, ctx->tx_ndp_modulus, ctx->tx_modulus + ctx->tx_remainder) here as the test robot already said. Sorry for not seeing that earlier. Otherwise this looks very good to me. The bug is real and severe, and your patch appears to be the proper fix for it. Thanks a lot for figuring this out and taking the time to fixup this rather messy piece of code. Reviewed-by: Bjørn Mork <bjorn@mork.no>
diff --git a/drivers/net/usb/cdc_ncm.c b/drivers/net/usb/cdc_ncm.c index e04f588538cc..59f0711b1b63 100644 --- a/drivers/net/usb/cdc_ncm.c +++ b/drivers/net/usb/cdc_ncm.c @@ -1199,7 +1199,9 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign) * accordingly. Otherwise, we should check here. */ if (ctx->drvflags & CDC_NCM_FLAG_NDP_TO_END) - delayed_ndp_size = ALIGN(ctx->max_ndp_size, ctx->tx_ndp_modulus); + delayed_ndp_size = ctx->max_ndp_size + + max(ctx->tx_ndp_modulus, + ctx->tx_modulus + ctx->tx_remainder) - 1; else delayed_ndp_size = 0; @@ -1410,7 +1412,8 @@ cdc_ncm_fill_tx_frame(struct usbnet *dev, struct sk_buff *skb, __le32 sign) if (!(dev->driver_info->flags & FLAG_SEND_ZLP) && skb_out->len > ctx->min_tx_pkt) { padding_count = ctx->tx_curr_size - skb_out->len; - skb_put_zero(skb_out, padding_count); + if (!WARN_ON(padding_count > ctx->tx_curr_size)) + skb_put_zero(skb_out, padding_count); } else if (skb_out->len < ctx->tx_curr_size && (skb_out->len % dev->maxpacket) == 0) { skb_put_u8(skb_out, 0); /* force short packet */