Hello, I'm just going to test the mic and make sure that I have the right distance to the microphone here. So, a couple of days ago I presented at Black Hat this same presentation, so I'm going to give it to everyone here today at DEF CON. The first thing I said at Black Hat, I suppose, was I wanted to achieve two things. And one of those things was not freaking out on stage, and I hope I don't freak out on stage today. And the second thing was to give people insight into where kernel security stands today and what sort of bugs are present, how many bugs are present, what forms of exploitation are available. And that is what my presentation is on, kernel auditing and exploitation. So there are three parts in today's presentation. At the end of each part we'll stop for questions. But feel free to jump in with your questions. If you have any questions, if you want to. So the three parts are the auditing research that I performed, a sample of exploitable bugs, and exploitation on some of those bugs. So part one is kernel auditing research. So last year for about three months, between July and September 2002, I performed a manual audit of the various open source kernels. And the OSs here were FreeBSD, NetBSD, OpenBSD, and Linux. This was a part-time audit, so I wasn't spending 24-7 or even eight hours a day or anything. It was just spare time that I had available. I just audit various bits of kernel source. So just to give a time frame of how much auditing was done on each kernel. NetBSD was about a little less than a week. FreeBSD a little less than a week also. OpenBSD was a couple of days. And Linux was the rest of my free time. Why did I audit Linux so much? Probably just because I use Linux a lot. I run it on this computer and most of my PCs. So unfortunately Linux was a little heavy-handed in my auditing because I do enjoy Linux. So what prior work has been done? On kernel auditing and so forth. There has been some prior work here. Probably the best that I think that I've seen is Dawson Engler's research. In the past couple of years he has released a number of papers. Some really great papers actually. Where basically he wrote an automated bug discovery tool using a language called Metal. And he released some papers on this. And to do this research he applied this automated bug discovery. On large sources. Namely being the operating systems kernels. So NetBSD, actually OpenBSD, Linux and FreeBSD he certainly performed automated bug discovery on. And actually he sent most of those bugs I think to the Linux kernel mailing list. And found a lot of concurrency and synchronization issues. Issues such as double locks, double unlocks. That seems to be... He also found a number of buffer overflows. And this was all automated. But most of the bugs that were reported were concurrency and synchronization. The Linux kernel auditing project is an interesting one here. There's a bit of a question mark at the end of this line. And the reason for that is I've never actually seen the Linux kernel auditing project do anything. They've got a mailing list. But there's very few posts to it. I think they released about two advisories. For some issues that were already known. And they never really... Like in my opinion they really didn't audit the Linux kernel. They talked about possibly let's audit the Linux kernel. But I don't think they actually did. Because there are places in the kernel source where you just... They have comments saying it's totally broken. Please don't use. And these bits of code are totally exploitable. So just some notes for the rest of the presentation. When I'm talking about bugs. I'm always going to be talking about vulnerabilities. I just... Vulnerabilities is a really long word. So I'll just say bug. Unless I state otherwise. And just to sort of summarize what happened after the end of these three months of auditing. I think in conjunction with the kernel developers and whatnot. At least 150 bugs were patched. And pretty much all of these were patched. They were exploitable. So I'm just going to like... In my view there seems to be... There seem to be a lot of bugs in the kernels from what I've seen. But not many people seem to be auditing them. Or if they're auditing them... I don't know. So I believe that there are certain myths. Or a bit of mythology around kernel source. And one of the myths I'm talking about here is that... Maybe it's assumed by people that kernels are written by security experts and programming gods. And certainly kernel developers... Some kernel developers are exceptionally talented and incredible programmers. But... There's a lot of kernel source here. A lot of developers get involved. And so the follow-up to this myth is... If the kernels are written by security experts and programming gods... They really mustn't have any security bugs. And if they have security bugs, they're not really simplistic. And I suppose that leads on to the next myth. Is that... It's just a rewrite of the first one. Is that kernels never have simplistic security bugs. Therefore only security experts or programming gods can find them. And I would disagree with this considerably. And I show evidence to... In contradiction to this by showing simple bugs that are exploitable. And so forth. I've got one more final myth. That... Again, a follow-up to the second one and the first one. That if kernels are buggy... Incredibly difficult to exploit. And therefore probably exploitation is just theoretical. Maybe you've heard that there are bugs. But they require something to be happening while something else is going on. And maybe the disk light is flashing a bit. These types of... These are the myths that I hear and I see. And I try to show evidence to contradict this. Because there are simple bugs in the kernel. Simple bugs to exploit. There are simple mistakes that are obviously spotable. So I make some conjectures for the auditing. That kernel code isn't special. It's just another program. It's a big program. It's a big, big program. But it's just another program. There's certainly a lot of bugs in user land. So why not the kernel as well? And one of the reasons for this is that... I believe this is that... These kernels are written in the same language that... The language of C that has had so many problems in the past with user land programs. User land programs generally written in C. Lots of bugs. Why do people not think the kernel is the same? And certainly... My conjecture is that kernel programmers do make mistakes. Just like everyone else. You know... If someone's... An average kernel is, say, a couple million lines of code. Are we expecting that one million or ten million lines of code is 100% bug-free? That a simple mistake hasn't occurred somewhere in this? It takes a long time just to look at five million lines of code. Let alone audit every single line there. So I started with a bit of a methodology for the auditing here. But the... I was only going to audit simple classes of bugs. Not going to look for really complicated, you know, ways of attacking the kernel. You know, if your disk light is flashing and, you know, maybe something is going on in the background. And you're paging something. Not going to go for any bugs like that. Not going to go for any attacks on algorithms or so forth. Just target really simple classes of bugs. And one of the ways of... To do this... Was to audit using bottom-up techniques. So basically find places in the code that, if were buggy, could probably be exploitable. And the way that I'd do this would be basically to grep for good places. And from that, look at the code around it. And if that code is buggy, it's probably exploitable. So looking for good entry points into the kernel. Now, kernel-to-userspace copies and userspace-to-kernel copies. Buffer copies. A very good place to look. If these bits of code are buggy, then certainly buffer overflows and other problems are likely to be exploitable here. As the auditing continued over the period of months, certainly I got more experience in what sort of things I should be looking for. And the number of classes of bugs and exploit classes certainly increased. So for example here, system calls are simple entry points. If you look from going to user land to kernel land and exploiting the kernel, system calls under the control of user land, maybe they're exploitable. I think, though, that a lot of people, from what I've heard, if they've gone to audit the kernel, they look at system calls and they think, Okay, let's go for the core system calls. Maybe there's a bug there. But there's in fact... You know... A lot of other places also that you can audit, such as the device drivers. These, again, have simple entry points. Primarily for the fact that in Unix everything, you know, really... The idea was that everything should be considered a file. So you can access a lot of code, a lot of kernel code, through these device drivers. IOCTLs seem to do everything. They're so generic. They basically can do anything and everything that you want and probably more. They increase the attack vector space massively. And it's argued that for Unix, everything is a file. What's the point of IOCTLs for this? IOCTLs break the design of Unix to say that everything is a file by introducing a system call that does everything at this point. So some of the Unix designers argue that that was a bit of a downfall of Unix at that point. I don't think so, though. It's certainly interesting. So there were some immediate results in the auditing here. The first bug was found within hours. And this was true for all systems audited. And it's arguable that the first bug in a non-familiar software is arguably the hardest to find. Once you start to have places to look for and ideas of what types of bugs are present, it's typically considered easier to find more bugs. So a couple of observations here. There does seem to be evidence of varying degrees of code quality, and hence security bugs. The core kernel code in all the systems audited was pretty good. Not so many problems there. There were a couple, but ultimately it seemed to be a lot more bug-free than, say, for example, device drivers, which pretty much anyone can write, make a submission for all the OSs here. So they did, in my opinion, seem to contain a large number of bugs. And I also make the comment that bug tends to exhibit signs of propagation and clustering. So what I mean by this is that, say, for example, you have a device driver, and this device driver, this code for this device driver, becomes the reference implementation. And this reference implementation has a bug in it. And now everyone, when they go to write their device driver, copies the buggy reference implementation, and thus the bug propagates with the security problems associated with it. The clustering observation is also that of, once you find a bug in a particular bit of source, you're probably more likely to find bugs nearby as well. So if you start to find bugs in, say, the video for Linux drivers, maybe there are more bugs in other video for Linux drivers. Maybe in the file system code, look around, probably more bugs around that area as well. And there are identical bugs across all platforms. And I'll show you some examples of this. It's not like the asterisks and the bracketed two stuff, just in reference to some slides coming up. But just before I get into that, just a bit of research bias. Manual auditing is inherently biased. Certainly I can't argue definitively that these observations are scientifically correct, because my auditing is inherently biased. Maybe I believe that core kernel code is more secure, hence I'm not finding bugs in that. It's hard to argue through scientific means. However, Dawson Engler's work with the automated bug discovery is less biased since it is not done by a human. It is done by an automated process which can be repeated time and time again and so forth. So just some code in reference to having the same bugs across a number of platforms. We have here NetBSD and OpenBSD. This was a couple of versions ago. And it's a bad example to show, to start off. And I should have changed this slide. But because you can't see the exact part where it's exploitable, you can just see part of the bug here. So I've highlighted... I don't think anyone can see this because I can't even see this from here. So basically I've... It's in the I386 set LDT code. We're adding two numbers together. Start plus num and checking if it's greater than another. And this is input validation checks. However, the problem is that when we add these two numbers together, we can get a sign wrap around, end with a negative number, pass this input validation check, and then a couple of lines afterwards we have a buffer copy which now uses the failed input validation check. These have been fixed since, so they shouldn't be current in any systems. So just to show some evidence in contradiction to the myths that I presented earlier, is that kernels aren't written by gods. You know, very talented, but not in the godly manner that the myth holds them to. So the initial bugs were found in all hours, and bugs were found in large quantities. 10 to 30 per day, which wasn't really uncommon. You know, in various places of the source, lots of bugs were present. And it was assumed in SATA that code was secure when in fact it wasn't. This is actually pretty funny, to be honest. So this is in Linux 2.4.18. And this is in the video for Linux code, I think. One of the drivers for that. So the comment is that, okay, first things first, make sure we don't copy more than we have, even if the application wants more. That would be a big security embarrassment, with an exclamation mark at the end. The very next line, the exact next line of this comment is an integer overflow. Okay. So about two lines below that is a buffer overflow as a result of the integer overflow. So it's a very interesting comment, certainly. There is another interesting comment. And there's a few interesting comments in the code. And I'll show some more a bit later on. But for this comment, it has, this routine does error checking to make sure that all memory accesses are within bounds. And then what we have, we have multiple problems in this code. We have a sign problem. We pass in a sign integer and do a comparison, but we don't check for the case when it's less than zero. We also have an integer overflow. Even if we got this sign problem fixed, we would have an integer overflow in the lines below. And then we have a buffer overflow after all of that. So, you know, they're pretty funny comments. I don't know. Maybe it's just my bad sense of humor. So some more evidence in contradiction to kernel mythology. Kernels really do have simplistic bugs. You know, I really didn't do any intensive code tracking for this audit. I really, you know, scrapping for simple places, gripping for good places to look, and then from there looking at code immediately above it. I didn't really, you know, I wasn't starting at the, you know, init.c or, you know, wherever here. I didn't start at a boot sector and follow it all the way to what happens when you, you know, fork. Just find simple places to audit and look at the immediate code around it. And certainly, in some cases, there was simply just no input validation at all. Also, inline documentation shows that, you know, code is not working. I should have some examples here. So we have this bit of code, ibcs2-stat.c And this is in all systems, actually. OpenBSD, NetBSD, FreeBSD, and Linux. The bug was shared across all platforms. FreeBSD have not fixed this. I don't know why. So basically, we pass in a length to a syscall. The length is just never validated. We copy a buffer using this length. And there's no, you can put a length of anything. Any length you want and it will copy that. So, you know, no input validation at all. Here is another no input validation bug. This one is copying from kernel space to user space. So this will give us kernel memory disclosure. And again, it's from a VGA driver here. So, video driver. Of some kind. Looks like to be NetBSD, I think. So we're going to call an IACTL. And then we can pass in a count of whatever we want. We just pass in a length. And it will just copy this back to user space. Okay, here's another bit of code. This one is in Linux. And this one is still present in Linux. I released this and an exploit for it a couple of months ago at RuxCon. And it doesn't seem that, you know, it hasn't been fixed. So I'm not quite sure what the story is there. So we have a comment. And this is in the Cough binary loader. It has a comment saying XXX untested. And, like, I can really guarantee that it's never been tested because if anyone used this it would kernel panic immediately. It's using the wrong arguments completely. There's no possible way it can work. But in this case it turns out to be exploitable. And we can escalate privileges and get a root shell by running a custom Cough binary. So, some more evidence in contradiction to kernel mythology. Kernels, if they're buggy, are not always difficult to exploit. To exploit 100% reliably procfs bugs in Linux to perform memory disclosure is 38 lines. For FreeBSD this is a custom call advisory that was released last year. 37 lines of C. FreeBSD and Linux the developers of respective developers both have exploits for these by the way. I did send the exploits that were written to them. Also an interesting thing a stack overflow in Linux requires no offsets. It's very very reliable. It assumes correctly that addresses that return addresses that's the only assumption it really makes to perform stack overflow in Linux. And in GCC it will always align return addresses. Actually when I presented this at Blackhat a couple days ago I was saying that I said exactly the same thing but I didn't want to make I didn't want to say 100% certain always will be aligned. So I said GCC should, I'm pretty sure of that. But some guy did come up to me after the presentation and said yes I can, it's definitely 100% true that GCC will never have anything that isn't word aligned. So it's just a bit of a note there. So what attack vectors are present at the result of auditing all this code and finding bugs and exploits it does seem clear that the more code there is that's running the more vulnerabilities likely to be present. Which is a pretty casual observation there. But the follow up to that is don't run these kernels that have everything compiled into them under the sun. Don't have support for hardware that you don't use. Don't have a million device drivers just running because all of these increase the attack space that you leave open. So definitely you can mitigate some risks there if you just compile smaller kernels and don't have so much support there for things that you don't use. So entry points into the kernel that use a lanker control are certainly the vectors of exploitation here. And device drivers, system calls, file systems. File systems are interesting. Load code in Linux, procfs in most of all of 2.2 and most of 2.4. I think there's some in the 2.6 tests at the moment. And certainly in most of the 2.5's as well. You can do things like lseek. If you can open a file in the procfs and it's readable by world, readable by everyone. So you open it, you seek to around 4 gig on 32 bit platforms. Seek to around 4 gig and then if you read something that you might be able to cause an integer overflow for around 4 gig plus what you read. Get an integer overflow and then you can have things like memory disclosure. Also just to make one more comment on that last slide. Is that the core kernel code again is pretty good like in most kernels. Not, you know, couple of bugs there but nothing major there. I think someone read the slide there with three minutes. Just heard a bit of laughter. The vendor response actually was really strong. Contacted everyone and everyone responded extremely well. sent an email, turned around, having a conversation with someone, turned back, under three minutes got a response. Sent a list of 10 to 15 bugs and in three minutes got a response on these. I think that's not bad. Alan Cox was pretty good. He was the first person that I sent bug reports and vulnerabilities to. Sent him a list of bugs for I think 2.2.16 at the time. This was like 2.4. something was current. It wasn't even the latest 2.2 version. Some old Linux kernel that no one was really using. In about three hours, a couple of hours, he sent back a list. He sent back information on all of the bugs that I had reported. Some of the bugs he said we fixed that in later 2.2 or in 2.4. He could actually name the people that had fixed bugs from one to two years earlier saying that Solid Designer had fixed various bugs. Things, for example, such as the getsockopt, setsockopt, signproblems from most of 2.2. That was pretty impressive, I thought. Just before I get too much into this, I am a little biased myself. I still believe in open source software. Even though I think the responses that I received were exceptional, it's a little biased there. Maybe the reason why open source response was so good was that they didn't have a marketing department. I emailed developers directly, people that actually code on these kernels. Maybe the only thing I could argue was source at that point. I don't know. A bit more bias. I don't know if anyone can see this. A bit of a grep for the bit of grep for hack. The number of references of the word hack in the 2.4.19 Linux kernel credits, 106 times. I don't know. I have a really bad joke. It's a bad joke. I gave it a blackout. No one laughed. A lot of hacks in the Linux kernel. No one laughed here again. So... Comedy, not my strong thing here. Just to talk about Linux here. A bit more about each vendor's response. Alan Cox, the first person I contacted, he remained personally involved and responsible for the entire duration. Sent tons and tons of bugs. He fixed the majority of software, patched a lot of things. Often attributed me with in the credits, with small patches and whatnot, in change logs. And even though these were one to two lines of code and were quite sort of obvious of what needed to be fixed. It was unusual that he attributed me for those. Solid Designer was responsible for the 2.2 Linux kernels. He was the person that was, I think, if you look back last year, the 2.2 kernel was released after some long period of time of not releasing another 2.2 kernel. And that was really Solid Designer doing all of that work. Backporting a lot of bugs from 2.4 as well. Dave Miller initially started on the Spark patches and whatnot. And then started to help in sort of generic stuff as well. So, in my opinion, Linux was probably the biggest success here. Certainly, Red Hat released an advisory last year about the 2.4 kernels. I think 2.4 or 19 or 18. And they were pretty political in their advisory, referencing the DMCA and saying stuff like we'd like to give you information on these vulnerabilities, but we can't because maybe the DMCA affects this. So if you go to another website that's outside the US, you'll be able to see specific information on each of the bugs that were fixed. That was interesting, I thought. But now it seems now it seems that Red Hat, along with most of the other Linux vendors, do release kernel advisories, which seems to be fantastic. They do release regular kernel advisories now. So, you know, it seems probable that this was probably attributed to the auditing work that was done last year. So, in my opinion, that was probably the biggest success story there. The irony is that there was the Linux kernel auditing project, but it seems that the way it performed last year was probably the most complete for Linux at that time. What about FreeBSD? FreeBSD certainly has a more formalised process with vulnerability disclosure and bug patching and whatnot. They've got a security officer contact point. It took me a bit longer to get a reasonable dialogue with them. I'm not talking weeks here, but I think it was like, a bit less than a week, I think, it took me to establish a really good dialogue there. But they were pretty effective once dialogue was established. They addressed a standardisation issue, which I haven't really described in my slides, but for one particular point, if we look at Linux 2.2 and if we look at Linux 2.2, there's the getsockop, setsockop code. The problem for that was that the socket option length could be a negative and when it was a negative, it would cause memory disclosure. A very similar problem with FreeBSD with the accept system call. The length of the socket address structure could be a negative and when it was, it would cause memory disclosure again. The good thing that FreeBSD did was that they said, okay, let's change this type def for the socket address length to be unsigned, which essentially, in my opinion, will solve problems that they haven't foreseen in the future. Unfortunately, the way that Linux went about fixing that, and it was unfortunate in some respects, because there was so many specific bugs in the getsockop code for various protocols and whatnot, what was done was that a check very early on in the code was performed to check for the negative case. It solved lots and lots of problems from hidden subsections of code that had the same sign bug, but my opinion was I would have liked that to be unsigned. So, was FreeBSD a success? They released an advisory last year with the accept system call again and this was a bit of a surprise. I'm working at a vulnerability company at the time and a co-worker happens to be that guy sitting right there comes up to me and says that he's going to implement my vulnerability and I'm like, what vulnerability, what are you talking about? And he's like, FreeBSD have released an advisory on the accept system call. So, I don't know, thanks FreeBSD. I really did not know about that and I saw the advisory, I think on BugTracker, like everyone else. So, NetBSD, I didn't speak to NetBSD for too long, but they did resolve all issues. I think what happened with that, it took me about a week before I could really talk to, have a good dialogue with someone and then it was about a week before they actually pushed patches into the main tree, the main development tree at this point. I think what was happening in the second week was that some guy had done the changes, though very simple changes, done the changes on his own box and was doing a bit of personal QA and then pushed it for the other developers to look at as well back in the main unstable development tree. Which is very typical in a development process. So, if we look at OpenBSD now, probably the quickest response in documented history. Three minutes is pretty fast. I can't get my mum to email me in three minutes. That's insane, it's three minutes. Interesting thing with OpenBSD though was that they released an advisory for the select system call stack overflow there. This was shortly after I sent them about 10 to 15 bugs and some of these bugs a bit after that they released the select advisory. What I think happened in that period of time was that Niels and probably other people in OpenBSD started at least a more concerted effort, if not the initial effort, I'm not quite sure, to do kernel audits here. So I think that was reasonably successful. Certainly they started to look at other issues then as well. Interesting thing also with NetBSD which I probably should have mentioned a bit before. When I sent NetBSD a list of problems some of the bugs were actually shared with OpenBSD as well. Which isn't too surprising. The bugs that were shared were primarily just driver code. Again, it's not surprising since OpenBSD can be considered a fork from NetBSD some time ago now. But some of the drivers are shared and some of the bugs were present in both. OpenBSD did take the patches for these things anyway for NetBSD propagated to OpenBSD pretty quickly but it was surprising to see the change logs in OpenBSD because it's like from NetBSD those are the integer overflows and the driver problems there and what not. So I've got a couple of I've got one change log here from the OpenBSD from OpenBSD. There's another good change log entry which I probably should have included but I'll just talk about this one for a sec. So this is the IBCS2 code that I showed earlier which had no input validation checking at all and the comment in the change log is that more possible integer overflows are found. So there were no integer overflows. It's just no input validation check. Another interesting change log entry and this was for a couple of them were it was I'm just trying to think back to the exact wording here it was more possible integer overflows found by yada yada yada some of these are okay but have been changed for consistency and in fact all of these were exploitable. It wasn't some of these are okay. Those patches they were all exploitable. So I think OpenBSD is certainly very good but it's certainly interesting change logs as well. So the IBCS2 stat.c code Linux fixed it, OpenBSD fixed it, NetBSD fixed it, FreeBSD I don't know why they've never fixed it. I've sent them this and they've just not fixed it. I don't know why. I'm really at a loss to say. And I also explain this at black and I'll explain it here. The reason why there is a square next to the FreeBSD line is that this actually was a powerpoint import into OpenOffice and it didn't have the font for the smiley face. So that's the reason for the square up there. There should have been a smiley face, a frown but oh well. So where are we today in kernel security? Auditing today always results in vulnerabilities being found. There are bugs still present in all the kernels and this isn't surprising because auditing and security really is or should be an ongoing process. You can't just audit something at some point in time and say it's going to be secure indefinitely. And certainly even though I will present a number of bugs and a number of bug classes there's certainly more things that are exploitable and certainly a lot more classes of bugs in the code as well than will just be described today. So a couple of months ago presented most of the bugs, a very technical presentation like basically I was going through lists and lists of bugs and saying about four months ago at Ruxcon and released some zero day at the time and some of those bugs are still present. I don't know why. So the cough loader for Linux and exploit is available for that on the Ruxcon website but I've never actually posted an advisory or posted anything to full disclosure or bug track or whatever. It's never been fixed. An obvious question does anyone read the conference materials and do it and does anything about it? Are we just presenting things for ourselves or what? So at this point I'm going to pause for audience participation and ask if there are any questions. Okay, I've actually got a pretty interesting question here. The question was that when I talked about bugs being clustered he was asking me if that was because of the way I was auditing and I suppose my response to that is I can't really present scientifically that bug clustering exists. All I can say is that I observed in my opinion bug clustering and it's possibly supporting evidence and Dawson Engler's work certainly talks about bug clustering and bug propagation and that's probably certainly more scientific than the methods that I use which manual auditing. I must admit I did look at certain bits of source and the sources around it in a reasonably close time frame so maybe that was the reason why I saw bug clustering. But it's a good question. Okay, I'll go to the next part of the presentation which is a sample of exploitable bugs. I'm actually going to it looks like I'm running really long here so I'm going to actually skip a few of the slides here. Okay, I've got a ten minute sign up there which is pretty good. I'm going to go through a couple of bugs and go through a couple of classes of ways, a couple of ways to exploit them as well. Sample of exploitable bugs. This was, okay, I'll just skip to something that's more interesting. If you want to you know, if anyone wants to talk to me about this after the presentation, that's fine. So I'll go to something that's, okay, this one is interesting. What we have here is that we have, and I know that no one can read this so I'll try to explain it. We have a memory allocation and we have memory allocation of something like a size of, a long times, you know, something plus a one and then down below we have a copy out call which is a kernel buffer copy from kernel space to user space and the copy out call does something like a size of, a long times, you know, this size thing and so basically one of the problems that I've seen a lot in programming is that when people are doing things like memory allocations and using one expression to calculate these lengths and then they're doing buffer copies using these you know, these other expressions or they're doing input validation checks using one expression and then buffer copies using another expression, typically always they lead themselves into problems because you can, many times you can get, you know, the first expression to do, you know, come out with one answer and the second one to come out with something else using integer overflows and what not so that seems to be a problem that exists, when you see code like that and they say okay they're using one expression here and another expression down below it's very, very often that it's exploitable in some way. This one, another interesting case we take a minimum here a minimum of two values one of those values we control from a syscall argument but the point here is that we control a syscall argument and we can make it a negative so when we take the minimum of these two values here you know, we're going to come up with a negative so then we do a copy out later on using this length which is was a negative now becomes a positive I got a sign that I had five minutes ago so I'll I'll skip most of these actually and I'll go to some ways to exploit Here's an example of what I was just talking about a second ago we have a validation check on this count value here this is in the PCI hot plug core.cq which is Linux code and we seem to have lost one of the I'll look at this one now we seem to have so we do a validation check on this count and we check if count is less than or equal to zero but then we do a memory allocation using count plus one so now we have integer overflow when we make count the size of uintmax we can get count plus one to wrap around back to zero and k-mallocing zero bytes will return successful providing we can perform a memory allocation to begin with interesting bug that I really do want to talk about this is very prevalent in a lot of the 2.2 Linux code and most of the 2.4 this is what I was talking about before when you lseq to around 4 gig we take the file pointer which typically is 64 bits but in some cases people screw up the prototypes and that causes problems and they cast it to a int and then they've had the file pointer which is cast now as 32 bit sign value plus the count which we're reading and that itself is an integer overflow and causes memory disclosure later on ok I'm going to skip at this point to some ok I won't pause for audience participation and kernel exploitation so there are two things that are two classes of exploits that we should look at here arbitrary code execution and information disclosure so for arbitrary code execution obviously the best form of exploitation that we have can give us a root shell privilege escalation escape kernel sandboxing security enhanced linux for example user mode linux if we look at digital rights management say for example we have a certain kernel version or a certain distro that is signed and it says that when you view this website you can't actually save any streaming content or so forth however if we have vulnerabilities in this software we can control it at that point and we can make the software do something else than what the DRM people say it should do ultimately in the trusted computing doesn't actually provide any software assurance trusted computing is basically just breaking policy at well defined sequence points and having trust relationships but if your trusted computing base or so forth is vulnerable or has hidden features then you know certainly other things are possible there seems to be the case if your trusted computing base is flawed and certainly in all of these things the kernel is seen as the trusted entity then ultimately system security is compromised we have information disclosure as well such as thank you and we will now SSH private keys if we can read arbitrary kernel memory we might be able to sneak out an SSH private key I will just pause for one second I have 10 minutes 5 minutes is fine yeah you can get 5 minutes okay 5 more minutes and I will be tackled off stage so I'm going to I'll try to get in as much as possible here has been prior work to kernel exploitation Noir in FRAC 60 wrote a great article on smashing the kernel stack for fun and profit this was an implementation of exploiting the open BSD kernel stack overflow there have been other exploits in the past from Dolores and FreeBSD and what not but in the general case it's seen that there aren't generic ways of attacking the kernel which was probably a good thing otherwise because he showed a class of bugs there kernel implementation all the kernels are written in C C has known bugs known problems known pitfalls attack the language attack the implementation method of attack but a very effective one too C has some pitfalls I won't talk about these but C has lots of problems and they've been seen time and time again for many many years now since the 1970s at least so there are problems in pretty much all code not just user land or kernel code it probably has the same classes of bugs that people are looking for and all code we can find bugs in lots and lots of code I will skip this because I've talked about it earlier on so when we what we if we look at kernel buffer copy is okay we can think of kernel and user space divided into segments kernel space is a segment user space is a segment when we do a kernel buffer copy we need to validate the source and destination that they reside in the right segments so that when we're copying something from kernel space to user space we are in fact copying it from kernel space to user space we're not putting in values such as 0xc something something something which represents kernel space to a read or a write system call or so forth for example here if we were able to read something from the network and it was possible to put in an address such as 0xc104 you know whatever if there was no validation done we'd actually read this data into the kernel segment and overwrite kernel structures or executable code and if that was the case that we could read into kernel space then we could certainly exploit the kernel here okay we have a FreeBSD sysexcept exploit here and I just wanted to show this code it's about 30, 37 or 38 lines what I said before and the way to exploit this is pretty straight forward the except system call takes three arguments the first argument is a socket the second argument is a socket address and the third argument is the socket address link we simply point the socket address to a user space buffer and then in our and then in our socket address link we pass to it a negative value and I'm just about to get thrown off stage so I'm gonna wrap up right now okay thank you very much everyone I hope you enjoyed my presentation I just wanted to say one more thing if anyone wanted to continue this or have any questions you can see me outside or right now somewhere else anyway but thank you for watching and I'll see you next time bye bye