Exploiting Uses of Uninitialized Stack Variables in Linux Kernels to Leak Kernel Pointers
Haehyun Cho, Jinbum Park, Joonwon Kang, Tiffany Bao Ruoyu Wang, Yan Shoshitaishvili, Adam Doupé, Gail-Joon Ahn
Exploiting Uses of Uninitialized Stack Variables in Linux Kernels - - PowerPoint PPT Presentation
Exploiting Uses of Uninitialized Stack Variables in Linux Kernels to Leak Kernel Pointers Haehyun Cho , Jinbum Park, Joonwon Kang, Tiffany Bao Ruoyu Wang, Yan Shoshitaishvili, Adam Doup, Gail-Joon Ahn Uninitialized variables in the stack
Haehyun Cho, Jinbum Park, Joonwon Kang, Tiffany Bao Ruoyu Wang, Yan Shoshitaishvili, Adam Doupé, Gail-Joon Ahn
2
void func () { int num; int ret; … } Kernel Stack
Base Base – 8n SP
0x 1111 2222 3333 4444 0x aaaa bbbb cccc dddd … … … … Kernel Stack
Base Base – 8n SP
3
void func () { int num; int ret; … }
4
void func () { int num = 0; int ret = 0; struct data_struct = {0,}; … } 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x dead beef 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 Kernel Stack
Base Base – 8n SP
5
void func () { int num = 0; int ret = 0; struct data_struct = {0,}; … } 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x dead beef 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 0x 0000 0000 0000 0000 Kernel Stack
Base Base – 8n SP
the user-space…
6
/* file: net/core/rtnetlink.c */ static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev) { //all fields in the map object are initialized struct rtnl_link_ifmap map = { .mem_start = dev->mem_start, .mem_end = dev->mem_end, .base_addr = dev->base_addr, .irq = dev->irq, .dma = dev->dma, .port = dev->if_port, }; //kernel data leak to the user-space if(nla_put(skb, IFLA_MAP, sizeof(map), &map)) return -EMSGSIZE; return 0; }
7
/* file: net/core/rtnetlink.c */ static int rtnl_fill_link_ifmap(struct sk_buff *skb, struct net_device *dev) { //all fields in the map object are initialized struct rtnl_link_ifmap map = { .mem_start = dev->mem_start, .mem_end = dev->mem_end, .base_addr = dev->base_addr, .irq = dev->irq, .dma = dev->dma, .port = dev->if_port, }; //kernel data leak to the user-space if(nla_put(skb, IFLA_MAP, sizeof(map), &map)) return -EMSGSIZE; return 0; } + 4 padding bytes
access the kernel memory
leave the kernel memory
8
In Linux kernel,
uninitialized data use bugs [2].
9
[1] Haogang Chen, Yandong Mao, Xi Wang, Dong Zhou, Nickolai Zeldovich, and M Frans Kaashoek. Linux kernel vulnerabilities: State-of-the-art defenses and open problems. In Proceedings of the 2nd Asia-Pacific Work- shop on Systems (APSys), Shanghai, China, July 2011. [2] KernelMemorySanitizer, a detector of uses of uninitialized memory in the Linux kernel. https://github.com/google/kmsan. [3] Kangjie Lu, Marie-Therese Walter, David Pfaff, Ste- fan Nümberger, Wenke Lee, and Michael Backes. Un- leashing Use-Before-Initialization Vulnerabilities in the Linux Kernel Using Targeted Stack Spraying. In Proceedings of the 2017 Annual Network and Distributed System Security Symposium (NDSS), San Diego, CA, February–March 2017.
In Linux kernel,
uninitialized data use bugs [2]. However, these vulnerabilities are commonly believed to be of low risks [3]. à not assigned any CVE entries and not patched in some cases
10
[1] Haogang Chen, Yandong Mao, Xi Wang, Dong Zhou, Nickolai Zeldovich, and M Frans Kaashoek. Linux kernel vulnerabilities: State-of-the-art defenses and open problems. In Proceedings of the 2nd Asia-Pacific Work- shop on Systems (APSys), Shanghai, China, July 2011. [2] KernelMemorySanitizer, a detector of uses of uninitialized memory in the Linux kernel. https://github.com/google/kmsan. [3] Kangjie Lu, Marie-Therese Walter, David Pfaff, Ste- fan Nümberger, Wenke Lee, and Michael Backes. Un- leashing Use-Before-Initialization Vulnerabilities in the Linux Kernel Using Targeted Stack Spraying. In Proceedings of the 2017 Annual Network and Distributed System Security Symposium (NDSS), San Diego, CA, February–March 2017.
Total Stack-base Heap-base # of exploits # of CVEs 87 76 11
11
“Potential of leaking kernel pointers and bypassing KASLR”
The number of information leak CVEs related to uses of uninitialized data between 2010 and 2019.
vulnerabilities that leak kernel pointer values.
(1) kernel functions or (2) the kernel stack.
12
data from the kernel stack base.
13
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x dead beef ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? Kernel Stack
Base Base – 8n
data from the kernel stack base.
14
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ffff ff04 ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? Kernel Stack
Base Base – 8n
data from the kernel stack base.
8 bytes.
15
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ffff ff04 ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? Kernel Stack
Base Base – 8n
16
PoVs Analysis Exploitability and exploits
Stack footprinting
17
0x 0101 0101 0101 0101 0x 0202 0202 0202 0202 0x 0303 0303 0303 0303 0x 0404 0404 0404 0404 0x 0505 0505 0505 0505 0x 0606 0606 0606 0606 0x 0707 0707 0707 0707 0x 0808 0808 0808 0808 0x 0909 0909 0909 0909 0x 0a0a 0a0a 0a0a 0a0a … … … … Kernel Stack
Base Base – 8n
Stack footprinting
18
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x 0404 0404 ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? … … … … Kernel Stack
Base Base – 8n
0x 0404 0404 ???? ????
Stack footprinting
à Leak offset = Base - 24
19
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x 0404 0404 ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? … … … … Kernel Stack
Base Base – 8n
0x 0404 0404 ???? ????
20
21
0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 0x 1122 3344 5566 7788 … … … … Kernel Stack
Base Base – 8n
22
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? … … … … Kernel Stack
Base Base – 8n
Kernel pointer to a kernel function Kernel pointer to the kernel stack
23
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? … … … … Kernel Stack
Base Base – 8n
Kernel pointer to a kernel function Kernel pointer to the kernel stack Offset : Base – 24 Type : Kernel code Syscall : mmap Args : 0,8,0,0,-1,0 Offset : Base – 64 Type : Kernel stack Syscall : mmap Args : 0,8,0,0,-1,0
allows users to make a program and execute it inside the kernel.
24
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? Kernel Stack Pointer to the base address
Spraying the frame pointer by crafting BPF instructions
allows users to make a program and execute it inside the kernel.
we can identify the layout of kernel stack
25
0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? 0x ???? ???? ???? ???? Kernel Stack Pointer to the base address
Spraying the frame pointer by crafting BPF instructions
à Guess and check!
0x ffff ff04 2000 0000
26
à Guess and check!
spraying (FP — 0x0000 0000 3000 0000)
27
0x ffff ff04 2000 0000 0x ffff ff03 ???? ???? Hidden data < 0x 3000 0000
à Guess and check!
spraying (FP — 0x0000 0000 3000 0000) spraying (FP — 0x0000 0000 1234 0000)
28
0x ffff ff03 ???? ???? Hidden data < 0x 3000 0000 0x ffff ff04 ???? ???? Hidden data > 0x 1234 0000 0x ffff ff04 2000 0000
29
30
1160 1224 1288 1352 1416 1480 1544 1608 1672 1736 1800 1864 1928 1992 2056 2120 2184 2248 6tacN offsets 10 20 30 40 50 60 70
1uPber of Sossible cases 3ointing to the Nernel stacN 3ointing to the Nernel code
64 128 192 256 320 384 448 512 576 640 704 768 832 896 960 1024 1088 6tacN offsets 10 20 30 40 50 60 70
1uPber of Sossible cases 3ointing to the Nernel stacN 3ointing to the Nernel code
Vulnerability Leak Size CVSS Exploitation Result CVE-2018-11580 4 bytes 2.1 Bypass KASLR CVE-2016-4569 4 bytes 2.1 Bypass KASLR Fixes: 372f525 4 bytes N/A Bypass KASLR CVE-2016-4486 4 bytes 2.1 Reveal the kernel stack base CVE-2016-5244 1 byte 5 Failed
31
Vulnerability Leak Size CVSS Exploitation Result CVE-2018-11580 4 bytes 2.1 Bypass KASLR CVE-2016-4569 4 bytes 2.1 Bypass KASLR CVE-2016-4486 4 bytes 2.1 Reveal the kernel stack base Fixes: 372f525 4 bytes N/A Bypass KASLR CVE-2016-5244 1 byte 5 Failed
32
Vulnerability Leak Size CVSS Exploitation Result CVE-2018-11580 4 bytes 2.1 Bypass KASLR CVE-2016-4569 4 bytes 2.1 Bypass KASLR Fixes: 372f525 4 bytes N/A Bypass KASLR CVE-2016-4486 4 bytes 2.1 Reveal the kernel stack base CVE-2016-5244 1 byte 5 Failed
Vulnerability Leak Size CVSS Exploitation Result CVE-2018-11580 4 bytes 2.1 Bypass KASLR CVE-2016-4569 4 bytes 2.1 Bypass KASLR Fixes: 372f525 4 bytes N/A Bypass KASLR CVE-2016-4486 4 bytes 2.1 Reveal the kernel stack base CVE-2016-5244 1 byte 5 Failed
33
34
35