linux/drivers/net
Jouni K. Seppänen 7a68d725e4 net: cdc_ncm: correct overhead in delayed_ndp_size
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>
2021-01-05 16:49:04 -08:00
..
appletalk
arcnet
bonding Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-12-11 22:29:38 -08:00
caif
can can: kvaser_pciefd: select CONFIG_CRC32 2021-01-05 15:50:36 -08:00
dsa net: dsa: lantiq_gswip: Fix GSWIP_MII_CFG(p) register access 2021-01-04 13:47:15 -08:00
ethernet net: hns3: fix incorrect handling of sctp6 rss tuple 2021-01-05 16:46:41 -08:00
fddi
fjes
hamradio
hippi
hyperv Networking fixes for 5.11-rc1. 2020-12-17 13:45:24 -08:00
ieee802154
ipa net: ipa: don't return a value from evt_ring_command() 2020-12-28 14:13:22 -08:00
ipvlan
mdio
netdevsim Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-12-11 22:29:38 -08:00
pcs
phy net: sfp: relax bitrate-derived mode check 2020-12-09 19:38:10 -08:00
plip
ppp ppp: add PPPIOCBRIDGECHAN and PPPIOCUNBRIDGECHAN ioctls 2020-12-10 13:57:36 -08:00
slip
team
usb net: cdc_ncm: correct overhead in delayed_ndp_size 2021-01-05 16:49:04 -08:00
vmxnet3
wan wan: ds26522: select CONFIG_BITREVERSE 2021-01-05 15:50:36 -08:00
wireguard selinux/stable-5.11 PR 20201214 2020-12-16 11:01:04 -08:00
wireless wil6210: select CONFIG_CRC32 2021-01-05 15:50:36 -08:00
xen-netback xen/xenbus: Add 'will_handle' callback support in xenbus_watch_path() 2020-12-14 10:04:18 +01:00
bareudp.c bareudp: Fix use of incorrect min_headroom size 2021-01-04 13:13:04 -08:00
dummy.c
eql.c
geneve.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-12-11 22:29:38 -08:00
gtp.c
ifb.c
Kconfig net: fix spelling mistake "wil" -> "will" in Kconfig 2020-12-05 15:17:19 -08:00
LICENSE.SRC
loopback.c
macsec.c
macvlan.c macvlan: Support for high multicast packet rate 2020-12-03 08:21:29 -08:00
macvtap.c
Makefile
mdio.c
mhi_net.c net: mhi: Fix unexpected queue wake 2020-12-14 17:25:56 -08:00
mii.c
net_failover.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
Space.c
sungem_phy.c
tap.c
thunderbolt.c USB / Thunderbolt patches for 5.11-rc1 2020-12-15 13:54:56 -08:00
tun.c tun: fix return value when the number of iovs exceeds MAX_SKB_FRAGS 2020-12-28 13:34:36 -08:00
veth.c Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 2020-12-04 07:48:12 -08:00
virtio_net.c Networking fixes for 5.11-rc3, including fixes from netfilter, wireless 2021-01-05 12:38:56 -08:00
vrf.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2020-12-11 22:29:38 -08:00
vsockmon.c
vxlan.c vxlan: avoid double unlikely() notation when using IS_ERR() 2020-12-10 12:43:29 -08:00
xen-netfront.c