WSL2-Linux-Kernel/drivers/net
Duoming Zhou a78b882c1a mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv
[ Upstream commit a52ed4866d ]

There are sleep in atomic context bugs when uploading device dump
data in mwifiex. The root cause is that dev_coredumpv could not
be used in atomic contexts, because it calls dev_set_name which
include operations that may sleep. The call tree shows execution
paths that could lead to bugs:

   (Interrupt context)
fw_dump_timer_fn
  mwifiex_upload_device_dump
    dev_coredumpv(..., GFP_KERNEL)
      dev_coredumpm()
        kzalloc(sizeof(*devcd), gfp); //may sleep
        dev_set_name
          kobject_set_name_vargs
            kvasprintf_const(GFP_KERNEL, ...); //may sleep
            kstrdup(s, GFP_KERNEL); //may sleep

The corresponding fail log is shown below:

[  135.275938] usb 1-1: == mwifiex dump information to /sys/class/devcoredump start
[  135.281029] BUG: sleeping function called from invalid context at include/linux/sched/mm.h:265
...
[  135.293613] Call Trace:
[  135.293613]  <IRQ>
[  135.293613]  dump_stack_lvl+0x57/0x7d
[  135.293613]  __might_resched.cold+0x138/0x173
[  135.293613]  ? dev_coredumpm+0xca/0x2e0
[  135.293613]  kmem_cache_alloc_trace+0x189/0x1f0
[  135.293613]  ? devcd_match_failing+0x30/0x30
[  135.293613]  dev_coredumpm+0xca/0x2e0
[  135.293613]  ? devcd_freev+0x10/0x10
[  135.293613]  dev_coredumpv+0x1c/0x20
[  135.293613]  ? devcd_match_failing+0x30/0x30
[  135.293613]  mwifiex_upload_device_dump+0x65/0xb0
[  135.293613]  ? mwifiex_dnld_fw+0x1b0/0x1b0
[  135.293613]  call_timer_fn+0x122/0x3d0
[  135.293613]  ? msleep_interruptible+0xb0/0xb0
[  135.293613]  ? lock_downgrade+0x3c0/0x3c0
[  135.293613]  ? __next_timer_interrupt+0x13c/0x160
[  135.293613]  ? lockdep_hardirqs_on_prepare+0xe/0x220
[  135.293613]  ? mwifiex_dnld_fw+0x1b0/0x1b0
[  135.293613]  __run_timers.part.0+0x3f8/0x540
[  135.293613]  ? call_timer_fn+0x3d0/0x3d0
[  135.293613]  ? arch_restore_msi_irqs+0x10/0x10
[  135.293613]  ? lapic_next_event+0x31/0x40
[  135.293613]  run_timer_softirq+0x4f/0xb0
[  135.293613]  __do_softirq+0x1c2/0x651
...
[  135.293613] RIP: 0010:default_idle+0xb/0x10
[  135.293613] RSP: 0018:ffff888006317e68 EFLAGS: 00000246
[  135.293613] RAX: ffffffff82ad8d10 RBX: ffff888006301cc0 RCX: ffffffff82ac90e1
[  135.293613] RDX: ffffed100d9ff1b4 RSI: ffffffff831ad140 RDI: ffffffff82ad8f20
[  135.293613] RBP: 0000000000000003 R08: 0000000000000000 R09: ffff88806cff8d9b
[  135.293613] R10: ffffed100d9ff1b3 R11: 0000000000000001 R12: ffffffff84593410
[  135.293613] R13: 0000000000000000 R14: 0000000000000000 R15: 1ffff11000c62fd2
...
[  135.389205] usb 1-1: == mwifiex dump information to /sys/class/devcoredump end

This patch uses delayed work to replace timer and moves the operations
that may sleep into a delayed work in order to mitigate bugs, it was
tested on Marvell 88W8801 chip whose port is usb and the firmware is
usb8801_uapsta.bin. The following is the result after using delayed
work to replace timer.

[  134.936453] usb 1-1: == mwifiex dump information to /sys/class/devcoredump start
[  135.043344] usb 1-1: == mwifiex dump information to /sys/class/devcoredump end

As we can see, there is no bug now.

Fixes: f5ecd02a8b ("mwifiex: device dump support for usb interface")
Reviewed-by: Brian Norris <briannorris@chromium.org>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Link: https://lore.kernel.org/r/b63b77fc84ed3e8a6bef02378e17c7c71a0bc3be.1654569290.git.duoming@zju.edu.cn
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-08-17 14:23:44 +02:00
..
appletalk
arcnet net: arcnet: com20020: Fix null-ptr-deref in com20020pci_probe() 2022-03-08 19:12:46 +01:00
bonding net: bonding: fix use-after-free after 802.3ad slave unbind 2022-07-07 17:53:28 +02:00
caif caif_virtio: fix race between virtio_device_ready() and ndo_open() 2022-07-07 17:53:27 +02:00
can can: pch_can: pch_can_error(): initialize errc before using it 2022-08-17 14:23:33 +02:00
dsa net: dsa: vitesse-vsc73xx: silent spi_device_id warnings 2022-07-29 17:25:21 +02:00
ethernet net: ionic: fix error check for vlan flags in ionic_set_nic_features() 2022-08-17 14:23:37 +02:00
fddi
fjes fjes: Check for error irq 2021-12-29 12:28:44 +01:00
hamradio hamradio: remove needs_free_netdev to avoid UAF 2022-04-20 09:34:04 +02:00
hippi drivers: net: hippi: Fix deadlock in rr_close() 2022-05-09 09:14:40 +02:00
hyperv hv_netvsc: Fix potential dereference of NULL pointer 2022-06-09 10:23:02 +02:00
ieee802154 net: ieee802154: ca8210: Fix lifs/sifs periods 2022-02-23 12:03:11 +01:00
ipa net: ipa: fix page free in ipa_endpoint_replenish_one() 2022-06-09 10:23:30 +02:00
ipvlan
mctp
mdio net: mdio: Fix ENOMEM return value in BCM6368 mux bus controller 2022-05-12 12:30:16 +02:00
netdevsim netdevsim: Avoid allocation warnings triggered from user space 2022-08-17 14:23:36 +02:00
pcs net: pcs: xpcs: propagate xpcs_read error to xpcs_get_state_c37_sgmii 2022-08-03 12:03:48 +02:00
phy net: sfp: fix memory leak in sfp_probe() 2022-07-21 21:24:36 +02:00
plip
ppp net: fix dev_fill_forward_path with pppoe + bridge 2022-05-25 09:57:31 +02:00
slip drivers: net: slip: fix NPD bug in sl_tx_timeout() 2022-04-20 09:34:17 +02:00
team
usb net: usb: make USB_RTL8153_ECM non user configurable 2022-08-17 14:23:37 +02:00
vmxnet3 net: vmxnet3: fix possible NULL pointer dereference in vmxnet3_rq_cleanup() 2022-05-25 09:57:31 +02:00
wan
wireguard wireguard: allowedips: don't corrupt stack when detecting overflow 2022-08-17 14:23:37 +02:00
wireless mwifiex: fix sleep in atomic context bugs caused by dev_coredumpv 2022-08-17 14:23:44 +02:00
wwan net: wwan: Fix MRU mismatch issue which may lead to data connection lost 2022-01-27 11:05:40 +01:00
xen-netback xen/netback: avoid entering xenvif_rx_next_skb() with an empty rx queue 2022-07-21 21:24:11 +02:00
Kconfig lib/crypto: blake2s: include as built-in 2022-05-30 09:28:59 +02:00
LICENSE.SRC
Makefile
Space.c
bareudp.c bareudp: use ipv6_mod_enabled to check if IPv6 enabled 2022-04-08 14:23:41 +02:00
dummy.c
eql.c
geneve.c
gtp.c
ifb.c
loopback.c
macsec.c net: macsec: fix potential resource leak in macsec_add_rxsa() and macsec_add_txsa() 2022-08-03 12:03:50 +02:00
macvlan.c macvlan: Fix leaking skb in source mode with nodst option 2022-04-20 09:34:13 +02:00
macvtap.c macvtap: advertise link netns via netlink 2022-04-13 20:59:07 +02:00
mdio.c
mhi_net.c
mii.c
net_failover.c
netconsole.c
nlmon.c
ntb_netdev.c
rionet.c
sb1000.c
sungem_phy.c net: sungem_phy: Add of_node_put() for reference returned by of_get_parent() 2022-08-03 12:03:48 +02:00
tap.c tuntap: add sanity checks about msg_controllen in sendmsg 2022-04-13 20:59:07 +02:00
thunderbolt.c
tun.c net: tun: split run_ebpf_filter() and pskb_trim() into different "if statement" 2022-07-29 17:25:11 +02:00
veth.c veth: Ensure eth header is in skb's linear part 2022-04-20 09:34:10 +02:00
virtio_net.c virtio-net: fix the race between refill work and close 2022-08-03 12:03:53 +02:00
vrf.c vrf: fix packet sniffing for traffic originating from ip tunnels 2022-04-13 20:59:15 +02:00
vsockmon.c
vxlan.c vxlan: fix error return code in vxlan_fdb_append 2022-04-27 14:38:55 +02:00
xen-netfront.c xen-netfront: restore __skb_queue_tail() positioning in xennet_get_responses() 2022-07-07 17:53:32 +02:00