Skip to content

Commit

Permalink
Bluetooth: fix possible info leak in bt_sock_recvmsg()
Browse files Browse the repository at this point in the history
In case the socket is already shutting down, bt_sock_recvmsg() returns
with 0 without updating msg_namelen leading to net/socket.c leaking the
local, uninitialized sockaddr_storage variable to userland -- 128 bytes
of kernel stack memory.

Fix this by moving the msg_namelen assignment in front of the shutdown
test.

Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: Johan Hedberg <johan.hedberg@gmail.com>
Signed-off-by: Mathias Krause <minipli@googlemail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
minipli authored and davem330 committed Apr 7, 2013
1 parent ef3313e commit 4683f42
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/bluetooth/af_bluetooth.c
Expand Up @@ -230,15 +230,15 @@ int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
if (flags & (MSG_OOB))
return -EOPNOTSUPP;

msg->msg_namelen = 0;

skb = skb_recv_datagram(sk, flags, noblock, &err);
if (!skb) {
if (sk->sk_shutdown & RCV_SHUTDOWN)
return 0;
return err;
}

msg->msg_namelen = 0;

copied = skb->len;
if (len < copied) {
msg->msg_flags |= MSG_TRUNC;
Expand Down

0 comments on commit 4683f42

Please sign in to comment.