]> git.baikalelectronics.ru Git - kernel.git/commit
ax25: Fix NULL pointer dereference in ax25_kill_by_device
authorDuoming Zhou <duoming@zju.edu.cn>
Tue, 8 Mar 2022 08:12:23 +0000 (16:12 +0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 9 Mar 2022 12:45:02 +0000 (12:45 +0000)
commit4fb6c22f5b14df2e788ce13e223a76fd17ececc0
treefb7c10dd2acfaf035b19cd8fdd828e75658e286c
parent588b8ced27a068d9b994a506aaa801c4fb99d50c
ax25: Fix NULL pointer dereference in ax25_kill_by_device

When two ax25 devices attempted to establish connection, the requester use ax25_create(),
ax25_bind() and ax25_connect() to initiate connection. The receiver use ax25_rcv() to
accept connection and use ax25_create_cb() in ax25_rcv() to create ax25_cb, but the
ax25_cb->sk is NULL. When the receiver is detaching, a NULL pointer dereference bug
caused by sock_hold(sk) in ax25_kill_by_device() will happen. The corresponding
fail log is shown below:

===============================================================
BUG: KASAN: null-ptr-deref in ax25_device_event+0xfd/0x290
Call Trace:
...
ax25_device_event+0xfd/0x290
raw_notifier_call_chain+0x5e/0x70
dev_close_many+0x174/0x220
unregister_netdevice_many+0x1f7/0xa60
unregister_netdevice_queue+0x12f/0x170
unregister_netdev+0x13/0x20
mkiss_close+0xcd/0x140
tty_ldisc_release+0xc0/0x220
tty_release_struct+0x17/0xa0
tty_release+0x62d/0x670
...

This patch add condition check in ax25_kill_by_device(). If s->sk is
NULL, it will goto if branch to kill device.

Fixes: 3652f39acf60 ("ax25: improve the incomplete fix to avoid UAF and NPD bugs")
Reported-by: Thomas Osterried <thomas@osterried.de>
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ax25/af_ax25.c