Skip to content

Commit 320f150

Browse files
committed
Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg
jira VULN-470 cve CVE-2023-51779 commit-author Hyunwoo Kim <[email protected]> commit 2e07e83 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: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Hyunwoo Kim <[email protected]> Signed-off-by: Luiz Augusto von Dentz <[email protected]> (cherry picked from commit 2e07e83) Signed-off-by: Brett Mastbergen <[email protected]>
1 parent fabbb1f commit 320f150

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

net/bluetooth/af_bluetooth.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,14 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
264264
if (flags & MSG_OOB)
265265
return -EOPNOTSUPP;
266266

267+
lock_sock(sk);
268+
267269
skb = skb_recv_datagram(sk, flags, &err);
268270
if (!skb) {
269271
if (sk->sk_shutdown & RCV_SHUTDOWN)
270-
return 0;
272+
err = 0;
271273

274+
release_sock(sk);
272275
return err;
273276
}
274277

@@ -294,6 +297,8 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
294297

295298
skb_free_datagram(sk, skb);
296299

300+
release_sock(sk);
301+
297302
if (flags & MSG_TRUNC)
298303
copied = skblen;
299304

0 commit comments

Comments
 (0)