OpenCloudOS-Kernel/drivers/net/hamradio
Lin Ma 3c58c9735f hamradio: improve the incomplete fix to avoid NPD
commit b2f37aead1 upstream.

The previous commit 3e0588c291 ("hamradio: defer ax25 kfree after
unregister_netdev") reorder the kfree operations and unregister_netdev
operation to prevent UAF.

This commit improves the previous one by also deferring the nullify of
the ax->tty pointer. Otherwise, a NULL pointer dereference bug occurs.
Partial of the stack trace is shown below.

BUG: kernel NULL pointer dereference, address: 0000000000000538
RIP: 0010:ax_xmit+0x1f9/0x400
...
Call Trace:
 dev_hard_start_xmit+0xec/0x320
 sch_direct_xmit+0xea/0x240
 __qdisc_run+0x166/0x5c0
 __dev_queue_xmit+0x2c7/0xaf0
 ax25_std_establish_data_link+0x59/0x60
 ax25_connect+0x3a0/0x500
 ? security_socket_connect+0x2b/0x40
 __sys_connect+0x96/0xc0
 ? __hrtimer_init+0xc0/0xc0
 ? common_nsleep+0x2e/0x50
 ? switch_fpu_return+0x139/0x1a0
 __x64_sys_connect+0x11/0x20
 do_syscall_64+0x33/0x40
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The crash point is shown as below

static void ax_encaps(...) {
  ...
  set_bit(TTY_DO_WRITE_WAKEUP, &ax->tty->flags); // ax->tty = NULL!
  ...
}

By placing the nullify action after the unregister_netdev, the ax->tty
pointer won't be assigned as NULL net_device framework layer is well
synchronized.

Signed-off-by: Lin Ma <linma@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Honglin Li <honglinli@tencent.com>
2024-06-11 20:43:51 +08:00
..
6pack.c drivers: hamradio: 6pack: fix UAF bug caused by mod_timer() 2024-06-11 20:43:48 +08:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
baycom_epp.c hamradio: Delete unnecessary checks before the macro call “dev_kfree_skb” 2019-08-22 16:22:03 -07:00
baycom_par.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 69 2019-05-24 17:36:47 +02:00
baycom_ser_fdx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 69 2019-05-24 17:36:47 +02:00
baycom_ser_hdx.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 69 2019-05-24 17:36:47 +02:00
bpqether.c ock: sync codes to ock 5.4.119-20.0009.21 2024-06-11 20:27:38 +08:00
dmascc.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 61 2019-05-24 17:36:45 +02:00
hdlcdrv.c hamradio: Delete unnecessary checks before the macro call “dev_kfree_skb” 2019-08-22 16:22:03 -07:00
mkiss.c hamradio: improve the incomplete fix to avoid NPD 2024-06-11 20:43:51 +08:00
scc.c proc: introduce proc_create_seq{,_data} 2018-05-16 07:23:35 +02:00
yam.c yam: fix a memory leak in yam_siocdevprivate() 2024-06-11 20:43:48 +08:00
z8530.h License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00