1 00:00:03,660 --> 00:00:08,160 Hello, I'm just going to test the mic and make sure that I have the right distance to the microphone here. 2 00:00:08,760 --> 00:00:17,480 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. 3 00:00:19,140 --> 00:00:22,620 The first thing I said at Black Hat, I suppose, was I wanted to achieve two things. 4 00:00:23,180 --> 00:00:28,300 And one of those things was not freaking out on stage, and I hope I don't freak out on stage today. 5 00:00:28,300 --> 00:00:40,680 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. 6 00:00:40,900 --> 00:00:44,780 And that is what my presentation is on, kernel auditing and exploitation. 7 00:00:46,620 --> 00:00:49,780 So there are three parts in today's presentation. 8 00:00:51,600 --> 00:00:55,380 At the end of each part we'll stop for questions. 9 00:00:56,480 --> 00:00:58,280 But feel free to jump in with your questions. 10 00:00:58,300 --> 00:00:59,800 If you have any questions, if you want to. 11 00:01:00,620 --> 00:01:09,000 So the three parts are the auditing research that I performed, a sample of exploitable bugs, and exploitation on some of those bugs. 12 00:01:10,880 --> 00:01:13,120 So part one is kernel auditing research. 13 00:01:14,700 --> 00:01:25,020 So last year for about three months, between July and September 2002, I performed a manual audit of the various open source kernels. 14 00:01:25,020 --> 00:01:29,900 And the OSs here were FreeBSD, NetBSD, OpenBSD, and Linux. 15 00:01:30,600 --> 00:01:37,540 This was a part-time audit, so I wasn't spending 24-7 or even eight hours a day or anything. 16 00:01:37,700 --> 00:01:40,600 It was just spare time that I had available. 17 00:01:40,900 --> 00:01:43,900 I just audit various bits of kernel source. 18 00:01:45,700 --> 00:01:50,120 So just to give a time frame of how much auditing was done on each kernel. 19 00:01:50,960 --> 00:01:53,720 NetBSD was about a little less than a week. 20 00:01:54,600 --> 00:01:56,400 FreeBSD a little less than a week also. 21 00:01:56,840 --> 00:01:58,140 OpenBSD was a couple of days. 22 00:01:58,340 --> 00:02:00,440 And Linux was the rest of my free time. 23 00:02:01,000 --> 00:02:04,080 Why did I audit Linux so much? 24 00:02:05,940 --> 00:02:08,480 Probably just because I use Linux a lot. 25 00:02:09,100 --> 00:02:12,900 I run it on this computer and most of my PCs. 26 00:02:13,180 --> 00:02:19,940 So unfortunately Linux was a little heavy-handed in my auditing because I do enjoy Linux. 27 00:02:21,340 --> 00:02:22,960 So what prior work has been done? 28 00:02:22,960 --> 00:02:25,940 On kernel auditing and so forth. 29 00:02:26,260 --> 00:02:28,020 There has been some prior work here. 30 00:02:28,640 --> 00:02:33,400 Probably the best that I think that I've seen is Dawson Engler's research. 31 00:02:33,720 --> 00:02:37,300 In the past couple of years he has released a number of papers. 32 00:02:37,400 --> 00:02:38,640 Some really great papers actually. 33 00:02:40,340 --> 00:02:46,080 Where basically he wrote an automated bug discovery tool using a language called Metal. 34 00:02:46,220 --> 00:02:47,500 And he released some papers on this. 35 00:02:47,580 --> 00:02:52,000 And to do this research he applied this automated bug discovery. 36 00:02:52,000 --> 00:02:54,000 On large sources. 37 00:02:54,200 --> 00:02:57,460 Namely being the operating systems kernels. 38 00:02:57,760 --> 00:03:05,480 So NetBSD, actually OpenBSD, Linux and FreeBSD he certainly performed automated bug discovery on. 39 00:03:06,520 --> 00:03:12,140 And actually he sent most of those bugs I think to the Linux kernel mailing list. 40 00:03:12,700 --> 00:03:16,120 And found a lot of concurrency and synchronization issues. 41 00:03:16,300 --> 00:03:18,600 Issues such as double locks, double unlocks. 42 00:03:19,800 --> 00:03:21,300 That seems to be... 43 00:03:21,300 --> 00:03:23,180 He also found a number of buffer overflows. 44 00:03:23,280 --> 00:03:24,160 And this was all automated. 45 00:03:24,980 --> 00:03:29,280 But most of the bugs that were reported were concurrency and synchronization. 46 00:03:29,740 --> 00:03:32,440 The Linux kernel auditing project is an interesting one here. 47 00:03:32,820 --> 00:03:36,740 There's a bit of a question mark at the end of this line. 48 00:03:36,920 --> 00:03:41,980 And the reason for that is I've never actually seen the Linux kernel auditing project do anything. 49 00:03:43,860 --> 00:03:45,360 They've got a mailing list. 50 00:03:46,280 --> 00:03:48,200 But there's very few posts to it. 51 00:03:48,300 --> 00:03:50,720 I think they released about two advisories. 52 00:03:50,720 --> 00:03:53,000 For some issues that were already known. 53 00:03:53,160 --> 00:03:54,240 And they never really... 54 00:03:54,240 --> 00:03:57,300 Like in my opinion they really didn't audit the Linux kernel. 55 00:03:57,680 --> 00:04:01,980 They talked about possibly let's audit the Linux kernel. 56 00:04:02,100 --> 00:04:03,160 But I don't think they actually did. 57 00:04:03,220 --> 00:04:06,020 Because there are places in the kernel source where you just... 58 00:04:06,020 --> 00:04:08,120 They have comments saying it's totally broken. 59 00:04:08,160 --> 00:04:09,020 Please don't use. 60 00:04:09,700 --> 00:04:12,160 And these bits of code are totally exploitable. 61 00:04:14,240 --> 00:04:16,780 So just some notes for the rest of the presentation. 62 00:04:18,060 --> 00:04:19,340 When I'm talking about bugs. 63 00:04:19,340 --> 00:04:20,900 I'm always going to be talking about vulnerabilities. 64 00:04:22,140 --> 00:04:23,160 I just... 65 00:04:23,160 --> 00:04:25,120 Vulnerabilities is a really long word. 66 00:04:26,740 --> 00:04:29,400 So I'll just say bug. 67 00:04:31,060 --> 00:04:32,280 Unless I state otherwise. 68 00:04:33,260 --> 00:04:38,360 And just to sort of summarize what happened after the end of these three months of auditing. 69 00:04:38,620 --> 00:04:43,600 I think in conjunction with the kernel developers and whatnot. 70 00:04:43,900 --> 00:04:47,940 At least 150 bugs were patched. 71 00:04:47,940 --> 00:04:49,320 And pretty much all of these were patched. 72 00:04:49,340 --> 00:04:49,740 They were exploitable. 73 00:04:52,200 --> 00:04:54,060 So I'm just going to like... 74 00:04:54,680 --> 00:04:56,520 In my view there seems to be... 75 00:04:56,520 --> 00:05:00,340 There seem to be a lot of bugs in the kernels from what I've seen. 76 00:05:01,060 --> 00:05:03,020 But not many people seem to be auditing them. 77 00:05:03,120 --> 00:05:04,660 Or if they're auditing them... 78 00:05:05,340 --> 00:05:06,200 I don't know. 79 00:05:06,380 --> 00:05:08,520 So I believe that there are certain myths. 80 00:05:08,660 --> 00:05:10,700 Or a bit of mythology around kernel source. 81 00:05:11,400 --> 00:05:14,240 And one of the myths I'm talking about here is that... 82 00:05:14,240 --> 00:05:18,420 Maybe it's assumed by people that kernels are written by security experts and programming gods. 83 00:05:19,340 --> 00:05:20,960 And certainly kernel developers... 84 00:05:21,940 --> 00:05:26,240 Some kernel developers are exceptionally talented and incredible programmers. 85 00:05:27,260 --> 00:05:27,780 But... 86 00:05:29,640 --> 00:05:31,300 There's a lot of kernel source here. 87 00:05:31,340 --> 00:05:32,640 A lot of developers get involved. 88 00:05:34,920 --> 00:05:37,340 And so the follow-up to this myth is... 89 00:05:39,000 --> 00:05:42,040 If the kernels are written by security experts and programming gods... 90 00:05:42,040 --> 00:05:44,660 They really mustn't have any security bugs. 91 00:05:44,780 --> 00:05:47,620 And if they have security bugs, they're not really simplistic. 92 00:05:49,340 --> 00:05:50,860 And I suppose that leads on to the next myth. 93 00:05:51,020 --> 00:05:51,700 Is that... 94 00:05:51,700 --> 00:05:53,500 It's just a rewrite of the first one. 95 00:05:53,640 --> 00:05:58,100 Is that kernels never have simplistic security bugs. 96 00:05:58,460 --> 00:06:01,720 Therefore only security experts or programming gods can find them. 97 00:06:02,240 --> 00:06:06,660 And I would disagree with this considerably. 98 00:06:06,720 --> 00:06:08,420 And I show evidence to... 99 00:06:09,200 --> 00:06:12,760 In contradiction to this by showing simple bugs that are exploitable. 100 00:06:13,540 --> 00:06:14,680 And so forth. 101 00:06:15,800 --> 00:06:17,820 I've got one more final myth. 102 00:06:18,080 --> 00:06:18,620 That... 103 00:06:18,620 --> 00:06:21,000 Again, a follow-up to the second one and the first one. 104 00:06:21,120 --> 00:06:22,440 That if kernels are buggy... 105 00:06:23,220 --> 00:06:24,720 Incredibly difficult to exploit. 106 00:06:24,960 --> 00:06:29,360 And therefore probably exploitation is just theoretical. 107 00:06:31,160 --> 00:06:34,140 Maybe you've heard that there are bugs. 108 00:06:34,280 --> 00:06:38,340 But they require something to be happening while something else is going on. 109 00:06:38,440 --> 00:06:41,580 And maybe the disk light is flashing a bit. 110 00:06:43,360 --> 00:06:45,620 These types of... 111 00:06:45,620 --> 00:06:48,500 These are the myths that I hear and I see. 112 00:06:48,620 --> 00:06:50,760 And I try to show evidence to contradict this. 113 00:06:50,820 --> 00:06:52,280 Because there are simple bugs in the kernel. 114 00:06:52,380 --> 00:06:53,500 Simple bugs to exploit. 115 00:06:53,700 --> 00:06:56,720 There are simple mistakes that are obviously spotable. 116 00:06:58,240 --> 00:07:01,680 So I make some conjectures for the auditing. 117 00:07:02,080 --> 00:07:04,100 That kernel code isn't special. 118 00:07:04,240 --> 00:07:05,380 It's just another program. 119 00:07:05,560 --> 00:07:06,400 It's a big program. 120 00:07:06,840 --> 00:07:09,140 It's a big, big program. 121 00:07:09,200 --> 00:07:10,460 But it's just another program. 122 00:07:11,240 --> 00:07:13,400 There's certainly a lot of bugs in user land. 123 00:07:14,300 --> 00:07:16,200 So why not the kernel as well? 124 00:07:17,760 --> 00:07:20,140 And one of the reasons for this is that... 125 00:07:20,620 --> 00:07:22,300 I believe this is that... 126 00:07:24,360 --> 00:07:27,060 These kernels are written in the same language that... 127 00:07:27,060 --> 00:07:30,980 The language of C that has had so many problems in the past with user land programs. 128 00:07:31,660 --> 00:07:34,800 User land programs generally written in C. 129 00:07:34,900 --> 00:07:35,780 Lots of bugs. 130 00:07:36,120 --> 00:07:38,340 Why do people not think the kernel is the same? 131 00:07:39,440 --> 00:07:40,400 And certainly... 132 00:07:41,840 --> 00:07:44,460 My conjecture is that kernel programmers do make mistakes. 133 00:07:44,880 --> 00:07:46,080 Just like everyone else. 134 00:07:47,700 --> 00:07:48,420 You know... 135 00:07:48,420 --> 00:07:50,080 If someone's... 136 00:07:50,080 --> 00:07:52,320 An average kernel is, say, a couple million lines of code. 137 00:07:52,620 --> 00:07:57,900 Are we expecting that one million or ten million lines of code is 100% bug-free? 138 00:07:57,940 --> 00:08:00,380 That a simple mistake hasn't occurred somewhere in this? 139 00:08:00,680 --> 00:08:04,960 It takes a long time just to look at five million lines of code. 140 00:08:05,060 --> 00:08:08,720 Let alone audit every single line there. 141 00:08:10,700 --> 00:08:14,340 So I started with a bit of a methodology for the auditing here. 142 00:08:14,520 --> 00:08:15,000 But the... 143 00:08:15,000 --> 00:08:17,720 I was only going to audit simple classes of bugs. 144 00:08:18,760 --> 00:08:22,720 Not going to look for really complicated, you know, ways of attacking the kernel. 145 00:08:22,880 --> 00:08:27,600 You know, if your disk light is flashing and, you know, maybe something is going on in the background. 146 00:08:27,680 --> 00:08:29,120 And you're paging something. 147 00:08:29,240 --> 00:08:31,580 Not going to go for any bugs like that. 148 00:08:31,720 --> 00:08:34,540 Not going to go for any attacks on algorithms or so forth. 149 00:08:36,040 --> 00:08:38,400 Just target really simple classes of bugs. 150 00:08:38,680 --> 00:08:40,580 And one of the ways of... 151 00:08:40,580 --> 00:08:41,960 To do this... 152 00:08:41,960 --> 00:08:44,780 Was to audit using bottom-up techniques. 153 00:08:45,000 --> 00:08:53,280 So basically find places in the code that, if were buggy, could probably be exploitable. 154 00:08:53,500 --> 00:08:58,420 And the way that I'd do this would be basically to grep for good places. 155 00:08:59,180 --> 00:09:01,840 And from that, look at the code around it. 156 00:09:01,920 --> 00:09:04,440 And if that code is buggy, it's probably exploitable. 157 00:09:04,520 --> 00:09:07,540 So looking for good entry points into the kernel. 158 00:09:08,880 --> 00:09:12,280 Now, kernel-to-userspace copies and userspace-to-kernel copies. 159 00:09:12,720 --> 00:09:13,440 Buffer copies. 160 00:09:15,000 --> 00:09:16,920 A very good place to look. 161 00:09:17,300 --> 00:09:27,920 If these bits of code are buggy, then certainly buffer overflows and other problems are likely to be exploitable here. 162 00:09:29,020 --> 00:09:38,600 As the auditing continued over the period of months, certainly I got more experience in what sort of things I should be looking for. 163 00:09:38,800 --> 00:09:43,760 And the number of classes of bugs and exploit classes certainly increased. 164 00:09:45,000 --> 00:09:48,280 So for example here, system calls are simple entry points. 165 00:09:50,120 --> 00:10:00,840 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. 166 00:10:01,760 --> 00:10:08,120 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, 167 00:10:08,200 --> 00:10:10,000 Okay, let's go for the core system calls. 168 00:10:10,120 --> 00:10:10,980 Maybe there's a bug there. 169 00:10:11,260 --> 00:10:13,400 But there's in fact... 170 00:10:13,400 --> 00:10:14,000 You know... 171 00:10:14,000 --> 00:10:17,580 A lot of other places also that you can audit, such as the device drivers. 172 00:10:17,760 --> 00:10:19,780 These, again, have simple entry points. 173 00:10:21,160 --> 00:10:24,300 Primarily for the fact that in Unix everything, you know, really... 174 00:10:24,300 --> 00:10:26,800 The idea was that everything should be considered a file. 175 00:10:26,940 --> 00:10:31,900 So you can access a lot of code, a lot of kernel code, through these device drivers. 176 00:10:34,600 --> 00:10:36,420 IOCTLs seem to do everything. 177 00:10:37,180 --> 00:10:38,420 They're so generic. 178 00:10:38,540 --> 00:10:43,800 They basically can do anything and everything that you want and probably more. 179 00:10:44,000 --> 00:10:47,060 They increase the attack vector space massively. 180 00:10:47,460 --> 00:10:52,640 And it's argued that for Unix, everything is a file. 181 00:10:52,700 --> 00:10:54,140 What's the point of IOCTLs for this? 182 00:10:55,640 --> 00:11:01,540 IOCTLs break the design of Unix to say that everything is a file by introducing a system call that does everything at this point. 183 00:11:01,900 --> 00:11:07,460 So some of the Unix designers argue that that was a bit of a downfall of Unix at that point. 184 00:11:08,180 --> 00:11:09,260 I don't think so, though. 185 00:11:09,760 --> 00:11:10,740 It's certainly interesting. 186 00:11:10,740 --> 00:11:13,900 So there were some immediate results in the auditing here. 187 00:11:14,080 --> 00:11:15,960 The first bug was found within hours. 188 00:11:16,420 --> 00:11:19,000 And this was true for all systems audited. 189 00:11:19,220 --> 00:11:25,980 And it's arguable that the first bug in a non-familiar software is arguably the hardest to find. 190 00:11:26,560 --> 00:11:32,440 Once you start to have places to look for and ideas of what types of bugs are present, 191 00:11:32,540 --> 00:11:35,620 it's typically considered easier to find more bugs. 192 00:11:36,620 --> 00:11:38,320 So a couple of observations here. 193 00:11:39,520 --> 00:11:44,240 There does seem to be evidence of varying degrees of code quality, and hence security bugs. 194 00:11:44,720 --> 00:11:48,660 The core kernel code in all the systems audited was pretty good. 195 00:11:49,220 --> 00:11:50,940 Not so many problems there. 196 00:11:51,080 --> 00:11:59,200 There were a couple, but ultimately it seemed to be a lot more bug-free than, say, for example, device drivers, 197 00:11:59,360 --> 00:12:03,380 which pretty much anyone can write, make a submission for all the OSs here. 198 00:12:04,100 --> 00:12:08,300 So they did, in my opinion, seem to contain a large number of bugs. 199 00:12:08,300 --> 00:12:12,880 And I also make the comment that bug tends to exhibit signs of propagation and clustering. 200 00:12:13,080 --> 00:12:17,360 So what I mean by this is that, say, for example, you have a device driver, 201 00:12:18,040 --> 00:12:23,080 and this device driver, this code for this device driver, becomes the reference implementation. 202 00:12:24,000 --> 00:12:26,620 And this reference implementation has a bug in it. 203 00:12:26,760 --> 00:12:33,060 And now everyone, when they go to write their device driver, copies the buggy reference implementation, 204 00:12:33,140 --> 00:12:37,520 and thus the bug propagates with the security problems associated with it. 205 00:12:38,300 --> 00:12:45,240 The clustering observation is also that of, once you find a bug in a particular bit of source, 206 00:12:45,540 --> 00:12:48,660 you're probably more likely to find bugs nearby as well. 207 00:12:48,880 --> 00:12:53,660 So if you start to find bugs in, say, the video for Linux drivers, 208 00:12:54,520 --> 00:12:57,440 maybe there are more bugs in other video for Linux drivers. 209 00:12:57,480 --> 00:13:02,440 Maybe in the file system code, look around, probably more bugs around that area as well. 210 00:13:02,740 --> 00:13:05,660 And there are identical bugs across all platforms. 211 00:13:05,960 --> 00:13:07,880 And I'll show you some examples of this. 212 00:13:08,300 --> 00:13:11,020 It's not like the asterisks and the bracketed two stuff, 213 00:13:11,280 --> 00:13:14,540 just in reference to some slides coming up. 214 00:13:15,640 --> 00:13:19,180 But just before I get into that, just a bit of research bias. 215 00:13:19,920 --> 00:13:22,780 Manual auditing is inherently biased. 216 00:13:23,980 --> 00:13:31,340 Certainly I can't argue definitively that these observations are scientifically correct, 217 00:13:31,460 --> 00:13:34,860 because my auditing is inherently biased. 218 00:13:35,140 --> 00:13:37,920 Maybe I believe that core kernel code 219 00:13:38,300 --> 00:13:40,400 is more secure, hence I'm not finding bugs in that. 220 00:13:40,600 --> 00:13:44,420 It's hard to argue through scientific means. 221 00:13:44,620 --> 00:13:47,160 However, Dawson Engler's work with the automated bug discovery 222 00:13:48,700 --> 00:13:51,700 is less biased since it is not done by a human. 223 00:13:51,760 --> 00:13:57,760 It is done by an automated process which can be repeated time and time again and so forth. 224 00:13:59,660 --> 00:14:05,800 So just some code in reference to having the same bugs across a number of platforms. 225 00:14:05,800 --> 00:14:08,340 We have here NetBSD and OpenBSD. 226 00:14:09,200 --> 00:14:11,400 This was a couple of versions ago. 227 00:14:12,060 --> 00:14:14,680 And it's a bad example to show, to start off. 228 00:14:14,940 --> 00:14:16,440 And I should have changed this slide. 229 00:14:16,940 --> 00:14:22,900 But because you can't see the exact part where it's exploitable, 230 00:14:22,980 --> 00:14:24,600 you can just see part of the bug here. 231 00:14:24,860 --> 00:14:26,380 So I've highlighted... 232 00:14:26,380 --> 00:14:29,920 I don't think anyone can see this because I can't even see this from here. 233 00:14:31,680 --> 00:14:33,360 So basically I've... 234 00:14:34,440 --> 00:14:37,000 It's in the I386 set LDT code. 235 00:14:37,160 --> 00:14:38,700 We're adding two numbers together. 236 00:14:39,160 --> 00:14:42,100 Start plus num and checking if it's greater than another. 237 00:14:42,380 --> 00:14:44,940 And this is input validation checks. 238 00:14:45,360 --> 00:14:48,400 However, the problem is that when we add these two numbers together, 239 00:14:48,480 --> 00:14:51,940 we can get a sign wrap around, end with a negative number, 240 00:14:52,220 --> 00:14:53,800 pass this input validation check, 241 00:14:54,040 --> 00:14:57,640 and then a couple of lines afterwards we have a buffer copy 242 00:14:58,360 --> 00:15:02,500 which now uses the failed input validation check. 243 00:15:04,240 --> 00:15:06,080 These have been fixed since, 244 00:15:07,740 --> 00:15:10,660 so they shouldn't be current in any systems. 245 00:15:12,280 --> 00:15:14,320 So just to show some evidence in contradiction 246 00:15:14,320 --> 00:15:16,900 to the myths that I presented earlier, 247 00:15:17,060 --> 00:15:19,740 is that kernels aren't written by gods. 248 00:15:20,900 --> 00:15:22,380 You know, very talented, 249 00:15:22,380 --> 00:15:26,280 but not in the godly manner that the myth holds them to. 250 00:15:27,520 --> 00:15:29,960 So the initial bugs were found in all hours, 251 00:15:30,080 --> 00:15:31,840 and bugs were found in large quantities. 252 00:15:32,140 --> 00:15:33,180 10 to 30 per day, 253 00:15:33,360 --> 00:15:34,320 which wasn't really uncommon. 254 00:15:35,600 --> 00:15:37,280 You know, in various places of the source, 255 00:15:37,460 --> 00:15:38,500 lots of bugs were present. 256 00:15:39,700 --> 00:15:42,520 And it was assumed in SATA that code was secure 257 00:15:42,520 --> 00:15:43,460 when in fact it wasn't. 258 00:15:43,500 --> 00:15:46,360 This is actually pretty funny, to be honest. 259 00:15:47,000 --> 00:15:48,840 So this is in Linux 2.4.18. 260 00:15:49,880 --> 00:15:53,560 And this is in the video for Linux code, I think. 261 00:15:53,740 --> 00:15:54,940 One of the drivers for that. 262 00:15:55,080 --> 00:15:56,800 So the comment is that, 263 00:15:57,560 --> 00:15:58,820 okay, first things first, 264 00:15:58,920 --> 00:16:00,920 make sure we don't copy more than we have, 265 00:16:01,060 --> 00:16:02,840 even if the application wants more. 266 00:16:02,840 --> 00:16:05,120 That would be a big security embarrassment, 267 00:16:05,320 --> 00:16:06,980 with an exclamation mark at the end. 268 00:16:07,060 --> 00:16:08,400 The very next line, 269 00:16:08,540 --> 00:16:11,060 the exact next line of this comment 270 00:16:11,060 --> 00:16:12,100 is an integer overflow. 271 00:16:13,840 --> 00:16:14,400 Okay. 272 00:16:14,460 --> 00:16:17,880 So about two lines below that 273 00:16:17,880 --> 00:16:19,520 is a buffer overflow 274 00:16:19,520 --> 00:16:21,020 as a result of the integer overflow. 275 00:16:21,500 --> 00:16:25,060 So it's a very interesting comment, certainly. 276 00:16:26,160 --> 00:16:28,540 There is another interesting comment. 277 00:16:28,580 --> 00:16:30,060 And there's a few interesting comments in the code. 278 00:16:30,220 --> 00:16:32,740 And I'll show some more a bit later on. 279 00:16:32,740 --> 00:16:34,360 But for this comment, 280 00:16:34,560 --> 00:16:37,020 it has, this routine does error checking 281 00:16:37,020 --> 00:16:38,850 to make sure that all memory accesses 282 00:16:39,260 --> 00:16:40,140 are within bounds. 283 00:16:41,220 --> 00:16:42,840 And then what we have, 284 00:16:42,860 --> 00:16:44,420 we have multiple problems in this code. 285 00:16:44,520 --> 00:16:48,260 We have a sign problem. 286 00:16:48,400 --> 00:16:50,380 We pass in a sign integer 287 00:16:50,380 --> 00:16:51,980 and do a comparison, 288 00:16:52,140 --> 00:16:54,200 but we don't check for the case when it's less than zero. 289 00:16:54,300 --> 00:16:56,540 We also have an integer overflow. 290 00:16:56,560 --> 00:16:59,020 Even if we got this sign problem fixed, 291 00:16:59,420 --> 00:17:01,120 we would have an integer overflow 292 00:17:01,120 --> 00:17:01,920 in the lines below. 293 00:17:02,740 --> 00:17:04,360 And then we have a buffer overflow 294 00:17:05,480 --> 00:17:06,600 after all of that. 295 00:17:06,760 --> 00:17:09,200 So, you know, they're pretty funny comments. 296 00:17:09,380 --> 00:17:10,040 I don't know. 297 00:17:10,060 --> 00:17:11,900 Maybe it's just my bad sense of humor. 298 00:17:12,920 --> 00:17:14,660 So some more evidence in contradiction 299 00:17:14,660 --> 00:17:15,680 to kernel mythology. 300 00:17:16,400 --> 00:17:18,060 Kernels really do have simplistic bugs. 301 00:17:19,680 --> 00:17:21,280 You know, I really didn't do 302 00:17:21,280 --> 00:17:22,480 any intensive code tracking 303 00:17:23,220 --> 00:17:24,200 for this audit. 304 00:17:24,260 --> 00:17:25,780 I really, you know, 305 00:17:25,900 --> 00:17:27,460 scrapping for simple places, 306 00:17:28,920 --> 00:17:30,460 gripping for good places to look, 307 00:17:30,600 --> 00:17:32,500 and then from there looking at code immediately 308 00:17:32,740 --> 00:17:33,440 above it. 309 00:17:33,680 --> 00:17:35,080 I didn't really, you know, 310 00:17:35,120 --> 00:17:36,380 I wasn't starting at the, you know, 311 00:17:36,380 --> 00:17:39,780 init.c or, you know, wherever here. 312 00:17:39,960 --> 00:17:40,940 I didn't start at a boot sector 313 00:17:40,940 --> 00:17:43,120 and follow it all the way to what happens 314 00:17:43,120 --> 00:17:45,400 when you, you know, fork. 315 00:17:45,600 --> 00:17:48,400 Just find simple places to audit 316 00:17:48,400 --> 00:17:50,400 and look at the immediate code around it. 317 00:17:51,740 --> 00:17:52,620 And certainly, 318 00:17:52,740 --> 00:17:54,040 in some cases, 319 00:17:54,520 --> 00:17:56,740 there was simply just no input validation at all. 320 00:17:57,960 --> 00:17:58,400 Also, 321 00:17:58,560 --> 00:18:00,700 inline documentation shows that, you know, 322 00:18:00,720 --> 00:18:02,080 code is not working. 323 00:18:02,740 --> 00:18:04,180 I should have some examples here. 324 00:18:04,860 --> 00:18:06,860 So we have this bit of code, 325 00:18:07,780 --> 00:18:09,320 ibcs2-stat.c 326 00:18:09,320 --> 00:18:11,140 And this is 327 00:18:11,140 --> 00:18:13,080 in all systems, actually. 328 00:18:13,280 --> 00:18:15,880 OpenBSD, NetBSD, FreeBSD, 329 00:18:15,880 --> 00:18:16,560 and Linux. 330 00:18:16,620 --> 00:18:18,820 The bug was shared across all platforms. 331 00:18:21,080 --> 00:18:22,420 FreeBSD have not fixed this. 332 00:18:22,520 --> 00:18:23,240 I don't know why. 333 00:18:24,600 --> 00:18:25,660 So basically, 334 00:18:25,800 --> 00:18:27,400 we pass in a length 335 00:18:27,400 --> 00:18:29,060 to a syscall. 336 00:18:29,860 --> 00:18:31,540 The length is just never validated. 337 00:18:32,740 --> 00:18:34,480 We copy a buffer using this length. 338 00:18:35,460 --> 00:18:36,320 And there's no, 339 00:18:36,440 --> 00:18:37,560 you can put a length of anything. 340 00:18:37,820 --> 00:18:39,920 Any length you want and it will copy that. 341 00:18:40,260 --> 00:18:42,780 So, you know, no input validation at all. 342 00:18:44,320 --> 00:18:45,300 Here is another 343 00:18:45,300 --> 00:18:48,260 no input validation bug. 344 00:18:49,040 --> 00:18:50,540 This one is copying 345 00:18:50,540 --> 00:18:52,180 from kernel space to user space. 346 00:18:53,000 --> 00:18:54,200 So this will 347 00:18:54,590 --> 00:18:56,020 give us kernel memory disclosure. 348 00:18:56,420 --> 00:18:57,940 And again, it's from a 349 00:18:58,800 --> 00:18:59,920 VGA driver here. 350 00:19:00,400 --> 00:19:02,280 So, video driver. 351 00:19:02,740 --> 00:19:03,820 Of some kind. 352 00:19:03,980 --> 00:19:05,500 Looks like to be NetBSD, I think. 353 00:19:06,220 --> 00:19:08,360 So we're going to call an IACTL. 354 00:19:09,240 --> 00:19:10,720 And then we can pass in 355 00:19:10,720 --> 00:19:12,140 a count of whatever we want. 356 00:19:12,220 --> 00:19:13,160 We just pass in a length. 357 00:19:13,460 --> 00:19:16,100 And it will just copy this back to user space. 358 00:19:19,180 --> 00:19:20,560 Okay, here's another bit of code. 359 00:19:21,020 --> 00:19:22,100 This one is in Linux. 360 00:19:22,960 --> 00:19:24,800 And this one is still present in Linux. 361 00:19:25,320 --> 00:19:26,440 I released this 362 00:19:26,440 --> 00:19:27,860 and an exploit for it 363 00:19:27,860 --> 00:19:29,440 a couple of months ago at RuxCon. 364 00:19:30,440 --> 00:19:32,600 And it doesn't seem that, you know, 365 00:19:32,740 --> 00:19:33,300 it hasn't been fixed. 366 00:19:33,420 --> 00:19:35,480 So I'm not quite sure what the story is there. 367 00:19:35,740 --> 00:19:36,800 So we have a comment. 368 00:19:36,980 --> 00:19:39,840 And this is in the Cough binary loader. 369 00:19:40,400 --> 00:19:41,640 It has a comment saying 370 00:19:42,800 --> 00:19:43,680 XXX untested. 371 00:19:44,040 --> 00:19:46,000 And, like, I can really guarantee 372 00:19:46,000 --> 00:19:47,060 that it's never been tested 373 00:19:47,060 --> 00:19:48,940 because if anyone used this 374 00:19:48,940 --> 00:19:50,200 it would kernel panic immediately. 375 00:19:52,160 --> 00:19:54,760 It's using the wrong arguments completely. 376 00:19:55,200 --> 00:19:56,860 There's no possible way it can work. 377 00:19:57,780 --> 00:19:59,020 But in this case 378 00:19:59,020 --> 00:20:00,820 it turns out to be exploitable. 379 00:20:00,960 --> 00:20:01,380 And we can 380 00:20:02,740 --> 00:20:04,100 escalate privileges and get a root shell 381 00:20:04,740 --> 00:20:06,400 by running a custom 382 00:20:06,400 --> 00:20:06,980 Cough binary. 383 00:20:08,440 --> 00:20:10,780 So, some more evidence 384 00:20:10,780 --> 00:20:12,140 in contradiction to 385 00:20:12,740 --> 00:20:13,700 kernel mythology. 386 00:20:14,800 --> 00:20:16,240 Kernels, if they're buggy, 387 00:20:16,360 --> 00:20:18,420 are not always difficult to exploit. 388 00:20:18,780 --> 00:20:20,660 To exploit 100% 389 00:20:20,660 --> 00:20:21,140 reliably 390 00:20:22,880 --> 00:20:23,560 procfs 391 00:20:24,560 --> 00:20:25,840 bugs in Linux to 392 00:20:26,520 --> 00:20:27,640 perform memory disclosure 393 00:20:27,640 --> 00:20:28,940 is 38 lines. 394 00:20:29,580 --> 00:20:31,160 For FreeBSD this 395 00:20:32,740 --> 00:20:33,340 is a custom call advisory 396 00:20:33,340 --> 00:20:34,500 that was released last year. 397 00:20:35,440 --> 00:20:37,080 37 lines of C. 398 00:20:39,220 --> 00:20:40,320 FreeBSD and Linux 399 00:20:40,320 --> 00:20:42,020 the developers of 400 00:20:42,680 --> 00:20:43,520 respective developers 401 00:20:44,480 --> 00:20:46,060 both have exploits 402 00:20:46,540 --> 00:20:47,780 for these by the way. 403 00:20:48,160 --> 00:20:50,600 I did send the exploits 404 00:20:50,600 --> 00:20:51,880 that were written to them. 405 00:20:53,460 --> 00:20:54,900 Also an interesting thing 406 00:20:54,900 --> 00:20:56,500 a stack overflow in Linux 407 00:20:56,500 --> 00:20:58,020 requires no offsets. 408 00:20:59,800 --> 00:21:00,660 It's very 409 00:21:00,660 --> 00:21:02,080 very reliable. It assumes 410 00:21:02,740 --> 00:21:04,340 correctly that addresses 411 00:21:04,340 --> 00:21:05,520 that return addresses 412 00:21:06,600 --> 00:21:07,960 that's the only assumption 413 00:21:07,960 --> 00:21:09,580 it really makes to perform 414 00:21:09,580 --> 00:21:11,260 stack overflow in Linux. 415 00:21:11,580 --> 00:21:14,360 And in GCC it will always 416 00:21:14,360 --> 00:21:16,200 align return addresses. 417 00:21:16,820 --> 00:21:18,480 Actually when I presented this at Blackhat 418 00:21:18,480 --> 00:21:19,720 a couple days ago 419 00:21:20,380 --> 00:21:22,040 I was saying that 420 00:21:22,040 --> 00:21:24,300 I said exactly the same thing but I didn't want to make 421 00:21:24,300 --> 00:21:26,380 I didn't want to say 100% 422 00:21:26,380 --> 00:21:28,460 certain always will be aligned. 423 00:21:28,840 --> 00:21:30,680 So I said GCC 424 00:21:30,680 --> 00:21:32,400 should, I'm pretty sure of that. 425 00:21:32,740 --> 00:21:34,680 But some guy did come up to me 426 00:21:34,680 --> 00:21:35,920 after the presentation and said 427 00:21:35,920 --> 00:21:38,480 yes I can, it's definitely 100% true 428 00:21:38,480 --> 00:21:40,080 that GCC will never 429 00:21:41,240 --> 00:21:42,960 have anything that isn't word aligned. 430 00:21:43,720 --> 00:21:44,280 So 431 00:21:44,280 --> 00:21:46,600 it's just a bit of a note there. 432 00:21:47,460 --> 00:21:48,020 So 433 00:21:48,020 --> 00:21:49,760 what attack vectors are present 434 00:21:50,540 --> 00:21:51,720 at the result of 435 00:21:52,480 --> 00:21:54,280 auditing all this code and finding 436 00:21:54,280 --> 00:21:55,720 bugs and exploits 437 00:21:56,540 --> 00:21:57,820 it does seem clear 438 00:21:57,820 --> 00:22:00,400 that the more code there is that's running 439 00:22:00,400 --> 00:22:02,720 the more vulnerabilities likely to be present. 440 00:22:02,740 --> 00:22:04,780 Which is a pretty 441 00:22:04,780 --> 00:22:06,480 casual observation there. 442 00:22:07,580 --> 00:22:08,820 But the follow up to that 443 00:22:08,820 --> 00:22:10,580 is don't run these kernels that have 444 00:22:10,580 --> 00:22:12,440 everything compiled into them under the sun. 445 00:22:12,900 --> 00:22:14,400 Don't have support for 446 00:22:14,400 --> 00:22:15,520 hardware that you don't use. 447 00:22:15,700 --> 00:22:18,380 Don't have a million device drivers just running 448 00:22:18,380 --> 00:22:20,060 because all of these 449 00:22:20,740 --> 00:22:22,040 increase the attack space 450 00:22:22,760 --> 00:22:24,240 that you leave open. 451 00:22:24,700 --> 00:22:25,220 So 452 00:22:25,220 --> 00:22:28,780 definitely you can mitigate some risks there 453 00:22:28,780 --> 00:22:29,640 if you just compile 454 00:22:30,400 --> 00:22:31,940 smaller kernels and 455 00:22:32,740 --> 00:22:33,900 don't have so much support there 456 00:22:34,920 --> 00:22:36,220 for things that you don't use. 457 00:22:36,580 --> 00:22:37,080 So 458 00:22:38,060 --> 00:22:40,380 entry points into the kernel 459 00:22:40,380 --> 00:22:41,300 that use a lanker control 460 00:22:41,300 --> 00:22:43,780 are certainly the vectors of exploitation here. 461 00:22:43,940 --> 00:22:46,060 And device drivers, system calls, 462 00:22:46,320 --> 00:22:48,000 file systems. File systems are interesting. 463 00:22:49,120 --> 00:22:50,380 Load code in 464 00:22:50,380 --> 00:22:52,060 Linux, procfs 465 00:22:53,100 --> 00:22:54,280 in most of 466 00:22:54,280 --> 00:22:56,480 all of 2.2 and most of 467 00:22:56,480 --> 00:22:58,380 2.4. I think there's some in 468 00:22:58,380 --> 00:23:00,480 the 2.6 tests at the moment. 469 00:23:01,440 --> 00:23:02,540 And certainly in 470 00:23:02,740 --> 00:23:04,460 most of the 2.5's as well. 471 00:23:05,000 --> 00:23:06,240 You can do things like 472 00:23:06,840 --> 00:23:08,740 lseek. If you can open a file in the procfs 473 00:23:10,300 --> 00:23:12,020 and it's readable by world, 474 00:23:12,160 --> 00:23:14,360 readable by everyone. So you open it, 475 00:23:14,380 --> 00:23:15,800 you seek to around 4 gig 476 00:23:15,800 --> 00:23:17,900 on 32 bit platforms. 477 00:23:18,160 --> 00:23:20,520 Seek to around 4 gig and then if you read 478 00:23:20,520 --> 00:23:22,580 something that you might be able to 479 00:23:22,580 --> 00:23:24,340 cause an integer overflow for around 480 00:23:24,340 --> 00:23:25,780 4 gig plus what you read. 481 00:23:26,320 --> 00:23:28,620 Get an integer overflow and then you can 482 00:23:28,620 --> 00:23:29,760 have things like memory disclosure. 483 00:23:33,220 --> 00:23:34,840 Also just to make 484 00:23:34,840 --> 00:23:36,000 one more comment on that last slide. 485 00:23:36,120 --> 00:23:38,540 Is that the core kernel code again is pretty 486 00:23:38,540 --> 00:23:39,720 good like in most kernels. 487 00:23:40,240 --> 00:23:42,540 Not, you know, couple of bugs there but 488 00:23:42,540 --> 00:23:42,960 nothing 489 00:23:44,520 --> 00:23:45,260 major there. 490 00:23:46,420 --> 00:23:48,520 I think someone read 491 00:23:48,520 --> 00:23:49,500 the slide there with 492 00:23:49,500 --> 00:23:50,340 three minutes. 493 00:23:52,040 --> 00:23:53,260 Just heard a bit of laughter. 494 00:23:55,120 --> 00:23:56,220 The vendor response 495 00:23:56,220 --> 00:23:57,880 actually was really strong. 496 00:23:58,740 --> 00:23:59,260 Contacted 497 00:24:00,460 --> 00:24:02,320 everyone and everyone responded 498 00:24:02,740 --> 00:24:03,860 extremely well. 499 00:24:03,960 --> 00:24:06,060 sent an email, 500 00:24:06,640 --> 00:24:08,740 turned around, having a conversation 501 00:24:08,740 --> 00:24:10,600 with someone, turned back, under three 502 00:24:10,600 --> 00:24:11,460 minutes got a response. 503 00:24:12,300 --> 00:24:14,660 Sent a list of 10 to 15 bugs 504 00:24:14,660 --> 00:24:16,640 and in three minutes got a 505 00:24:16,640 --> 00:24:17,340 response on these. 506 00:24:17,760 --> 00:24:20,300 I think that's not bad. 507 00:24:21,660 --> 00:24:22,500 Alan Cox 508 00:24:22,500 --> 00:24:24,040 was pretty good. 509 00:24:24,880 --> 00:24:26,800 He was the first person 510 00:24:26,800 --> 00:24:27,740 that I sent 511 00:24:28,640 --> 00:24:30,400 bug reports and vulnerabilities 512 00:24:30,400 --> 00:24:30,960 to. 513 00:24:32,740 --> 00:24:34,640 Sent him a list of bugs for I think 514 00:24:34,640 --> 00:24:36,260 2.2.16 at the time. 515 00:24:36,560 --> 00:24:38,900 This was like 2.4. 516 00:24:39,040 --> 00:24:39,920 something was current. 517 00:24:40,140 --> 00:24:42,520 It wasn't even the latest 2.2 version. 518 00:24:42,640 --> 00:24:44,560 Some old Linux kernel 519 00:24:44,560 --> 00:24:46,660 that no one was really using. 520 00:24:47,240 --> 00:24:48,740 In about three hours, 521 00:24:48,840 --> 00:24:50,360 a couple of hours, 522 00:24:50,580 --> 00:24:52,060 he sent back a list. 523 00:24:52,560 --> 00:24:54,600 He sent back information on all of the 524 00:24:54,600 --> 00:24:55,400 bugs that I had reported. 525 00:24:55,940 --> 00:24:58,780 Some of the bugs he said we fixed that in later 2.2 526 00:24:58,780 --> 00:25:00,740 or in 2.4. 527 00:25:01,220 --> 00:25:02,620 He could actually 528 00:25:02,740 --> 00:25:04,860 name the people that had fixed 529 00:25:04,860 --> 00:25:06,820 bugs from one to two years earlier 530 00:25:06,820 --> 00:25:08,460 saying that Solid Designer 531 00:25:08,460 --> 00:25:10,520 had fixed various 532 00:25:10,520 --> 00:25:11,500 bugs. 533 00:25:12,360 --> 00:25:14,260 Things, for example, such as the 534 00:25:14,260 --> 00:25:15,560 getsockopt, setsockopt, 535 00:25:16,640 --> 00:25:17,840 signproblems from 536 00:25:18,520 --> 00:25:19,440 most of 2.2. 537 00:25:20,620 --> 00:25:22,420 That was pretty impressive, 538 00:25:22,520 --> 00:25:22,780 I thought. 539 00:25:26,100 --> 00:25:28,380 Just before I get too much 540 00:25:28,380 --> 00:25:30,540 into this, I am a little biased 541 00:25:30,540 --> 00:25:30,960 myself. 542 00:25:32,740 --> 00:25:34,340 I still believe in open source software. 543 00:25:35,500 --> 00:25:36,700 Even though 544 00:25:36,700 --> 00:25:37,640 I think 545 00:25:38,940 --> 00:25:40,940 the responses that I received 546 00:25:40,940 --> 00:25:42,040 were exceptional, 547 00:25:42,820 --> 00:25:44,420 it's a little biased there. 548 00:25:44,820 --> 00:25:45,880 Maybe the 549 00:25:46,500 --> 00:25:48,440 reason why open source response 550 00:25:48,440 --> 00:25:50,500 was so good was that they didn't have 551 00:25:50,500 --> 00:25:51,420 a marketing department. 552 00:25:51,780 --> 00:25:53,400 I emailed developers directly, 553 00:25:53,740 --> 00:25:55,920 people that actually code on these kernels. 554 00:25:57,320 --> 00:25:58,680 Maybe the only 555 00:25:58,680 --> 00:26:00,540 thing I could argue was source at that point. 556 00:26:00,840 --> 00:26:01,720 I don't know. 557 00:26:02,740 --> 00:26:04,040 A bit more bias. 558 00:26:04,220 --> 00:26:05,740 I don't know if anyone can see this. 559 00:26:06,420 --> 00:26:08,020 A bit of a grep for the 560 00:26:08,740 --> 00:26:10,520 bit of 561 00:26:10,520 --> 00:26:12,620 grep for hack. The number of 562 00:26:12,620 --> 00:26:14,420 references of the word hack in the 563 00:26:14,420 --> 00:26:16,720 2.4.19 Linux kernel credits, 564 00:26:16,920 --> 00:26:18,140 106 times. 565 00:26:18,560 --> 00:26:19,320 I don't know. 566 00:26:19,820 --> 00:26:21,860 I have a really bad joke. 567 00:26:22,560 --> 00:26:24,640 It's a bad joke. I gave it a blackout. 568 00:26:24,640 --> 00:26:25,140 No one laughed. 569 00:26:25,600 --> 00:26:27,840 A lot of hacks in the Linux kernel. 570 00:26:28,060 --> 00:26:30,600 No one laughed here again. 571 00:26:31,220 --> 00:26:31,740 So... 572 00:26:34,480 --> 00:26:35,000 Comedy, 573 00:26:35,300 --> 00:26:36,600 not my strong thing here. 574 00:26:38,260 --> 00:26:40,240 Just to talk about Linux here. 575 00:26:40,580 --> 00:26:41,660 A bit more about 576 00:26:42,280 --> 00:26:43,560 each vendor's response. 577 00:26:44,600 --> 00:26:46,740 Alan Cox, the first person I contacted, 578 00:26:47,040 --> 00:26:48,560 he remained personally involved and responsible 579 00:26:48,560 --> 00:26:49,560 for the entire duration. 580 00:26:50,860 --> 00:26:52,600 Sent tons and tons of bugs. 581 00:26:52,760 --> 00:26:53,980 He fixed 582 00:26:53,980 --> 00:26:55,860 the majority of software, 583 00:26:56,440 --> 00:26:57,500 patched a lot of things. 584 00:26:58,780 --> 00:27:00,120 Often attributed me with 585 00:27:00,720 --> 00:27:01,420 in the credits, 586 00:27:02,740 --> 00:27:04,080 with small patches and whatnot, 587 00:27:04,320 --> 00:27:05,320 in change logs. 588 00:27:05,560 --> 00:27:08,400 And even though these were one to two lines of code 589 00:27:08,400 --> 00:27:09,900 and were quite sort of obvious of 590 00:27:09,900 --> 00:27:11,940 what needed to be fixed. 591 00:27:12,080 --> 00:27:14,140 It was unusual that he attributed me 592 00:27:14,140 --> 00:27:14,740 for those. 593 00:27:15,560 --> 00:27:18,400 Solid Designer was responsible for the 2.2 Linux kernels. 594 00:27:18,500 --> 00:27:20,500 He was the person 595 00:27:20,500 --> 00:27:22,080 that was, I think, 596 00:27:22,100 --> 00:27:24,440 if you look back last year, the 2.2 kernel 597 00:27:24,440 --> 00:27:25,440 was released after 598 00:27:25,440 --> 00:27:28,380 some long period of time of not releasing another 599 00:27:28,380 --> 00:27:30,800 2.2 kernel. And that was really Solid Designer 600 00:27:30,800 --> 00:27:32,340 doing all of that work. 601 00:27:32,740 --> 00:27:34,500 Backporting a lot of bugs 602 00:27:34,500 --> 00:27:35,440 from 2.4 as well. 603 00:27:36,300 --> 00:27:38,460 Dave Miller initially 604 00:27:38,460 --> 00:27:40,680 started on the Spark patches 605 00:27:40,680 --> 00:27:42,420 and whatnot. And then 606 00:27:42,420 --> 00:27:44,700 started to help in sort of generic stuff as well. 607 00:27:46,740 --> 00:27:47,280 So, 608 00:27:48,260 --> 00:27:50,640 in my opinion, Linux was probably 609 00:27:50,640 --> 00:27:51,700 the biggest success here. 610 00:27:53,800 --> 00:27:54,340 Certainly, 611 00:27:54,520 --> 00:27:56,400 Red Hat released an advisory last year 612 00:27:57,840 --> 00:27:58,620 about the 613 00:27:58,620 --> 00:27:59,480 2.4 kernels. 614 00:27:59,940 --> 00:28:02,500 I think 2.4 615 00:28:02,740 --> 00:28:03,560 or 19 or 18. 616 00:28:04,840 --> 00:28:06,520 And they were pretty 617 00:28:06,520 --> 00:28:08,440 political in their advisory, referencing 618 00:28:08,440 --> 00:28:10,260 the DMCA and saying stuff like 619 00:28:11,160 --> 00:28:12,360 we'd like to give you 620 00:28:12,360 --> 00:28:14,560 information on these vulnerabilities, but we can't 621 00:28:14,560 --> 00:28:16,580 because maybe the DMCA affects this. 622 00:28:16,720 --> 00:28:18,340 So if you go to another website 623 00:28:18,340 --> 00:28:20,600 that's outside the US, you'll be able 624 00:28:20,600 --> 00:28:22,500 to see specific information 625 00:28:22,500 --> 00:28:24,640 on each of the bugs that were fixed. 626 00:28:25,520 --> 00:28:26,460 That was interesting, 627 00:28:26,640 --> 00:28:28,600 I thought. But now 628 00:28:28,600 --> 00:28:29,020 it seems 629 00:28:29,020 --> 00:28:32,020 now it seems that 630 00:28:33,500 --> 00:28:34,800 Red Hat, along with 631 00:28:34,800 --> 00:28:36,660 most of the other Linux vendors, do release 632 00:28:36,660 --> 00:28:38,580 kernel advisories, which seems to be 633 00:28:38,580 --> 00:28:40,540 fantastic. They do release regular kernel 634 00:28:40,540 --> 00:28:41,260 advisories now. 635 00:28:42,840 --> 00:28:43,920 So, you know, 636 00:28:43,980 --> 00:28:46,360 it seems probable that this was 637 00:28:46,360 --> 00:28:48,440 probably attributed to the 638 00:28:48,440 --> 00:28:49,860 auditing work that was done last year. 639 00:28:51,200 --> 00:28:52,660 So, in my opinion, that was 640 00:28:52,660 --> 00:28:54,380 probably the biggest success story there. 641 00:28:55,080 --> 00:28:58,100 The irony is that 642 00:28:58,520 --> 00:29:00,600 there was the Linux kernel auditing project, 643 00:29:00,740 --> 00:29:01,920 but it seems that the 644 00:29:02,740 --> 00:29:04,060 way it performed last year was probably 645 00:29:04,660 --> 00:29:05,760 the most complete 646 00:29:05,760 --> 00:29:07,540 for Linux at that time. 647 00:29:10,260 --> 00:29:11,540 What about FreeBSD? 648 00:29:12,920 --> 00:29:14,760 FreeBSD certainly has a more 649 00:29:14,760 --> 00:29:16,560 formalised process 650 00:29:16,560 --> 00:29:18,500 with vulnerability disclosure 651 00:29:18,500 --> 00:29:20,700 and bug patching and whatnot. 652 00:29:20,960 --> 00:29:22,680 They've got a security officer contact point. 653 00:29:23,280 --> 00:29:24,580 It took me a bit longer 654 00:29:24,580 --> 00:29:26,020 to get a 655 00:29:26,820 --> 00:29:28,140 reasonable dialogue with them. 656 00:29:28,640 --> 00:29:30,220 I'm not talking weeks here, but 657 00:29:30,740 --> 00:29:31,700 I think it was like, 658 00:29:32,740 --> 00:29:34,060 a bit less than a week, I think, 659 00:29:34,100 --> 00:29:36,220 it took me to establish 660 00:29:36,220 --> 00:29:37,220 a really good 661 00:29:39,700 --> 00:29:40,580 dialogue there. 662 00:29:41,000 --> 00:29:42,320 But they were pretty effective 663 00:29:42,320 --> 00:29:44,080 once dialogue was established. 664 00:29:44,740 --> 00:29:46,440 They addressed a standardisation 665 00:29:46,440 --> 00:29:47,440 issue, 666 00:29:48,460 --> 00:29:50,400 which I haven't really 667 00:29:50,400 --> 00:29:52,240 described in my slides, but 668 00:29:52,240 --> 00:29:54,060 for one particular point, 669 00:29:54,180 --> 00:29:56,440 if we look at Linux 2.2 670 00:29:56,440 --> 00:29:58,520 and if we look at 671 00:29:58,520 --> 00:30:00,420 Linux 2.2, there's the getsockop, 672 00:30:00,520 --> 00:30:02,580 setsockop code. The problem for that 673 00:30:02,740 --> 00:30:04,560 was that the socket option 674 00:30:04,560 --> 00:30:06,800 length could be a negative 675 00:30:06,800 --> 00:30:08,680 and when it 676 00:30:08,680 --> 00:30:10,300 was a negative, it would cause memory 677 00:30:10,300 --> 00:30:10,600 disclosure. 678 00:30:11,800 --> 00:30:14,180 A very similar problem with FreeBSD 679 00:30:14,630 --> 00:30:16,420 with the accept system call. 680 00:30:16,600 --> 00:30:18,520 The length of the socket 681 00:30:18,520 --> 00:30:20,620 address structure could be 682 00:30:20,620 --> 00:30:20,960 a negative 683 00:30:20,960 --> 00:30:24,400 and when it was, it would cause 684 00:30:24,400 --> 00:30:25,340 memory disclosure again. 685 00:30:26,280 --> 00:30:28,440 The good thing that FreeBSD 686 00:30:28,440 --> 00:30:30,320 did was that they said, 687 00:30:30,460 --> 00:30:32,080 okay, let's change this 688 00:30:32,740 --> 00:30:34,500 type def for the socket address 689 00:30:34,500 --> 00:30:36,380 length to be unsigned, which 690 00:30:36,380 --> 00:30:38,140 essentially, in my opinion, 691 00:30:38,840 --> 00:30:40,400 will solve problems 692 00:30:40,400 --> 00:30:42,180 that they haven't foreseen in the future. 693 00:30:43,100 --> 00:30:44,640 Unfortunately, the way that Linux 694 00:30:44,640 --> 00:30:46,620 went about fixing that, and it was 695 00:30:46,620 --> 00:30:48,020 unfortunate in some respects, 696 00:30:48,240 --> 00:30:49,680 because there was so many 697 00:30:52,040 --> 00:30:52,600 specific 698 00:30:53,480 --> 00:30:54,780 bugs in the getsockop 699 00:30:54,780 --> 00:30:55,800 code for various 700 00:30:57,280 --> 00:30:58,360 protocols and whatnot, 701 00:30:58,580 --> 00:31:00,260 what was done was that 702 00:31:00,260 --> 00:31:02,180 a check very early on 703 00:31:02,740 --> 00:31:04,620 in the code was performed to check 704 00:31:04,620 --> 00:31:05,380 for the negative case. 705 00:31:05,960 --> 00:31:08,520 It solved lots and lots of 706 00:31:08,520 --> 00:31:09,880 problems from hidden 707 00:31:10,600 --> 00:31:12,220 subsections of code that had the same 708 00:31:12,740 --> 00:31:13,720 sign bug, but 709 00:31:13,720 --> 00:31:16,880 my opinion was I would have liked that to be unsigned. 710 00:31:19,020 --> 00:31:20,660 So, was FreeBSD a 711 00:31:20,660 --> 00:31:20,820 success? 712 00:31:22,060 --> 00:31:23,960 They released an advisory last year 713 00:31:24,520 --> 00:31:26,540 with the accept system call again 714 00:31:26,540 --> 00:31:28,580 and this was a bit of a surprise. 715 00:31:30,000 --> 00:31:30,680 I'm working 716 00:31:30,680 --> 00:31:32,560 at a vulnerability company at the time 717 00:31:32,740 --> 00:31:34,260 and a co-worker 718 00:31:34,260 --> 00:31:36,480 happens to be that guy sitting right there 719 00:31:37,920 --> 00:31:40,540 comes up to me and says that 720 00:31:40,540 --> 00:31:42,300 he's going to implement my vulnerability 721 00:31:42,300 --> 00:31:43,560 and I'm like, 722 00:31:43,680 --> 00:31:46,700 what vulnerability, what are you talking about? 723 00:31:46,940 --> 00:31:48,260 And he's like, FreeBSD have 724 00:31:48,260 --> 00:31:50,320 released an advisory on the 725 00:31:50,320 --> 00:31:51,920 accept system call. 726 00:31:52,320 --> 00:31:54,520 So, I don't know, 727 00:31:54,560 --> 00:31:56,720 thanks FreeBSD. I really did not 728 00:31:56,720 --> 00:31:58,440 know about that and I 729 00:31:58,440 --> 00:32:00,740 saw the advisory, I think 730 00:32:00,740 --> 00:32:02,580 on BugTracker, like everyone else. 731 00:32:03,620 --> 00:32:04,140 So, 732 00:32:04,740 --> 00:32:05,260 NetBSD, 733 00:32:05,460 --> 00:32:08,520 I didn't speak to NetBSD for 734 00:32:08,520 --> 00:32:10,520 too long, but they did 735 00:32:10,520 --> 00:32:11,700 resolve all issues. 736 00:32:12,320 --> 00:32:13,360 I think 737 00:32:15,320 --> 00:32:16,720 what happened with that, 738 00:32:16,740 --> 00:32:18,120 it took me about a week before 739 00:32:18,120 --> 00:32:19,160 I could really 740 00:32:19,160 --> 00:32:22,560 talk to, have a 741 00:32:22,560 --> 00:32:24,540 good dialogue with someone and then it was about 742 00:32:24,540 --> 00:32:26,360 a week before they actually 743 00:32:26,360 --> 00:32:28,720 pushed patches into the main 744 00:32:28,720 --> 00:32:30,640 tree, the main development tree at this 745 00:32:30,640 --> 00:32:32,420 point. I think what was happening in the 746 00:32:32,740 --> 00:32:34,480 second week was 747 00:32:34,480 --> 00:32:36,680 that some guy 748 00:32:36,680 --> 00:32:38,580 had done the changes, though very simple changes, 749 00:32:39,680 --> 00:32:40,640 done the changes 750 00:32:40,640 --> 00:32:42,560 on his own box and was doing a bit of personal 751 00:32:42,560 --> 00:32:44,760 QA and then pushed it for the other 752 00:32:45,320 --> 00:32:46,800 developers to look at as well 753 00:32:47,300 --> 00:32:48,320 back in the main 754 00:32:48,320 --> 00:32:49,980 unstable development tree. 755 00:32:50,880 --> 00:32:52,380 Which is very typical 756 00:32:52,380 --> 00:32:53,980 in a development process. 757 00:32:55,520 --> 00:32:56,460 So, if we look at 758 00:32:56,460 --> 00:32:57,300 OpenBSD now, 759 00:32:59,200 --> 00:33:00,760 probably the quickest response 760 00:33:00,760 --> 00:33:02,540 in documented history. Three minutes is 761 00:33:02,740 --> 00:33:03,580 pretty fast. 762 00:33:04,020 --> 00:33:06,620 I can't get my mum to email me 763 00:33:06,620 --> 00:33:07,540 in three minutes. 764 00:33:10,080 --> 00:33:12,020 That's insane, it's three minutes. 765 00:33:14,480 --> 00:33:16,340 Interesting thing with OpenBSD though 766 00:33:16,340 --> 00:33:18,780 was that they released an advisory 767 00:33:18,780 --> 00:33:20,700 for the select system call 768 00:33:20,700 --> 00:33:22,320 stack overflow there. 769 00:33:23,100 --> 00:33:24,700 This was shortly 770 00:33:24,700 --> 00:33:25,920 after I sent them about 771 00:33:25,920 --> 00:33:28,940 10 to 15 bugs 772 00:33:28,940 --> 00:33:30,780 and some of 773 00:33:30,780 --> 00:33:31,140 these bugs 774 00:33:33,360 --> 00:33:35,220 a bit after that they released 775 00:33:35,220 --> 00:33:36,220 the select advisory. 776 00:33:36,600 --> 00:33:38,600 What I think happened in that 777 00:33:38,600 --> 00:33:40,200 period of time was that Niels 778 00:33:40,200 --> 00:33:42,360 and probably other people 779 00:33:42,360 --> 00:33:43,600 in OpenBSD started 780 00:33:43,600 --> 00:33:46,840 at least a more concerted 781 00:33:46,840 --> 00:33:48,440 effort, if not the initial effort, 782 00:33:48,520 --> 00:33:50,140 I'm not quite sure, to 783 00:33:50,740 --> 00:33:51,900 do kernel audits here. 784 00:33:52,900 --> 00:33:54,380 So I think that was 785 00:33:54,380 --> 00:33:55,700 reasonably successful. 786 00:33:57,100 --> 00:33:58,620 Certainly they started to 787 00:33:58,620 --> 00:34:00,400 look at other issues then as well. 788 00:34:01,960 --> 00:34:02,720 Interesting thing 789 00:34:02,740 --> 00:34:04,940 also with NetBSD 790 00:34:04,940 --> 00:34:06,440 which I probably should have 791 00:34:06,440 --> 00:34:07,280 mentioned a bit before. 792 00:34:08,360 --> 00:34:10,500 When I sent NetBSD a list of problems 793 00:34:10,500 --> 00:34:12,620 some of the bugs were actually shared 794 00:34:12,620 --> 00:34:13,680 with OpenBSD as well. 795 00:34:14,440 --> 00:34:15,740 Which isn't too 796 00:34:17,160 --> 00:34:18,640 surprising. The bugs that 797 00:34:18,640 --> 00:34:20,600 were shared were primarily just driver code. 798 00:34:21,240 --> 00:34:22,680 Again, it's not 799 00:34:22,680 --> 00:34:23,620 surprising since 800 00:34:24,820 --> 00:34:26,400 OpenBSD can be considered 801 00:34:26,400 --> 00:34:27,960 a fork from NetBSD 802 00:34:27,960 --> 00:34:30,320 some time ago now. 803 00:34:30,820 --> 00:34:32,420 But some of the drivers are 804 00:34:32,740 --> 00:34:34,720 shared and some of the bugs 805 00:34:34,720 --> 00:34:35,880 were present in both. 806 00:34:36,560 --> 00:34:38,340 OpenBSD did take the 807 00:34:40,640 --> 00:34:42,300 patches for these things anyway 808 00:34:42,300 --> 00:34:44,740 for NetBSD propagated to OpenBSD 809 00:34:44,740 --> 00:34:46,540 pretty quickly 810 00:34:46,540 --> 00:34:48,500 but it was surprising to see 811 00:34:48,500 --> 00:34:49,720 the change logs in OpenBSD 812 00:34:49,720 --> 00:34:51,680 because it's like from NetBSD 813 00:34:51,680 --> 00:34:54,180 those are the integer overflows 814 00:34:54,180 --> 00:34:55,980 and the driver problems there and what not. 815 00:34:56,960 --> 00:34:57,920 So I've got 816 00:34:57,920 --> 00:34:59,300 a couple of 817 00:35:00,160 --> 00:35:02,560 I've got one change log here from the OpenBSD 818 00:35:03,600 --> 00:35:04,720 from OpenBSD. 819 00:35:04,920 --> 00:35:06,840 There's another good change log 820 00:35:06,840 --> 00:35:08,660 entry which I probably should have included 821 00:35:08,660 --> 00:35:10,240 but I'll just talk about this one for a sec. 822 00:35:10,480 --> 00:35:12,380 So this is the IBCS2 823 00:35:12,380 --> 00:35:14,420 code that I showed earlier which had 824 00:35:14,420 --> 00:35:16,400 no input validation checking at all 825 00:35:16,400 --> 00:35:18,500 and the comment in the change log 826 00:35:18,500 --> 00:35:20,680 is that more possible 827 00:35:20,680 --> 00:35:21,720 integer overflows 828 00:35:21,720 --> 00:35:23,980 are found. So 829 00:35:23,980 --> 00:35:26,860 there were no integer overflows. 830 00:35:28,160 --> 00:35:28,900 It's just 831 00:35:28,900 --> 00:35:30,260 no input validation check. 832 00:35:31,360 --> 00:35:32,480 Another interesting 833 00:35:32,740 --> 00:35:34,240 change log entry 834 00:35:34,520 --> 00:35:36,880 and this was for a couple of them 835 00:35:36,880 --> 00:35:37,640 were 836 00:35:39,780 --> 00:35:40,900 it was 837 00:35:41,560 --> 00:35:42,760 I'm just trying to 838 00:35:42,760 --> 00:35:44,280 think back to the exact wording here 839 00:35:44,280 --> 00:35:46,600 it was more possible 840 00:35:46,600 --> 00:35:47,620 integer overflows 841 00:35:48,760 --> 00:35:50,700 found by yada yada yada 842 00:35:50,700 --> 00:35:52,440 some of these are okay 843 00:35:52,440 --> 00:35:54,000 but have been changed for consistency 844 00:35:54,580 --> 00:35:56,680 and in fact all of these 845 00:35:56,680 --> 00:35:58,620 were exploitable. It wasn't some of these 846 00:35:58,620 --> 00:36:00,540 are okay. Those patches 847 00:36:00,540 --> 00:36:01,840 they were all exploitable. 848 00:36:02,740 --> 00:36:04,660 So I think 849 00:36:04,660 --> 00:36:06,300 OpenBSD is certainly 850 00:36:06,300 --> 00:36:08,140 very good but 851 00:36:08,500 --> 00:36:10,620 it's certainly interesting change logs as well. 852 00:36:12,180 --> 00:36:14,260 So the IBCS2 853 00:36:14,260 --> 00:36:15,620 stat.c code 854 00:36:16,980 --> 00:36:18,740 Linux fixed it, OpenBSD 855 00:36:18,740 --> 00:36:21,000 fixed it, NetBSD fixed it, FreeBSD 856 00:36:21,000 --> 00:36:22,580 I don't know why they've never 857 00:36:22,580 --> 00:36:24,500 fixed it. I've sent them this 858 00:36:24,500 --> 00:36:26,220 and they've just not fixed it. 859 00:36:26,320 --> 00:36:27,020 I don't know why. 860 00:36:28,100 --> 00:36:30,220 I'm really at a loss to say. 861 00:36:31,340 --> 00:36:32,680 And I also 862 00:36:32,740 --> 00:36:34,680 explain this at black and I'll explain 863 00:36:34,680 --> 00:36:36,720 it here. The reason why there is a square 864 00:36:37,160 --> 00:36:38,400 next to the FreeBSD 865 00:36:39,360 --> 00:36:40,460 line is that 866 00:36:40,460 --> 00:36:42,860 this actually was a powerpoint 867 00:36:43,460 --> 00:36:44,840 import into OpenOffice 868 00:36:44,840 --> 00:36:46,640 and it didn't have the font for the 869 00:36:46,640 --> 00:36:47,300 smiley face. 870 00:36:48,980 --> 00:36:50,620 So that's the reason for the 871 00:36:50,620 --> 00:36:52,280 square up there. There should have been a 872 00:36:52,820 --> 00:36:54,000 smiley face, a frown 873 00:36:54,840 --> 00:36:55,900 but oh well. 874 00:36:56,980 --> 00:36:58,820 So where are we today in kernel security? 875 00:37:00,980 --> 00:37:01,860 Auditing today 876 00:37:02,740 --> 00:37:04,580 always results in vulnerabilities being 877 00:37:04,580 --> 00:37:04,880 found. 878 00:37:05,980 --> 00:37:08,580 There are bugs still present in all the kernels 879 00:37:08,580 --> 00:37:10,080 and this isn't surprising 880 00:37:10,620 --> 00:37:12,120 because auditing and security 881 00:37:13,360 --> 00:37:13,920 really 882 00:37:14,680 --> 00:37:16,420 is or should be an ongoing process. 883 00:37:16,840 --> 00:37:17,940 You can't just 884 00:37:18,740 --> 00:37:20,460 audit something at some point in time and say 885 00:37:20,460 --> 00:37:22,620 it's going to be secure indefinitely. 886 00:37:23,580 --> 00:37:24,600 And certainly 887 00:37:24,600 --> 00:37:25,760 even though 888 00:37:25,760 --> 00:37:27,800 I will present 889 00:37:27,800 --> 00:37:30,740 a number of bugs and a number of bug classes 890 00:37:30,740 --> 00:37:32,360 there's certainly more things that are 891 00:37:32,740 --> 00:37:34,480 exploitable and certainly a lot more classes 892 00:37:34,480 --> 00:37:35,640 of bugs in the code as well 893 00:37:36,460 --> 00:37:38,100 than will just be described today. 894 00:37:39,380 --> 00:37:39,860 So 895 00:37:39,860 --> 00:37:41,420 a couple of months ago 896 00:37:42,540 --> 00:37:43,820 presented most of 897 00:37:43,820 --> 00:37:46,260 the bugs, a very technical 898 00:37:46,260 --> 00:37:46,800 presentation 899 00:37:48,580 --> 00:37:50,400 like basically I was going through lists 900 00:37:50,400 --> 00:37:51,480 and lists of bugs and saying 901 00:37:51,480 --> 00:37:54,020 about four months ago 902 00:37:54,900 --> 00:37:55,860 at Ruxcon 903 00:37:55,860 --> 00:37:58,260 and released some zero day 904 00:37:59,720 --> 00:38:00,980 at the time 905 00:38:00,980 --> 00:38:02,640 and some of those bugs are still 906 00:38:02,740 --> 00:38:04,520 present. I don't know why. 907 00:38:05,760 --> 00:38:06,740 So the 908 00:38:06,740 --> 00:38:08,400 cough loader for Linux 909 00:38:08,400 --> 00:38:10,580 and exploit is available 910 00:38:10,580 --> 00:38:12,040 for that on the Ruxcon website 911 00:38:12,480 --> 00:38:14,500 but I've never actually 912 00:38:14,500 --> 00:38:16,720 posted an advisory or posted 913 00:38:16,720 --> 00:38:18,860 anything to full disclosure 914 00:38:18,860 --> 00:38:19,780 or bug track or 915 00:38:20,480 --> 00:38:20,820 whatever. 916 00:38:22,820 --> 00:38:24,120 It's never been fixed. 917 00:38:24,640 --> 00:38:26,340 An obvious question 918 00:38:26,340 --> 00:38:28,660 does anyone read 919 00:38:28,660 --> 00:38:29,800 the conference materials 920 00:38:30,720 --> 00:38:32,720 and do it 921 00:38:32,740 --> 00:38:33,680 and does anything about it? 922 00:38:33,800 --> 00:38:35,780 Are we just presenting things for ourselves 923 00:38:35,780 --> 00:38:36,580 or what? 924 00:38:39,140 --> 00:38:40,740 So at this point I'm going to pause 925 00:38:40,740 --> 00:38:42,180 for audience participation and ask 926 00:38:42,180 --> 00:38:42,780 if there are any questions. 927 00:38:57,160 --> 00:38:58,680 Okay, I've actually 928 00:38:58,680 --> 00:39:00,120 got a pretty interesting question here. 929 00:39:00,400 --> 00:39:02,180 The question was that 930 00:39:02,740 --> 00:39:03,560 when I talked about 931 00:39:04,540 --> 00:39:06,020 bugs being clustered 932 00:39:06,020 --> 00:39:07,880 he was asking me if that was 933 00:39:07,880 --> 00:39:10,260 because of the way I was auditing 934 00:39:10,260 --> 00:39:12,640 and I suppose my response to that 935 00:39:12,640 --> 00:39:14,600 is I can't really 936 00:39:14,600 --> 00:39:16,640 present scientifically that 937 00:39:16,640 --> 00:39:18,200 bug clustering exists. 938 00:39:18,340 --> 00:39:20,180 All I can say is that I observed 939 00:39:20,520 --> 00:39:22,140 in my opinion bug clustering 940 00:39:22,140 --> 00:39:24,400 and it's possibly supporting evidence 941 00:39:24,400 --> 00:39:26,600 and Dawson Engler's work certainly 942 00:39:26,600 --> 00:39:28,540 talks about bug clustering and bug propagation 943 00:39:28,540 --> 00:39:29,780 and that's probably 944 00:39:30,460 --> 00:39:31,880 certainly more scientific than 945 00:39:32,740 --> 00:39:33,600 the methods that I use which 946 00:39:33,600 --> 00:39:34,700 manual auditing. 947 00:39:35,860 --> 00:39:38,540 I must admit I did look at 948 00:39:38,540 --> 00:39:40,480 certain bits of source and the sources 949 00:39:40,480 --> 00:39:41,040 around it 950 00:39:44,100 --> 00:39:46,520 in a reasonably 951 00:39:46,520 --> 00:39:48,000 close time frame so maybe 952 00:39:48,000 --> 00:39:50,480 that was the reason why I saw bug clustering. 953 00:39:51,520 --> 00:39:52,840 But it's a good question. 954 00:39:56,740 --> 00:39:58,640 Okay, I'll go to the next 955 00:39:58,640 --> 00:40:00,440 part of the presentation which is 956 00:40:00,440 --> 00:40:02,440 a sample of exploitable bugs. 957 00:40:02,740 --> 00:40:03,440 I'm actually going to 958 00:40:03,440 --> 00:40:05,780 it looks like I'm running really long here 959 00:40:05,780 --> 00:40:08,560 so I'm going to actually skip 960 00:40:08,560 --> 00:40:09,980 a few of the slides here. 961 00:40:10,600 --> 00:40:12,360 Okay, I've got a ten minute sign up there 962 00:40:12,360 --> 00:40:13,080 which is pretty good. 963 00:40:14,880 --> 00:40:16,720 I'm going to go through a couple 964 00:40:16,720 --> 00:40:18,560 of bugs and go through a couple of 965 00:40:18,560 --> 00:40:20,600 classes of ways, a couple of ways to exploit them 966 00:40:20,600 --> 00:40:20,900 as well. 967 00:40:22,280 --> 00:40:23,420 Sample of exploitable bugs. 968 00:40:24,720 --> 00:40:25,980 This was, okay, 969 00:40:26,580 --> 00:40:28,720 I'll just skip to something that's more interesting. 970 00:40:29,980 --> 00:40:30,740 If you want to 971 00:40:30,740 --> 00:40:32,660 you know, if anyone wants to talk to me about 972 00:40:32,740 --> 00:40:33,900 this after the presentation, 973 00:40:34,220 --> 00:40:34,920 that's fine. 974 00:40:36,960 --> 00:40:38,700 So I'll go to something 975 00:40:38,700 --> 00:40:40,620 that's, okay, 976 00:40:40,700 --> 00:40:41,780 this one is interesting. 977 00:40:42,720 --> 00:40:44,580 What we have here is that we 978 00:40:44,580 --> 00:40:46,680 have, and I know that 979 00:40:46,680 --> 00:40:48,540 no one can read this so I'll try 980 00:40:48,540 --> 00:40:49,240 to explain it. 981 00:40:50,000 --> 00:40:52,180 We have a memory allocation 982 00:40:52,660 --> 00:40:54,640 and we have memory 983 00:40:54,640 --> 00:40:56,740 allocation of something like a size of, 984 00:40:56,800 --> 00:40:57,960 a long times, 985 00:40:58,580 --> 00:41:00,260 you know, something plus a one 986 00:41:00,260 --> 00:41:02,660 and then down below we have 987 00:41:02,740 --> 00:41:04,760 a copy out call 988 00:41:04,760 --> 00:41:06,680 which is a kernel buffer copy 989 00:41:08,120 --> 00:41:09,900 from kernel space to user space 990 00:41:10,500 --> 00:41:12,520 and the copy out call does something like 991 00:41:12,520 --> 00:41:14,200 a size of, a long times, 992 00:41:14,200 --> 00:41:15,380 you know, this size thing 993 00:41:15,380 --> 00:41:18,240 and so basically one of the problems that 994 00:41:19,100 --> 00:41:20,380 I've seen a lot 995 00:41:20,380 --> 00:41:21,840 in programming 996 00:41:21,840 --> 00:41:24,460 is that when people are doing things like 997 00:41:24,460 --> 00:41:26,800 memory allocations and using one expression 998 00:41:26,800 --> 00:41:28,060 to calculate these lengths 999 00:41:28,060 --> 00:41:30,580 and then they're doing buffer copies using these 1000 00:41:30,580 --> 00:41:32,320 you know, these other expressions 1001 00:41:32,740 --> 00:41:34,600 or they're doing input validation checks 1002 00:41:34,600 --> 00:41:36,600 using one expression and then buffer copies 1003 00:41:36,600 --> 00:41:38,640 using another expression, typically always 1004 00:41:38,640 --> 00:41:40,680 they lead themselves into problems 1005 00:41:40,680 --> 00:41:42,620 because you can, many times 1006 00:41:42,620 --> 00:41:44,580 you can get, you know, the first expression to do, 1007 00:41:44,660 --> 00:41:46,160 you know, come out with one answer 1008 00:41:46,620 --> 00:41:48,460 and the second one to come out with something else 1009 00:41:48,460 --> 00:41:50,480 using integer overflows and what not 1010 00:41:50,480 --> 00:41:52,240 so that seems to be a problem 1011 00:41:52,740 --> 00:41:54,720 that exists, when you see 1012 00:41:54,720 --> 00:41:56,380 code like that and they say okay 1013 00:41:56,380 --> 00:41:58,700 they're using one expression here and another expression down below 1014 00:41:59,140 --> 00:42:00,580 it's very, very often 1015 00:42:00,580 --> 00:42:01,840 that it's exploitable in some way. 1016 00:42:04,120 --> 00:42:05,000 This one, 1017 00:42:05,100 --> 00:42:06,740 another interesting case 1018 00:42:06,740 --> 00:42:08,300 we take a minimum here 1019 00:42:08,300 --> 00:42:10,660 a minimum 1020 00:42:10,660 --> 00:42:11,400 of two values 1021 00:42:12,280 --> 00:42:14,600 one of those values we control from a 1022 00:42:14,600 --> 00:42:15,300 syscall argument 1023 00:42:17,500 --> 00:42:18,460 but the 1024 00:42:18,460 --> 00:42:19,780 point here is that 1025 00:42:19,780 --> 00:42:22,680 we control a syscall argument and we can make it a negative 1026 00:42:22,680 --> 00:42:24,580 so when we take the minimum of these 1027 00:42:24,580 --> 00:42:25,600 two values here 1028 00:42:26,960 --> 00:42:28,580 you know, we're going to come up with a negative 1029 00:42:28,580 --> 00:42:30,640 so then we do a 1030 00:42:30,640 --> 00:42:32,600 copy out later on using this length which is 1031 00:42:32,740 --> 00:42:34,440 was a negative now becomes a positive 1032 00:42:34,440 --> 00:42:36,360 I got a sign 1033 00:42:36,360 --> 00:42:38,460 that I had five minutes ago so I'll 1034 00:42:38,460 --> 00:42:40,600 I'll skip most of these 1035 00:42:40,600 --> 00:42:42,440 actually and I'll go to 1036 00:42:42,440 --> 00:42:44,200 some ways to exploit 1037 00:42:53,260 --> 00:42:54,540 Here's an example of what 1038 00:42:54,540 --> 00:42:55,980 I was just talking about a second ago 1039 00:42:56,540 --> 00:42:58,700 we have a validation check 1040 00:42:58,700 --> 00:43:00,080 on this count value here 1041 00:43:00,080 --> 00:43:02,720 this is in the PCI hot plug core.cq 1042 00:43:02,740 --> 00:43:03,360 which is 1043 00:43:05,160 --> 00:43:06,200 Linux code 1044 00:43:06,720 --> 00:43:08,320 and we seem to have lost 1045 00:43:08,320 --> 00:43:09,660 one of the 1046 00:43:10,900 --> 00:43:12,620 I'll look at this one now 1047 00:43:12,620 --> 00:43:14,460 we seem to have 1048 00:43:15,100 --> 00:43:16,540 so we do a validation 1049 00:43:16,540 --> 00:43:17,740 check on this count 1050 00:43:17,740 --> 00:43:20,600 and we check if count is less than or equal 1051 00:43:20,600 --> 00:43:22,580 to zero but then we do 1052 00:43:22,580 --> 00:43:24,400 a memory allocation using count plus one 1053 00:43:25,620 --> 00:43:26,700 so now we 1054 00:43:26,700 --> 00:43:28,220 have integer overflow 1055 00:43:28,580 --> 00:43:30,520 when we make count the size 1056 00:43:30,520 --> 00:43:31,300 of uintmax 1057 00:43:33,280 --> 00:43:35,140 we can get count plus one 1058 00:43:35,140 --> 00:43:36,820 to wrap around back to zero 1059 00:43:36,820 --> 00:43:39,680 and k-mallocing zero bytes 1060 00:43:39,680 --> 00:43:40,440 will return 1061 00:43:40,440 --> 00:43:42,620 successful providing 1062 00:43:42,620 --> 00:43:44,720 we can perform a memory allocation 1063 00:43:44,720 --> 00:43:45,460 to begin with 1064 00:43:47,800 --> 00:43:48,840 interesting bug 1065 00:43:48,840 --> 00:43:50,660 that I really do want to talk about 1066 00:43:52,040 --> 00:43:52,920 this is 1067 00:43:52,920 --> 00:43:54,760 very prevalent 1068 00:43:54,760 --> 00:43:56,680 in a lot of the 2.2 Linux code 1069 00:43:56,680 --> 00:43:58,100 and most of the 2.4 1070 00:43:59,060 --> 00:44:00,620 this is what I was talking about before 1071 00:44:00,620 --> 00:44:02,200 when you lseq 1072 00:44:02,740 --> 00:44:04,080 to around 4 gig 1073 00:44:04,080 --> 00:44:05,860 we take the file pointer 1074 00:44:06,480 --> 00:44:08,380 which typically is 64 bits 1075 00:44:08,380 --> 00:44:11,300 but in some cases 1076 00:44:11,300 --> 00:44:12,340 people screw up the prototypes 1077 00:44:12,340 --> 00:44:13,620 and that causes problems 1078 00:44:13,620 --> 00:44:17,260 and they cast it to a int 1079 00:44:17,260 --> 00:44:19,340 and then they've had the file pointer 1080 00:44:19,340 --> 00:44:20,620 which is cast now as 1081 00:44:20,620 --> 00:44:22,380 32 bit sign value 1082 00:44:22,380 --> 00:44:24,480 plus the count which we're reading 1083 00:44:24,480 --> 00:44:27,200 and that itself is an integer overflow 1084 00:44:27,200 --> 00:44:28,520 and causes memory disclosure 1085 00:44:29,160 --> 00:44:29,980 later on 1086 00:44:30,860 --> 00:44:32,720 ok I'm going to skip at this point 1087 00:44:32,740 --> 00:44:33,240 to 1088 00:44:34,340 --> 00:44:34,940 some 1089 00:44:38,060 --> 00:44:38,660 ok 1090 00:44:38,660 --> 00:44:41,160 I won't pause for audience participation 1091 00:44:41,160 --> 00:44:42,520 and kernel exploitation 1092 00:44:45,080 --> 00:44:46,920 so there are two things 1093 00:44:46,920 --> 00:44:47,320 that are 1094 00:44:47,320 --> 00:44:49,540 two classes of exploits 1095 00:44:49,540 --> 00:44:50,680 that we should look at here 1096 00:44:50,680 --> 00:44:51,960 arbitrary code execution 1097 00:44:51,960 --> 00:44:53,600 and information disclosure 1098 00:44:53,600 --> 00:44:55,720 so for arbitrary code execution 1099 00:44:55,720 --> 00:44:58,540 obviously the best form of exploitation 1100 00:44:58,540 --> 00:45:00,840 that we have can give us a root shell 1101 00:45:02,740 --> 00:45:04,020 privilege escalation 1102 00:45:04,500 --> 00:45:06,240 escape kernel sandboxing 1103 00:45:06,540 --> 00:45:08,240 security enhanced linux for example 1104 00:45:08,240 --> 00:45:09,240 user mode linux 1105 00:45:09,240 --> 00:45:11,460 if we look at digital rights management 1106 00:45:12,260 --> 00:45:13,920 say for example 1107 00:45:13,920 --> 00:45:15,540 we have a certain kernel version 1108 00:45:15,540 --> 00:45:17,460 or a certain distro that is signed 1109 00:45:17,460 --> 00:45:18,720 and it says that 1110 00:45:18,720 --> 00:45:20,440 when you view this website 1111 00:45:20,440 --> 00:45:22,520 you can't actually save any streaming content 1112 00:45:22,520 --> 00:45:23,300 or so forth 1113 00:45:23,300 --> 00:45:26,660 however if we have vulnerabilities in this software 1114 00:45:28,520 --> 00:45:30,320 we can control it at that point 1115 00:45:30,320 --> 00:45:31,540 and we can make the software do 1116 00:45:32,070 --> 00:45:33,180 something else than 1117 00:45:33,180 --> 00:45:35,600 what the DRM people say it should do 1118 00:45:36,320 --> 00:45:36,940 ultimately 1119 00:45:38,150 --> 00:45:39,120 in the 1120 00:45:40,140 --> 00:45:42,240 trusted computing doesn't actually 1121 00:45:42,240 --> 00:45:43,640 provide any software assurance 1122 00:45:44,320 --> 00:45:46,240 trusted computing is basically just 1123 00:45:47,860 --> 00:45:48,960 breaking policy 1124 00:45:48,960 --> 00:45:50,260 at well defined 1125 00:45:51,140 --> 00:45:52,460 sequence points 1126 00:45:52,460 --> 00:45:54,020 and having trust relationships 1127 00:45:54,020 --> 00:45:55,440 but if your trusted 1128 00:45:55,440 --> 00:45:57,240 computing base or so forth 1129 00:45:58,120 --> 00:45:59,280 is vulnerable 1130 00:46:00,320 --> 00:46:01,680 or has hidden features 1131 00:46:02,800 --> 00:46:03,840 then you know 1132 00:46:03,840 --> 00:46:06,080 certainly other things 1133 00:46:06,080 --> 00:46:06,740 are possible there 1134 00:46:06,740 --> 00:46:09,780 seems to be the case 1135 00:46:09,780 --> 00:46:11,300 if your trusted computing base is flawed 1136 00:46:11,300 --> 00:46:13,260 and certainly in 1137 00:46:13,260 --> 00:46:14,840 all of these things 1138 00:46:14,840 --> 00:46:17,380 the kernel is seen as the trusted entity 1139 00:46:17,380 --> 00:46:19,640 then ultimately system security is compromised 1140 00:46:20,320 --> 00:46:21,880 we have information disclosure 1141 00:46:21,880 --> 00:46:22,520 as well 1142 00:46:24,280 --> 00:46:25,420 such as 1143 00:46:27,500 --> 00:46:28,860 thank you 1144 00:46:30,320 --> 00:46:30,920 and we will now 1145 00:46:30,920 --> 00:46:31,780 SSH private keys 1146 00:46:31,780 --> 00:46:35,040 if we can read arbitrary kernel memory 1147 00:46:35,040 --> 00:46:37,780 we might be able to sneak out 1148 00:46:37,780 --> 00:46:39,040 an SSH private key 1149 00:46:39,040 --> 00:46:41,160 I will just pause for one second 1150 00:46:42,460 --> 00:46:44,420 I have 10 minutes 1151 00:46:48,300 --> 00:46:50,000 5 minutes is fine 1152 00:46:50,000 --> 00:46:51,360 yeah you can get 5 minutes 1153 00:46:52,120 --> 00:46:52,800 okay 1154 00:46:52,800 --> 00:46:54,540 5 more minutes 1155 00:46:54,540 --> 00:46:57,260 and I will be tackled off stage 1156 00:46:57,260 --> 00:46:58,480 so 1157 00:46:59,620 --> 00:47:00,300 I'm going to 1158 00:47:00,320 --> 00:47:02,140 I'll try to 1159 00:47:02,140 --> 00:47:03,680 get in as much as possible here 1160 00:47:04,780 --> 00:47:06,380 has been prior work 1161 00:47:06,380 --> 00:47:07,300 to kernel exploitation 1162 00:47:08,160 --> 00:47:09,920 Noir in FRAC 60 1163 00:47:10,600 --> 00:47:11,620 wrote a great 1164 00:47:12,300 --> 00:47:12,900 article 1165 00:47:12,900 --> 00:47:15,980 on smashing the kernel stack 1166 00:47:15,980 --> 00:47:16,740 for fun and profit 1167 00:47:17,660 --> 00:47:18,900 this was an implementation 1168 00:47:18,900 --> 00:47:21,820 of exploiting 1169 00:47:21,820 --> 00:47:23,340 the open BSD 1170 00:47:23,340 --> 00:47:24,440 kernel stack overflow 1171 00:47:24,440 --> 00:47:27,360 there have been other exploits 1172 00:47:27,360 --> 00:47:28,780 in the past from 1173 00:47:30,320 --> 00:47:31,840 Dolores and FreeBSD and what not 1174 00:47:34,580 --> 00:47:36,280 but in the general case 1175 00:47:36,280 --> 00:47:37,760 it's seen that 1176 00:47:38,320 --> 00:47:39,600 there aren't generic ways 1177 00:47:39,600 --> 00:47:40,440 of attacking the kernel 1178 00:47:40,440 --> 00:47:41,500 which was probably a good thing 1179 00:47:41,500 --> 00:47:42,600 otherwise because he showed 1180 00:47:42,600 --> 00:47:44,560 a class of bugs there 1181 00:47:45,540 --> 00:47:46,580 kernel implementation 1182 00:47:47,660 --> 00:47:49,040 all the kernels are written in C 1183 00:47:49,700 --> 00:47:51,260 C has known bugs 1184 00:47:51,260 --> 00:47:52,360 known problems 1185 00:47:52,360 --> 00:47:53,260 known pitfalls 1186 00:47:54,080 --> 00:47:55,120 attack the language 1187 00:47:55,120 --> 00:47:56,700 attack the implementation 1188 00:48:00,420 --> 00:48:02,080 method of attack 1189 00:48:02,080 --> 00:48:03,660 but a very effective one too 1190 00:48:05,040 --> 00:48:06,620 C has some pitfalls 1191 00:48:06,620 --> 00:48:08,100 I won't talk about these 1192 00:48:08,100 --> 00:48:08,840 but 1193 00:48:10,880 --> 00:48:12,500 C has lots of problems 1194 00:48:12,500 --> 00:48:14,120 and they've been seen 1195 00:48:14,120 --> 00:48:14,980 time and time again 1196 00:48:14,980 --> 00:48:17,080 for many many years now 1197 00:48:17,080 --> 00:48:19,920 since the 1970s at least 1198 00:48:22,140 --> 00:48:22,660 so 1199 00:48:22,660 --> 00:48:26,180 there are problems 1200 00:48:26,180 --> 00:48:27,320 in pretty much all code 1201 00:48:27,320 --> 00:48:28,880 not just user land or kernel code 1202 00:48:30,320 --> 00:48:30,540 it probably has 1203 00:48:30,540 --> 00:48:32,820 the same classes of bugs 1204 00:48:32,820 --> 00:48:34,640 that people are looking for 1205 00:48:35,400 --> 00:48:36,520 and all code 1206 00:48:36,520 --> 00:48:39,400 we can find bugs 1207 00:48:39,400 --> 00:48:41,640 in lots and lots of code 1208 00:48:43,680 --> 00:48:45,240 I will skip this because 1209 00:48:45,240 --> 00:48:47,100 I've talked about it earlier on 1210 00:48:50,540 --> 00:48:51,140 so 1211 00:48:54,420 --> 00:48:55,340 when we 1212 00:48:56,300 --> 00:48:57,120 what we 1213 00:48:57,120 --> 00:49:00,240 if we look at kernel buffer 1214 00:49:00,320 --> 00:49:00,860 copy is okay 1215 00:49:00,860 --> 00:49:03,140 we can think of kernel and user space 1216 00:49:03,140 --> 00:49:05,740 divided into segments 1217 00:49:06,100 --> 00:49:07,900 kernel space is a segment 1218 00:49:07,900 --> 00:49:09,380 user space is a segment 1219 00:49:09,380 --> 00:49:11,540 when we do a kernel buffer copy 1220 00:49:11,540 --> 00:49:12,400 we need to validate 1221 00:49:13,400 --> 00:49:14,920 the source and destination 1222 00:49:14,920 --> 00:49:17,480 that they reside in the right segments 1223 00:49:17,480 --> 00:49:19,920 so that when we're copying something from kernel space 1224 00:49:19,920 --> 00:49:20,700 to user space 1225 00:49:21,460 --> 00:49:23,740 we are in fact copying it from kernel space 1226 00:49:23,740 --> 00:49:24,800 to user space 1227 00:49:24,800 --> 00:49:27,760 we're not putting in values such as 0xc 1228 00:49:28,320 --> 00:49:30,040 something something something which represents 1229 00:49:30,320 --> 00:49:32,480 kernel space to a read or a write 1230 00:49:32,480 --> 00:49:33,620 system call or so forth 1231 00:49:34,860 --> 00:49:36,280 for example here 1232 00:49:36,280 --> 00:49:37,460 if we were able to 1233 00:49:38,180 --> 00:49:38,860 read something 1234 00:49:39,940 --> 00:49:40,980 from the network 1235 00:49:40,980 --> 00:49:44,100 and it was possible to put in an address 1236 00:49:44,100 --> 00:49:46,320 such as 0xc104 1237 00:49:46,960 --> 00:49:47,540 you know 1238 00:49:47,540 --> 00:49:48,220 whatever 1239 00:49:48,220 --> 00:49:50,900 if there was no validation done 1240 00:49:50,900 --> 00:49:52,360 we'd actually read this data 1241 00:49:52,360 --> 00:49:53,800 into the kernel segment 1242 00:49:53,800 --> 00:49:56,380 and overwrite kernel structures 1243 00:49:56,380 --> 00:49:58,060 or executable code 1244 00:50:00,320 --> 00:50:00,820 and if that was the case 1245 00:50:00,820 --> 00:50:02,540 that we could read into kernel space 1246 00:50:02,540 --> 00:50:05,780 then we could certainly exploit the kernel here 1247 00:50:10,000 --> 00:50:10,560 okay 1248 00:50:11,460 --> 00:50:14,320 we have a FreeBSD sysexcept 1249 00:50:15,140 --> 00:50:15,980 exploit here 1250 00:50:15,980 --> 00:50:17,740 and I just wanted to show this code 1251 00:50:17,740 --> 00:50:20,860 it's about 30, 37 or 38 lines 1252 00:50:20,860 --> 00:50:21,860 what I said before 1253 00:50:21,860 --> 00:50:23,680 and the way to exploit this 1254 00:50:23,680 --> 00:50:24,820 is pretty straight forward 1255 00:50:24,820 --> 00:50:27,120 the except system call 1256 00:50:27,120 --> 00:50:28,220 takes three arguments 1257 00:50:30,320 --> 00:50:31,960 the first argument is a socket 1258 00:50:31,960 --> 00:50:34,460 the second argument is a socket address 1259 00:50:34,460 --> 00:50:36,040 and the third argument 1260 00:50:36,040 --> 00:50:37,280 is the socket address link 1261 00:50:37,280 --> 00:50:39,220 we simply point 1262 00:50:39,220 --> 00:50:40,540 the socket address 1263 00:50:41,420 --> 00:50:42,900 to a user space buffer 1264 00:50:43,820 --> 00:50:45,700 and then in our 1265 00:50:46,060 --> 00:50:48,420 and then in our 1266 00:50:48,420 --> 00:50:49,380 socket address link 1267 00:50:50,060 --> 00:50:51,520 we pass to it a negative value 1268 00:50:52,060 --> 00:50:53,880 and I'm just about to get thrown off stage 1269 00:50:53,880 --> 00:50:56,360 so I'm gonna wrap up right now 1270 00:50:56,360 --> 00:50:57,180 okay 1271 00:50:57,180 --> 00:50:59,860 thank you very much everyone 1272 00:51:00,320 --> 00:51:01,700 I hope you enjoyed my presentation 1273 00:51:13,040 --> 00:51:14,460 I just wanted to say 1274 00:51:14,460 --> 00:51:14,940 one more thing 1275 00:51:16,900 --> 00:51:17,900 if anyone 1276 00:51:17,900 --> 00:51:20,400 wanted to continue this 1277 00:51:20,400 --> 00:51:21,420 or have any questions 1278 00:51:21,420 --> 00:51:23,160 you can see me outside 1279 00:51:23,160 --> 00:51:25,220 or right now 1280 00:51:25,220 --> 00:51:26,680 somewhere else anyway 1281 00:51:26,680 --> 00:51:27,720 but thank you 1282 00:51:33,080 --> 00:51:33,720 for watching 1283 00:51:33,720 --> 00:51:34,200 and I'll see you next time 1284 00:51:34,200 --> 00:51:35,020 bye bye