linux/drivers/net/usb
Jouni K. Seppänen 69ac0b72a1 net: cdc_ncm: correct overhead in delayed_ndp_size
[ Upstream commit 7a68d725e4 ]

Aligning to tx_ndp_modulus is not sufficient because the next align
call can be cdc_ncm_align_tail, which can add up to ctx->tx_modulus +
ctx->tx_remainder - 1 bytes. This used to lead to occasional crashes
on a Huawei 909s-120 LTE module as follows:

- the condition marked /* if there is a remaining skb [...] */ is true
  so the swaps happen
- skb_out is set from ctx->tx_curr_skb
- skb_out->len is exactly 0x3f52
- ctx->tx_curr_size is 0x4000 and delayed_ndp_size is 0xac
  (note that the sum of skb_out->len and delayed_ndp_size is 0x3ffe)
- the for loop over n is executed once
- the cdc_ncm_align_tail call marked /* align beginning of next frame */
  increases skb_out->len to 0x3f56 (the sum is now 0x4002)
- the condition marked /* check if we had enough room left [...] */ is
  false so we break out of the loop
- the condition marked /* If requested, put NDP at end of frame. */ is
  true so the NDP is written into skb_out
- now skb_out->len is 0x4002, so padding_count is minus two interpreted
  as an unsigned number, which is used as the length argument to memset,
  leading to a crash with various symptoms but usually including

> Call Trace:
>  <IRQ>
>  cdc_ncm_fill_tx_frame+0x83a/0x970 [cdc_ncm]
>  cdc_mbim_tx_fixup+0x1d9/0x240 [cdc_mbim]
>  usbnet_start_xmit+0x5d/0x720 [usbnet]

The cdc_ncm_align_tail call first aligns on a ctx->tx_modulus
boundary (adding at most ctx->tx_modulus-1 bytes), then adds
ctx->tx_remainder bytes. Alternatively, the next alignment call can
occur in cdc_ncm_ndp16 or cdc_ncm_ndp32, in which case at most
ctx->tx_ndp_modulus-1 bytes are added.

A similar problem has occurred before, and the code is nontrivial to
reason about, so add a guard before the crashing call. By that time it
is too late to prevent any memory corruption (we'll have written past
the end of the buffer already) but we can at least try to get a warning
written into an on-disk log by avoiding the hard crash caused by padding
past the buffer with a huge number of zeros.

Signed-off-by: Jouni K. Seppänen <jks@iki.fi>
Fixes: 4a0e3e989d ("cdc_ncm: Add support for moving NDP to end of NCM frame")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=209407
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-01-17 14:04:18 +01:00
..
asix_common.c net: usb: Fix uninit-was-stored issue in asix_read_phy_addr() 2020-09-09 19:04:32 +02:00
asix_devices.c
asix.h
ax88172a.c ax88172a: fix ax88172a_unbind() failures 2020-07-29 10:16:49 +02:00
ax88179_178a.c net: usb: ax88179_178a: fix missing stop entry in driver_info 2020-10-14 10:31:25 +02:00
catc.c
cdc_eem.c
cdc_ether.c r8152: support additional Microsoft Surface Ethernet Adapter variant 2020-06-03 08:19:20 +02:00
cdc_mbim.c
cdc_ncm.c net: cdc_ncm: correct overhead in delayed_ndp_size 2021-01-17 14:04:18 +01:00
cdc_subset.c
cdc-phonet.c
ch9200.c
cx82310_eth.c cx82310_eth: fix a memory leak bug 2019-09-10 10:33:47 +01:00
dm9601.c net: usb: dm9601: Add USB ID of Keenetic Plus DSL 2020-09-12 13:40:22 +02:00
gl620a.c
hso.c usb: hso: check for return value in hso_serial_common_create() 2020-08-11 15:32:33 +02:00
huawei_cdc_ncm.c
int51x1.c
ipheth.c usbnet: ipheth: fix connectivity with iOS 14 2020-12-08 10:18:52 +01:00
kalmia.c net: kalmia: fix memory leaks 2019-09-10 10:33:48 +01:00
kaweth.c
Kconfig
lan78xx.c net: lan78xx: replace bogus endpoint lookup 2020-08-11 15:32:34 +02:00
lan78xx.h
lg-vl600.c
Makefile
mcs7830.c
net1080.c
pegasus.c
pegasus.h
plusb.c
qmi_wwan.c net: usb: qmi_wwan: add Quectel EM160R-GL 2021-01-12 20:10:19 +01:00
r8152.c r8152: support additional Microsoft Surface Ethernet Adapter variant 2020-06-03 08:19:20 +02:00
rndis_host.c rndis_host: increase sleep time in the query-response loop 2020-10-07 08:00:06 +02:00
rtl8150.c net: usb: rtl8150: set random MAC address when set_ethernet_addr() fails 2020-10-14 10:31:26 +02:00
sierra_net.c
smsc75xx.c
smsc75xx.h
smsc95xx.c smsc95xx: avoid memory leak in smsc95xx_bind 2020-07-16 08:17:24 +02:00
smsc95xx.h
sr9700.c
sr9700.h
sr9800.c net: usb: sr9800: fix uninitialized local variable 2019-11-06 13:06:26 +01:00
sr9800.h
usbnet.c usbnet: sanity checking of packet sizes and device mtu 2019-10-05 13:09:30 +02:00
zaurus.c