Skip to content

Commit 2e07e83

Browse files
V4bel-theoriVudentz
authored andcommitted
Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg
This can cause a race with bt_sock_ioctl() because bt_sock_recvmsg() gets the skb from sk->sk_receive_queue and then frees it without holding lock_sock. A use-after-free for a skb occurs with the following flow. ``` bt_sock_recvmsg() -> skb_recv_datagram() -> skb_free_datagram() bt_sock_ioctl() -> skb_peek() ``` Add lock_sock to bt_sock_recvmsg() to fix this issue. Cc: [email protected] Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Signed-off-by: Hyunwoo Kim <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]>
1 parent 04a342c commit 2e07e83

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

net/bluetooth/af_bluetooth.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,14 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
309309
if (flags & MSG_OOB)
310310
return -EOPNOTSUPP;
311311

312+
lock_sock(sk);
313+
312314
skb = skb_recv_datagram(sk, flags, &err);
313315
if (!skb) {
314316
if (sk->sk_shutdown & RCV_SHUTDOWN)
315-
return 0;
317+
err = 0;
316318

319+
release_sock(sk);
317320
return err;
318321
}
319322

@@ -343,6 +346,8 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
343346

344347
skb_free_datagram(sk, skb);
345348

349+
release_sock(sk);
350+
346351
if (flags & MSG_TRUNC)
347352
copied = skblen;
348353

0 commit comments

Comments
 (0)