* [PATCH] ax25: fix NPD bug in ax25_disconnect
@ 2022-02-08 15:40 Duoming Zhou
2022-02-09 12:00 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Duoming Zhou @ 2022-02-08 15:40 UTC (permalink / raw)
To: linux-hams; +Cc: jreuter, ralf, davem, kuba, netdev, linux-kernel, Duoming Zhou
The ax25_disconnect() in ax25_kill_by_device() is not
protected by any locks, thus there is a race condition
between ax25_disconnect() and ax25_destroy_socket().
when ax25->sk is assigned as NULL by ax25_destroy_socket(),
a NULL pointer dereference bug will occur if site (1) or (2)
dereferences ax25->sk.
ax25_kill_by_device() | ax25_release()
ax25_disconnect() | ax25_destroy_socket()
... |
if(ax25->sk != NULL) | ...
... | ax25->sk = NULL;
bh_lock_sock(ax25->sk); //(1) | ...
... |
bh_unlock_sock(ax25->sk); //(2)|
This patch moves ax25_disconnect() into lock_sock(), which can
synchronize with ax25_destroy_socket() in ax25_release().
Fail log:
===============================================================
BUG: kernel NULL pointer dereference, address: 0000000000000088
...
RIP: 0010:_raw_spin_lock+0x7e/0xd0
...
Call Trace:
ax25_disconnect+0xf6/0x220
ax25_device_event+0x187/0x250
raw_notifier_call_chain+0x5e/0x70
dev_close_many+0x17d/0x230
rollback_registered_many+0x1f1/0x950
unregister_netdevice_queue+0x133/0x200
unregister_netdev+0x13/0x20
...
Signed-off-by: Duoming Zhou <duoming@zju.edu.cn>
---
net/ax25/af_ax25.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index 3e49d28824e..3d87040d1bf 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -92,8 +92,8 @@ static void ax25_kill_by_device(struct net_device *dev)
lock_sock(sk);
s->ax25_dev = NULL;
ax25_dev_put(ax25_dev);
- release_sock(sk);
ax25_disconnect(s, ENETUNREACH);
+ release_sock(sk);
spin_lock_bh(&ax25_list_lock);
sock_put(sk);
/* The entry could have been deleted from the
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ax25: fix NPD bug in ax25_disconnect
2022-02-08 15:40 [PATCH] ax25: fix NPD bug in ax25_disconnect Duoming Zhou
@ 2022-02-09 12:00 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-09 12:00 UTC (permalink / raw)
To: Duoming Zhou; +Cc: linux-hams, jreuter, ralf, davem, kuba, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller <davem@davemloft.net>:
On Tue, 8 Feb 2022 23:40:00 +0800 you wrote:
> The ax25_disconnect() in ax25_kill_by_device() is not
> protected by any locks, thus there is a race condition
> between ax25_disconnect() and ax25_destroy_socket().
> when ax25->sk is assigned as NULL by ax25_destroy_socket(),
> a NULL pointer dereference bug will occur if site (1) or (2)
> dereferences ax25->sk.
>
> [...]
Here is the summary with links:
- ax25: fix NPD bug in ax25_disconnect
https://git.kernel.org/netdev/net/c/7ec02f5ac8a5
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-02-09 12:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-08 15:40 [PATCH] ax25: fix NPD bug in ax25_disconnect Duoming Zhou
2022-02-09 12:00 ` 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