Skip to content

Commit d475fa2

Browse files
Bluetooth: af_bluetooth: Fix Use-After-Free in bt_sock_recvmsg
jira VULN-465 cve CVE-2023-51779 commit-author Hyunwoo Kim <[email protected]> commit 2e07e83 upstream-diff We are missing f4b41f0 ("net: remove noblock parameter from skb_recv_datagram()") commit. The patch is clean otherwise. 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: Pratham Patel <[email protected]>
1 parent daece95 commit d475fa2

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
@@ -263,11 +263,14 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
263263
if (flags & MSG_OOB)
264264
return -EOPNOTSUPP;
265265

266+
lock_sock(sk);
267+
266268
skb = skb_recv_datagram(sk, flags, noblock, &err);
267269
if (!skb) {
268270
if (sk->sk_shutdown & RCV_SHUTDOWN)
269-
return 0;
271+
err = 0;
270272

273+
release_sock(sk);
271274
return err;
272275
}
273276

@@ -293,6 +296,8 @@ int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
293296

294297
skb_free_datagram(sk, skb);
295298

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

0 commit comments

Comments
 (0)