00:00:00.834-->00:00:05.839 >> Please join me in welcoming Matt King. [applause] >> Uh thank you, so I’m here to talk 00:00:10.277-->00:00:14.281 today about a tool I wrote called Micro-Reno- Micro-Renovator uh its for 00:00:14.281-->00:00:20.454 patching CPU microcode and I really hope none of you have to use it. Um, so I’m Matt. Uh some 00:00:20.454-->00:00:26.793 quick things about me that become relevant real quick here. I used to actually work 00:00:26.793-->00:00:31.798 designing CPUs. Uh currently I work at a cloud doing hardware security things and in between 00:00:34.034-->00:00:39.039 uh I did product security validation for desktop CPUs for a very popular CPU vendor. And 00:00:41.508-->00:00:46.513 uh about that, um, sorry. Uh I may, may have missed something. Uh didn’t see it coming. So uh 00:00:51.285-->00:00:57.357 this was a really big deal uh the bugs were actually in the hardware uh real hard to fix, 00:00:57.357-->00:01:01.561 but there were patches, uh an there were several different kinds of patches for the 00:01:01.561-->00:01:06.066 different kinds of bugs and so that’s really what we’re talking here today is about some of 00:01:06.066-->00:01:12.539 those patches. Um, a little bit of background, right, so everybody remembers Meltdown uh 00:01:12.539-->00:01:17.411 that was fixed by patching the operating system kernels uh and that was all there was to it. 00:01:17.411-->00:01:23.250 You go, you patch your kernel uh it fixes the issue you’re not vulnerable to the exploit 00:01:23.250-->00:01:28.255 anymore so kernel patching, not fun, but pretty straightforward. Uh Spectre v1 required more 00:01:31.291-->00:01:36.296 patching um because you had to go patch everything that had the new Speculation gadgets in it. 00:01:38.732-->00:01:44.871 So not just kernels, browsers, sandboxes uh damens and anything that could be potentially be 00:01:44.871-->00:01:51.244 used uh we just saw net spectre which was exploiting Spectre in a network connected damen, so 00:01:51.244-->00:01:57.384 lots of software to patch. But still just software uh still pretty straightforward, we know 00:01:57.384-->00:02:01.989 how to patch software, its inconvenient, but we can do it, uh but some of the other 00:02:01.989-->00:02:06.994 variations, um to if you uh don’t trust the retpoline fix and 4 uh required microcode 00:02:09.596-->00:02:14.601 changes and um this means you have to actually go patch the CPU firmware in order for the 00:02:16.837-->00:02:21.008 software fixes to take effect. So you have to do two things, which is, you have to get the 00:02:21.008-->00:02:24.678 kernel patches to you use the new microcode but then you have to actually update the processor 00:02:24.678-->00:02:31.585 firmware so that the uh the new capabilities are exposed to the operating system so it can use 00:02:31.585-->00:02:36.590 them to protect you from these bugs. So what is microcode? We have to patch it. But not a lot 00:02:38.792-->00:02:44.731 of people really understand much about microcode or what it is. Uh for today we’re just going to 00:02:44.731-->00:02:49.636 treat it like firmware. Right? It’s firmware that you load onto your processor. Um I’m not going 00:02:49.636-->00:02:54.307 to go into a whole lot more depth about it, um that is a link on the slides you can click 00:02:54.307-->00:02:59.312 it. It is very inaccurate, it is not brief. Um, there’s a lot there and it it would waste my 00:03:01.815-->00:03:06.820 whole time slot to go into it. Um, but like other kinds of firmware, it can be patched, uh 00:03:09.656-->00:03:15.562 and it happens semi regularly to fix bugs and other radi and this was not really any different. 00:03:15.562-->00:03:20.133 Spectre wasn’t using any new capability in the CPU that didn’t exist before, it was just 00:03:20.133-->00:03:25.138 using the standard microcode patch to to load this uh to add the new capabilities. The big 00:03:27.240-->00:03:34.081 difference about microcode versus other types of firmware um processors don’t have 00:03:34.081-->00:03:39.719 persistent storage. So when you load a microcode patch, it only stays until the next time you 00:03:39.719-->00:03:44.724 reset the CPU or turn it off or reboot, um, even going to sleep causes the microcode patch to 00:03:46.893-->00:03:52.866 get lost because its just stored non-persistently. So anytime the CPU loses power, it goes away 00:03:52.866-->00:03:57.871 and you have to reload it when the system comes back up. Um, that means that some bit of 00:04:01.675-->00:04:06.746 software has to store this patch file and reload it very early on when you turn the system back 00:04:06.746-->00:04:13.520 on. Um this is generally then done by either your BIOS or your operating system. Um and it 00:04:13.520-->00:04:19.226 happens every time you boot right? Either BIOS does it or the operating system does it on 00:04:19.226-->00:04:26.032 every boot, every reset, every wake from sleep. Um, anything that really changes the state of 00:04:26.032-->00:04:31.304 the processor and causes that to go away, so they have to be aware of the patch. They have to 00:04:31.304-->00:04:35.976 know it’s there and they have to remember to reload it because if the system is depending on that 00:04:35.976-->00:04:42.949 patch and you go through a sleep wake cycle and you lose it and it’s not there when you come 00:04:42.949-->00:04:49.556 back and something is expecting it, uh it will halt the system. So because these patches are 00:04:49.556-->00:04:55.362 being reapplied by uh either BIOS or the OS that’s generally where we get them from. Right? 00:04:55.362-->00:05:00.734 When you when you need new microcode, you can go to Intel’s website and download it, but 00:05:00.734-->00:05:07.140 that doesn’t do a lot because you still have to get some of your software to load it. And so 00:05:07.140-->00:05:12.913 uh BIOS updates are the most reliable way of doing it but like quick show of hands. Who 00:05:12.913-->00:05:17.717 goes to their laptop vendor’s website you know weekly, checks for BIOS updates and downloads 00:05:17.717-->00:05:23.190 them? Ok, I see at least a couple liars in the audience. [laughter] Um, the common way, 00:05:23.190-->00:05:28.628 so really unless you’re running like a Macbook or a surface where you’re OS updates are also 00:05:28.628-->00:05:33.867 your firmware updates, it tends to not happen reliably. Um the other common method is your 00:05:33.867-->00:05:38.772 operating system will distribute the updates, you’ll get them from Microsoft, they’ll drop 00:05:38.772-->00:05:42.375 them in a package and they’ll redistribute them through the normal OS update mechanism. Um 00:05:42.375-->00:05:48.915 this has been working pretty well on Linux. But it’s been going less well on Microsoft. Uh 00:05:48.915-->00:05:53.453 it took Microsoft about two months before they started redistributing the microcode 00:05:53.453-->00:06:00.260 updates uh and it was four or five months before they were doing it for most of the Intel 00:06:00.260-->00:06:05.565 CPUs, they sort of rolled them out slowly for older and older generations of CPUs and they’re 00:06:05.565-->00:06:09.769 still only doing this in Windows 10. So if you have an older version of Windows on your 00:06:09.769-->00:06:16.009 laptop, you can’t actually get fully patched for Spectre. Even though Intel has issued the 00:06:16.009-->00:06:21.481 patches, Microsoft has patched their kernel. You have no way to apply the microcode. Um I have a 00:06:21.481-->00:06:26.353 system at home that is in this state. That I can’t actually patch for Spectre using any 00:06:26.353-->00:06:31.057 officially supported tool right now. Uh even though all the patches I need exist. And that 00:06:31.057-->00:06:36.062 is a little frustrating. So, um. There are and and I say, many systems, so I I went digging um 00:06:45.672-->00:06:50.677 there’s not just a system, there’s millions. And really the only fix is to go buy a new 00:06:53.513-->00:06:58.918 computer if you’re vendor’s not doing a BIOS update or go buy a new operating system if you’re 00:06:58.918-->00:07:04.658 still if you’re new enough to be supported by Windows 10. Um this is Windows PCs that were about 3 00:07:04.658-->00:07:09.863 to 9 years old um anything older Intel has said they can’t actually issue microcode patch 00:07:09.863-->00:07:16.436 for, so they don’t exist. Uh anything less than about 3 years old shipped with Windows 10 00:07:16.436-->00:07:21.441 initially, so it’s not a problem there, um but BIOS updates are not coming quickly from a lot of 00:07:23.743-->00:07:29.049 these things. Uh so there are at least a couple third party microcode update drivers that 00:07:29.049-->00:07:34.254 you can run in Windows, but they don’t actually work to patch Spectre. They will update your 00:07:34.254-->00:07:40.226 microcode, but by the time you do so, uh the Windows kernel has already started up, tried to 00:07:40.226-->00:07:46.566 find the new capabilities, failed to do so uh early in boot and decided it can’t use them. 00:07:46.566-->00:07:50.937 So it will run a long and you’ll have the new microcode, but the kernel will not be making use of 00:07:50.937-->00:07:57.744 it at that point. Um, based on the publically available data I can find, there is somewhere on 00:07:57.744-->00:08:03.550 the order of two and a half billion Intel CPUs that shipped. Uh Core I series, which are the 00:08:03.550-->00:08:09.489 ones getting patches. And something like half a billion of them maybe can’t actually update 00:08:09.489-->00:08:14.427 right now. Uh if anybody has better data, I’m happy to update my spreadsheet that I used to 00:08:14.427-->00:08:21.034 generate this. Um, but if you look around and I did go look around, most lapt- most systems 00:08:21.034-->00:08:26.039 less than er 6 generation and beyond which is Skylake are getting BIOS updates, um fourth 00:08:28.608-->00:08:32.545 and fifth generation it’s kind of spotty. It’s a mix. Some vendors have done it, some 00:08:32.545-->00:08:38.251 haven’t. And anything third generation or older I’ve only seen BIOS updates for Xeon 00:08:38.251-->00:08:44.257 platforms. So no laptop or desktop systems are really getting updates there. Uh, so 00:08:44.257-->00:08:50.997 this sucks. Right. That’s a lot of systems that can’t patch. Uh in my case I only have one that 00:08:50.997-->00:08:56.903 I actually can’t patch that I care about, but that’s still one too many. Um, so I started 00:08:56.903-->00:09:03.042 thinking when can these microcode updates be applied, right? Um. BIOS can do it, but I 00:09:03.042-->00:09:09.416 can’t actually go modify my BIOS. Uh it’s assigned package, if I change microcode file in 00:09:09.416-->00:09:14.921 there, it won’t work, it will fail the signature check. Uh the same thing with the OS, the 00:09:14.921-->00:09:19.626 built in files are all assigned drivers by Microsoft, I can’t change them or they’ll stop 00:09:19.626-->00:09:25.265 working. So wh- where else can I do this? Maybe in the Bootloader. Um, so I went 00:09:25.265-->00:09:31.171 looking and unfortunately there was no EFI utility in existence earlier this year that could 00:09:31.171-->00:09:36.176 actually do a microcode load from an EFI shell or an EFI environment. Um, the code to do 00:09:38.645-->00:09:43.650 it is already a part of the open source UFI code base, but it basically had hard pointed the 00:09:45.885-->00:09:50.890 data file to use uh to the you know known location that I could modify. Um this is this is all 00:09:53.093-->00:09:59.866 open source code, right? And the code’s there. Uh, how hard could it be to to turn it into 00:09:59.866-->00:10:03.403 something I could run myself. And I see people in the front snickering because the first 00:10:03.403-->00:10:07.640 time I tried to actually build something in EFI it took to better part of a day to get a 00:10:07.640-->00:10:13.413 working build environment, so when I ask myself how hard could this be, uh I knew, I knew what 00:10:13.413-->00:10:18.151 I was going into and I expected this was going to take me um months of effort just to get 00:10:18.151-->00:10:23.156 like “hello world” to build. Uh but it didn’t. Uh EDK2 has come a really long way uh I had a 00:10:27.827-->00:10:31.264 functioning build environment in less than half an hour and that was mostly because I screwed up 00:10:31.264-->00:10:37.036 installing a couple dependencies on the first try. Um so i started cutting pasting code 00:10:37.036-->00:10:42.041 from the existing update routine into a stand alone app that I could run myself and it worked. 00:10:44.043-->00:10:48.114 That was, I expected this to be a more interesting part of the talk, but it really wasn’t 00:10:48.114-->00:10:52.552 because it was a few hundred lines of codes that I copied. [laughter] Ok, so now I’ve got 00:10:52.552-->00:10:57.557 this, I need to run it. Uh, BIOS you know has a, or UEFI because this only works for UEFI boot 00:11:05.865-->00:11:11.538 um. But its a its a pretty simple flow, it does a whole bunch of flow we don’t actually 00:11:11.538-->00:11:16.976 care about right now. Uh we don’t have to understand. Um and then it goes and runs an EFI 00:11:16.976-->00:11:21.915 applications, right? It normally that EFI application is your Windows boot loader, but it 00:11:21.915-->00:11:27.353 doesn’t have to be. You can change that and we can run our application first, and then run 00:11:27.353-->00:11:32.358 the Windows bootloader after it finishes. So let’s try that. Uh, so you can see this is the the 00:11:35.895-->00:11:41.634 Windows booted up, you can see from the top line that’s in red that the hardware support 00:11:41.634-->00:11:45.838 provided by the new microcode was not there. Uh that’s what the top line meant, it just said 00:11:45.838-->00:11:51.244 that the hardware support wasn’t ready. Um so we’re gonna reboot and we’re gonna drop into an EFI 00:11:51.244-->00:11:56.616 shell. There it is. And you’re going to see it parses the microcode file that’s the 00:11:56.616-->00:12:01.721 section in the middle, it’s telling you about it. And then that section at the bottom 00:12:01.721-->00:12:06.726 there’s four threads in this system. It loaded the microcode to all four threads. And then we 00:12:06.726-->00:12:13.600 start running the Windows bootloader again. Um, I added some breakpoints in there so you 00:12:13.600-->00:12:18.805 can see because uh without them it only takes like maybe a second and you wouldn’t have had 00:12:18.805-->00:12:24.611 time to see it. So it does make boot a little bit longer, but not substantially. Uh and now 00:12:24.611-->00:12:29.616 back in Windows hopefully this will get up soon and there we go and now you can see uh it’s 00:12:32.518-->00:12:39.392 green. The hardware supports there, it detected the new microcode and we are patched. 00:12:39.392-->00:12:44.397 [applause] So I wrote some script to install this automatically, uh it goes and it 00:12:50.703-->00:12:56.843 modifies the EFI boot partition on a Windows system to load the microcode loader app uh it runs 00:12:56.843-->00:13:03.049 off a Linux live CD so you can just take like a ubunktu or Fedora live CD image based off 00:13:03.049-->00:13:08.521 their website. Uh boot into it, check out the get, this repo from GitHub um and run the 00:13:08.521-->00:13:14.894 installer. And it will go and it will detect your CPU version, it will try to find updated 00:13:14.894-->00:13:20.266 microcode for it uh and then it will copy that and all the EFI apps it needs onto the boot 00:13:20.266-->00:13:23.836 partition and set them as the default boot target so that it will run before the Windows 00:13:23.836-->00:13:28.841 bootloader on every startup. Uh, there are some limitations. So as I mentioned earlier, uh this 00:13:33.479-->00:13:40.353 breaks sleep. Um, hibernations still works, but because the you don’t go through the na- normal 00:13:40.353-->00:13:46.325 bootflow on awake from sleep, uh this doesn’t get run and the kernel panics and locks up real 00:13:46.325-->00:13:52.598 hard. Um, I don’t currently support secure boot with this yet, uh I just haven’t gotten 00:13:52.598-->00:13:57.603 around to adding support for that. Um, its I’ve seen some uh inconsistent behavior from 00:14:01.441-->00:14:06.846 Windows after booting sometimes I suspect I’ve left some things in memory that I should have in 00:14:06.846-->00:14:11.851 my application. Um, rebooting tends to fix that. Uh and I can’t promise this will continue 00:14:14.420-->00:14:18.791 to work for very long, um, Microsoft has already once started reverting the changes 00:14:18.791-->00:14:25.398 I’ve made to the boot partition, about a month and a half ago, a Windows update started rolling 00:14:25.398-->00:14:30.770 back my changes on every Windows boot. So I had to make some modifications and it works now, 00:14:30.770-->00:14:35.775 but I also haven’t run Windows update in a couple weeks. So uh to summarize, right, I I get it, 00:14:42.882-->00:14:47.887 firmware patching is real hard and I know Microsoft is is trying um UEF- the the change 00:14:49.956-->00:14:54.961 from BIOS to UEFI should have made things better as with regards to patching and it 00:14:57.130-->00:15:02.902 really didn’t. Um, but you know we’re not, we’re not running security patches for things uh 00:15:02.902-->00:15:07.840 ju- just to put out a press release saying we wrote a security patch. That’s not the 00:15:07.840-->00:15:14.614 point, right? The point is to make end users more secure. And going around and you know say 00:15:14.614-->00:15:20.586 either not issuing patches or making it ever harder to apply updates when you’re not 00:15:20.586-->00:15:26.959 supporting them re- really seems uh not helpful. And a- as an industry, as a security 00:15:26.959-->00:15:32.265 industry, if we’re not like enabling users to make their systems more secure. We’re 00:15:32.265-->00:15:38.070 failing. Um, we’re failing really bad. Uh, and so uh as I said at the beginning, I hope 00:15:38.070-->00:15:44.844 nobody has to use this, because really what should happen is uh you know, BIOS vendors, OS 00:15:44.844-->00:15:49.549 vendors should be including these patches themselves. And we shouldn’t be going around 00:15:49.549-->00:15:55.021 hacking bootloaders just to patch our systems from security bugs. [inaudible audience 00:15:55.021-->00:15:59.959 question] So uh yeah, so the question is have a I considered installing on the driver chain 00:16:05.531-->00:16:10.536 instead of the boot actions. So the problem is uh the Microsoft uh microcode driver is a signed 00:16:16.175-->00:16:20.112 package that includes both like the driver component and the microcode component. [inaudible 00:16:20.112-->00:16:25.117 audience question] Oh the UEFI driver. [inaudible audience comment] Oh so no I have not 00:16:33.359-->00:16:38.364 tried installing as a UEFI driver. [inaudible audience comment] It might. I will look 00:16:44.670-->00:16:49.675 into that. [inaudible audience comment/question] Uh so the question was are 00:16:52.178-->00:16:57.183 microcontrollers also affected by this. [inaudible audience comment] So this is for uh 00:16:59.986-->00:17:05.558 designed for basically desktop, glasstop, laptop server CPUs that have microcode patches that 00:17:05.558-->00:17:11.397 need to be applied. So anything uh activity 6 that loads microcode, this should work 00:17:11.397-->00:17:16.402 with, although uh most microcontrollers were not really impacted by Spectre. Uh, any 00:17:19.805-->00:17:24.810 other questions? Alright, thank you very much. [applause]