Monday, February 3, 2014

Linux 3.4+: arbitrary write with CONFIG_X86_X32 [CVE-2014-0038] (seclists.org)

Bug:
----
The X86_X32 recvmmsg syscall does not properly sanitize the timeout pointer
passed from userspace.

Exploit primitive:
------------------
Pass a pointer to a kernel address as timeout for recvmmsg,
if the original byte at that address is known it can be overwritten
with known data.
If the least significant byte is 0xff, waiting 255 seconds will turn it into a 0x00.

Restrictions:
-------------
The first long at the passed address (tv_sec) has to be positive
and the second long (tv_nsec) has to be smaller than 1000000000.

Overview:
---------
Target the release function pointer of the ptmx_fops structure located in
non initialized (and thus writable) kernel memory. Zero out the three most
significant bytes and thus turn it into a pointer to an address mappable in
user space.
The release pointer is used as it is followed by 16 0x00 bytes (so the tv_nsec
is valid).
Open /dev/ptmx, close it and enjoy.

Not very beautiful but should be fairly reliable if symbols can be resolved.

Tested on Ubuntu 13.10

Read here more. Here is an example code.