All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] L2CAP: Fix null-ptr-deref in l2cap_sock_set_shutdown_cb
@ 2023-01-19  1:34 Sungwoo Kim
  2023-01-19  1:40 ` BUG: KASAN: null-ptr-deref in _raw_spin_lock_bh+0x4c/0xc0 Sungwoo Kim
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Sungwoo Kim @ 2023-01-19  1:34 UTC (permalink / raw)
  Cc: daveti, wuruoyu, benquike, Sungwoo Kim, Marcel Holtmann,
	Johan Hedberg, Luiz Augusto von Dentz, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	open list:BLUETOOTH SUBSYSTEM, open list:NETWORKING [GENERAL],
	open list

The L2CAP socket shutdown invokes l2cap_sock_destruct without a lock
on conn->chan_lock, assigning NULL to chan->data *just before*
the l2cap_disconnect_req thread that accesses to chan->data.
This patch prevent it by adding a null check for a workaround, instead
of fixing a lock.

This bug is found by FuzzBT, a modified Syzkaller by Sungwoo Kim(me).
Ruoyu Wu(wuruoyu@me.com) and Hui Peng(benquike@gmail.com) has helped
the FuzzBT project.

Signed-off-by: Sungwoo Kim <iam@sung-woo.kim>
---
 net/bluetooth/l2cap_sock.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index ca8f07f35..350c7afdf 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1681,9 +1681,11 @@ static void l2cap_sock_set_shutdown_cb(struct l2cap_chan *chan)
 {
 	struct sock *sk = chan->data;
 
-	lock_sock(sk);
-	sk->sk_shutdown = SHUTDOWN_MASK;
-	release_sock(sk);
+	if (!sk) {
+		lock_sock(sk);
+		sk->sk_shutdown = SHUTDOWN_MASK;
+		release_sock(sk);
+	}
 }
 
 static long l2cap_sock_get_sndtimeo_cb(struct l2cap_chan *chan)
-- 
2.25.1


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

end of thread, other threads:[~2023-01-20 22:10 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-19  1:34 [PATCH] L2CAP: Fix null-ptr-deref in l2cap_sock_set_shutdown_cb Sungwoo Kim
2023-01-19  1:40 ` BUG: KASAN: null-ptr-deref in _raw_spin_lock_bh+0x4c/0xc0 Sungwoo Kim
2023-01-19  2:04   ` [PATCH] L2CAP: Fix null-ptr-deref in l2cap_sock_set_shutdown_cb Sungwoo Kim
2023-01-19  2:46     ` bluez.test.bot
2023-01-19  3:57   ` BUG: KASAN: null-ptr-deref in _raw_spin_lock_bh+0x4c/0xc0 Eric Dumazet
2023-01-19  2:44 ` L2CAP: Fix null-ptr-deref in l2cap_sock_set_shutdown_cb bluez.test.bot
2023-01-19  4:16 ` [PATCH] " Eric Dumazet
2023-01-20 22:09   ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.