android_kernel_msm-6.1_noth.../drivers/net
Tudor Ambarus fd04f99bfa UPSTREAM: net: cdc_ncm: Deal with too low values of dwNtbOutMaxSize
commit 7e01c7f7046efc2c7c192c3619db43292b98e997 upstream.

Currently in cdc_ncm_check_tx_max(), if dwNtbOutMaxSize is lower than
the calculated "min" value, but greater than zero, the logic sets
tx_max to dwNtbOutMaxSize. This is then used to allocate a new SKB in
cdc_ncm_fill_tx_frame() where all the data is handled.

For small values of dwNtbOutMaxSize the memory allocated during
alloc_skb(dwNtbOutMaxSize, GFP_ATOMIC) will have the same size, due to
how size is aligned at alloc time:
	size = SKB_DATA_ALIGN(size);
        size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
Thus we hit the same bug that we tried to squash with
commit 2be6d4d16a ("net: cdc_ncm: Allow for dwNtbOutMaxSize to be unset or zero")

Low values of dwNtbOutMaxSize do not cause an issue presently because at
alloc_skb() time more memory (512b) is allocated than required for the
SKB headers alone (320b), leaving some space (512b - 320b = 192b)
for CDC data (172b).

However, if more elements (for example 3 x u64 = [24b]) were added to
one of the SKB header structs, say 'struct skb_shared_info',
increasing its original size (320b [320b aligned]) to something larger
(344b [384b aligned]), then suddenly the CDC data (172b) no longer
fits in the spare SKB data area (512b - 384b = 128b).

Consequently the SKB bounds checking semantics fails and panics:

skbuff: skb_over_panic: text:ffffffff831f755b len:184 put:172 head:ffff88811f1c6c00 data:ffff88811f1c6c00 tail:0xb8 end:0x80 dev:<NULL>
------------[ cut here ]------------
kernel BUG at net/core/skbuff.c:113!
invalid opcode: 0000 [#1] PREEMPT SMP KASAN
CPU: 0 PID: 57 Comm: kworker/0:2 Not tainted 5.15.106-syzkaller-00249-g19c0ed55a470 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/14/2023
Workqueue: mld mld_ifc_work
RIP: 0010:skb_panic net/core/skbuff.c:113 [inline]
RIP: 0010:skb_over_panic+0x14c/0x150 net/core/skbuff.c:118
[snip]
Call Trace:
 <TASK>
 skb_put+0x151/0x210 net/core/skbuff.c:2047
 skb_put_zero include/linux/skbuff.h:2422 [inline]
 cdc_ncm_ndp16 drivers/net/usb/cdc_ncm.c:1131 [inline]
 cdc_ncm_fill_tx_frame+0x11ab/0x3da0 drivers/net/usb/cdc_ncm.c:1308
 cdc_ncm_tx_fixup+0xa3/0x100

Deal with too low values of dwNtbOutMaxSize, clamp it in the range
[USB_CDC_NCM_NTB_MIN_OUT_SIZE, CDC_NCM_NTB_MAX_SIZE_TX]. We ensure
enough data space is allocated to handle CDC data by making sure
dwNtbOutMaxSize is not smaller than USB_CDC_NCM_NTB_MIN_OUT_SIZE.

Fixes: 289507d336 ("net: cdc_ncm: use sysfs for rx/tx aggregation tuning")
Cc: stable@vger.kernel.org
Reported-by: syzbot+9f575a1f15fc0c01ed69@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=b982f1059506db48409d
Link: https://lore.kernel.org/all/20211202143437.1411410-1-lee.jones@linaro.org/
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
Link: https://lore.kernel.org/r/20230517133808.1873695-2-tudor.ambarus@linaro.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Bug: 281604646
Bug: 281606231
Change-Id: Ic1d912e7bf2ba53620eb8293b68ec6046422e047
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
2023-06-07 11:55:40 +00:00
..
appletalk
arcnet arcnet: fix potential memory leak in com20020_probe() 2022-11-23 12:41:54 +00:00
bonding bonding: Fix memory leak when changing bond type to Ethernet 2023-04-26 14:28:34 +02:00
caif
can can: esd_usb: Make use of can_change_state() and relocate checking skb for NULL 2023-03-10 09:33:06 +01:00
dsa net: dsa: b53: mmap: add phy ops 2023-04-26 14:28:36 +02:00
ethernet e1000e: Disable TSO on i219-LM card to increase speed 2023-04-26 14:28:35 +02:00
fddi net: defxx: Fix missing err handling in dfx_init() 2022-12-31 13:32:26 +01:00
fjes
hamradio hamradio: baycom_epp: Fix return type of baycom_send_packet() 2022-12-31 13:33:00 +01:00
hippi
hyperv hv_netvsc: Check status in SEND_RNDIS_PKT completion message 2023-03-10 09:33:53 +01:00
ieee802154 ca8210: Fix unsigned mac_len comparison with zero in ca8210_skb_tx() 2023-04-06 12:10:42 +02:00
ipa net: ipa: compute DMA pool size properly 2023-04-06 12:10:48 +02:00
ipvlan ipvlan: Make skb->skb_iif track skb->dev for l3s mode 2023-03-22 13:33:44 +01:00
mctp mctp: serial: Fix starting value for frame check sequence 2022-12-31 13:32:56 +01:00
mdio Revert "Revert "net: mdio: fix owner field for mdio buses registered using device-tree"" 2023-04-12 02:08:28 +00:00
netdevsim netdevsim: Fix memory leak of nsim_dev->fa_cookie 2022-11-16 12:20:57 -08:00
pcs
phy net: phy: nxp-c45-tja11xx: fix unsigned long multiplication overflow 2023-04-20 12:35:13 +02:00
plip net: plip: don't call kfree_skb/dev_kfree_skb() under spin_lock_irq() 2022-12-07 20:10:47 -08:00
ppp use less confusing names for iov_iter direction initializers 2023-02-09 11:28:04 +01:00
pse-pd
slip
team
usb UPSTREAM: net: cdc_ncm: Deal with too low values of dwNtbOutMaxSize 2023-06-07 11:55:40 +00:00
vmxnet3 vmxnet3: use gro callback when UPT is enabled 2023-04-06 12:10:52 +02:00
vxlan vxlan: Fix memory leaks in error path 2023-01-12 12:02:25 +01:00
wan net: wan: Add checks for NULL for utdm in undo_uhdlc_init and unmap_si_regs 2023-02-01 08:34:17 +01:00
wireguard treewide: use get_random_bytes() when possible 2022-10-11 17:42:58 -06:00
wireless BACKPORT: firmware: qcom_scm: Use fixed width src vm bitmap 2023-05-16 20:35:28 +00:00
wwan net: wwan: iosm: Fix error handling path in ipc_pcie_probe() 2023-04-20 12:35:09 +02:00
xen-netback xen/netback: use same error messages for same errors 2023-04-26 14:28:37 +02:00
amt.c
bareudp.c
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
Kconfig
LICENSE.SRC
loopback.c net: loopback: use NET_NAME_PREDICTABLE for name_assign_type 2022-11-25 09:39:05 +00:00
macsec.c net: macsec: fix net device access prior to holding a lock 2022-12-31 13:32:53 +01:00
macvlan.c net: macvlan: Use built-in RCU list checking 2022-11-14 10:50:02 +00:00
macvtap.c
Makefile
mdio.c
mhi_net.c net: mhi: Fix memory leak in mhi_net_dellink() 2022-11-14 11:21:02 +00:00
mii.c
net_failover.c net/net_failover: fix txq exceeding warning 2023-04-06 12:10:46 +02:00
netconsole.c
nlmon.c
ntb_netdev.c ntb_netdev: Use dev_kfree_skb_any() in interrupt context 2022-12-31 13:32:28 +01:00
rionet.c
sb1000.c
Space.c
sungem_phy.c
tap.c tap: tap_open(): correctly initialize socket uid 2023-03-10 09:33:01 +01:00
thunderbolt.c net: thunderbolt: fix memory leak in tbnet_open() 2022-12-08 09:07:37 -08:00
tun.c tun: tun_chr_open(): correctly initialize socket uid 2023-03-10 09:33:01 +01:00
veth.c veth: Fix use after free in XDP_REDIRECT 2023-03-22 13:33:49 +01:00
virtio_net.c virtio_net: bugfix overflow inside xdp_linearize_page() 2023-04-26 14:28:33 +02:00
vrf.c net: vrf: determine the dst using the original ifindex for multicast 2023-01-12 12:01:57 +01:00
vsockmon.c
xen-netfront.c xen-netfront: Fix NULL sring after live migration 2022-12-05 11:35:29 +00:00