linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ax25: Fix NULL pointer dereference in ax25_kill_by_device
@ 2022-03-08  8:12 Duoming Zhou
  2022-03-09 12:50 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Duoming Zhou @ 2022-03-08  8:12 UTC (permalink / raw)
  To: linux-hams; +Cc: netdev, linux-kernel, kuba, davem, ralf, jreuter, Duoming Zhou

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: 4e0f718daf97 ("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>
---
 net/ax25/af_ax25.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index d53cbb4e250..6bd09718077 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -87,6 +87,13 @@ static void ax25_kill_by_device(struct net_device *dev)
 	ax25_for_each(s, &ax25_list) {
 		if (s->ax25_dev == ax25_dev) {
 			sk = s->sk;
+			if (!sk) {
+				spin_unlock_bh(&ax25_list_lock);
+				s->ax25_dev = NULL;
+				ax25_disconnect(s, ENETUNREACH);
+				spin_lock_bh(&ax25_list_lock);
+				goto again;
+			}
 			sock_hold(sk);
 			spin_unlock_bh(&ax25_list_lock);
 			lock_sock(sk);
--
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ax25: Fix NULL pointer dereference in ax25_kill_by_device
  2022-03-08  8:12 [PATCH] ax25: Fix NULL pointer dereference in ax25_kill_by_device Duoming Zhou
@ 2022-03-09 12:50 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-09 12:50 UTC (permalink / raw)
  To: Duoming Zhou; +Cc: linux-hams, netdev, linux-kernel, kuba, davem, ralf, jreuter

Hello:

This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:

On Tue,  8 Mar 2022 16:12:23 +0800 you wrote:
> 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:
> 
> [...]

Here is the summary with links:
  - ax25: Fix NULL pointer dereference in ax25_kill_by_device
    https://git.kernel.org/netdev/net/c/71171ac8eb34

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-09 12:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08  8:12 [PATCH] ax25: Fix NULL pointer dereference in ax25_kill_by_device Duoming Zhou
2022-03-09 12:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).