summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHillf Danton <hdanton@sina.com>2020-02-05 10:31:59 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2020-10-01 13:14:32 +0200
commit4b0795d5b615de48541eae1a87b5a37543e1c17f (patch)
treeb393b5a3a5b90492ec4fdd64568e6003eef02462
parentf9cb6b6124ac3e1586251329e51b898f1d0a54e6 (diff)
downloadlinux-stable-4b0795d5b615de48541eae1a87b5a37543e1c17f.tar.gz
linux-stable-4b0795d5b615de48541eae1a87b5a37543e1c17f.tar.bz2
linux-stable-4b0795d5b615de48541eae1a87b5a37543e1c17f.zip
Bluetooth: prefetch channel before killing sock
[ Upstream commit 2a154903cec20fb64ff4d7d617ca53c16f8fd53a ] Prefetch channel before killing sock in order to fix UAF like BUG: KASAN: use-after-free in l2cap_sock_release+0x24c/0x290 net/bluetooth/l2cap_sock.c:1212 Read of size 8 at addr ffff8880944904a0 by task syz-fuzzer/9751 Reported-by: syzbot+c3c5bdea7863886115dc@syzkaller.appspotmail.com Fixes: 6c08fc896b60 ("Bluetooth: Fix refcount use-after-free issue") Cc: Manish Mandlik <mmandlik@google.com> Signed-off-by: Hillf Danton <hdanton@sina.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--net/bluetooth/l2cap_sock.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index d128750e4730..5572042f0453 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -1190,6 +1190,7 @@ static int l2cap_sock_release(struct socket *sock)
{
struct sock *sk = sock->sk;
int err;
+ struct l2cap_chan *chan;
BT_DBG("sock %p, sk %p", sock, sk);
@@ -1199,15 +1200,16 @@ static int l2cap_sock_release(struct socket *sock)
bt_sock_unlink(&l2cap_sk_list, sk);
err = l2cap_sock_shutdown(sock, 2);
+ chan = l2cap_pi(sk)->chan;
- l2cap_chan_hold(l2cap_pi(sk)->chan);
- l2cap_chan_lock(l2cap_pi(sk)->chan);
+ l2cap_chan_hold(chan);
+ l2cap_chan_lock(chan);
sock_orphan(sk);
l2cap_sock_kill(sk);
- l2cap_chan_unlock(l2cap_pi(sk)->chan);
- l2cap_chan_put(l2cap_pi(sk)->chan);
+ l2cap_chan_unlock(chan);
+ l2cap_chan_put(chan);
return err;
}