Matthew Garrett ([personal profile] mjg59) wrote2012-05-30 11:11 pm
Entry tags:

Implementing UEFI Secure Boot in Fedora

Edit 16:17EDT 31/5/12: Clarification of who gets the $99
Edit 02:10EDT 01/6/12: Clarification that it's a one-off payment

(Brief disclaimer - while I work for Red Hat, I'm only going to be talking about Fedora here. Anything written below represents only my opinions and my work on Fedora, not Red Hat's opinions or future plans)

Fedora 17 was released this week. It's both useful and free, and serves as a welcome addition to any family gathering. Do give it a go. But it's also noteworthy for another reason - it's the last Fedora release in the pre-UEFI secure boot era. Fedora 18 will be released at around the same time as Windows 8, and as previously discussed all Windows 8 hardware will be shipping with secure boot enabled by default. While Microsoft have modified their original position and all x86 Windows machines will be required to have a firmware option to disable this or to permit users to enrol their own keys, it's not really an option to force all our users to play with hard to find firmware settings before they can run Fedora. We've been working on a plan for dealing with this. It's not ideal, but of all the approaches we've examined we feel that this one offers the best balance between letting users install Fedora while still permitting user freedom.

Getting the machine booted


Most hardware you'll be able to buy towards the end of the year will be Windows 8 certified. That means that it'll be carrying a set of secure boot keys, and if it comes with Windows 8 pre-installed then secure boot will be enabled by default. This set of keys isn't absolutely fixed and will probably vary between manufacturers, but anything with a Windows logo will carry the Microsoft key[1].

We explored the possibility of producing a Fedora key and encouraging hardware vendors to incorporate it, but turned it down for a couple of reasons. First, while we had a surprisingly positive response from the vendors, there was no realistic chance that we could get all of them to carry it. That would mean going back to the bad old days of scouring compatibility lists before buying hardware, and that's fundamentally user-hostile. Secondly, it would put Fedora in a privileged position. As one of the larger distributions, we have more opportunity to talk to hardware manufacturers than most distributions do. Systems with a Fedora key would boot Fedora fine, but would they boot Mandriva? Arch? Mint? Mepis? Adopting a distribution-specific key and encouraging hardware companies to adopt it would have been hostile to other distributions. We want to compete on merit, not because we have better links to OEMs.

An alternative was producing some sort of overall Linux key. It turns out that this is also difficult, since it would mean finding an entity who was willing to take responsibility for managing signing or key distribution. That means having the ability to keep the root key absolutely secure and perform adequate validation of people asking for signing. That's expensive. Like millions of dollars expensive. It would also take a lot of time to set up, and that's not really time we had. And, finally, nobody was jumping at the opportunity to volunteer. So no generic Linux key.

The last option wasn't hugely attractive, but is probably the least worst. Microsoft will be offering signing services through their sysdev portal. It's not entirely free (there's a one-off $99 fee to gain access edit: The $99 goes to Verisign, not Microsoft - further edit: once paid you can sign as many binaries as you want), but it's cheaper than any realistic alternative would have been. It ensures compatibility with as wide a range of hardware as possible and it avoids Fedora having any special privileges over other Linux distributions. If there are better options then we haven't found them. So, in all probability, this is the approach we'll take. Our first stage bootloader will be signed with a Microsoft key.

Bootloaders


We've decided to take a multi-layer approach to our signing for a fairly simple reason. Signing through the Microsoft signing service is a manual process, and that's a pain. We don't want to have bootloader updates delayed because someone needs to find a copy of Internet Explorer and a smartcard and build packages by hand. Instead we're writing a very simple bootloader[2]. This will do nothing other than load a real bootloader (grub 2), validate that it's signed with a Fedora signing key and then execute it. Using the Fedora signing key there means that we can build grub updates in our existing build infrastructure and sign them ourselves. The first stage bootloader should change very rarely, and we don't envisage updating it more than once per release cycle. It shouldn't be much of a burden on release management.

What about grub? We've already switched Fedora 18 over to using grub 2 by default on EFI systems, but it still needs some work before it's ready for secure boot. The first thing is that we'll be disabling the module loading. Right now you can load arbitrary code into grub 2 at runtime, and that defeats the point of secure boot. So that'll be disabled. Next we'll be adding support for verifying that the kernel it's about to boot is signed with a trusted key. And finally we'll be sanitising the kernel command line to avoid certain bits of functionality that would permit an attacker to cause even a signed kernel to launch arbitrary code. These restrictions will all vanish if secure boot is disabled.

Kernel


Secure boot is built on the idea that all code that can touch the hardware directly is trusted, and any untrusted code must go through the trusted code. This can be circumvented if users can execute arbitrary code in the kernel. So, we'll be moving to requiring signed kernel modules and locking down certain aspects of kernel functionality. The most obvious example is that it won't be possible to access PCI regions directly from userspace, which means all graphics cards will need kernel drivers. Userspace modesetting will be a thing of the past. Again, disabling secure boot will disable these restrictions.

Signed modules are obviously troubling from a user perspective. We'll be signing all the drivers that we ship, but what about out of tree drivers? We don't have a good answer for that yet. As before, we don't want any kind of solution that works for us but doesn't work for other distributions. Fedora-only or Ubuntu-only drivers are the last thing anyone wants, and this really needs to be handled in a cross-distribution way.

Wait signed what


Secure boot is designed to protect against malware code running before the operating system. This isn't a hypothetical threat. Pre-boot malware exists in the wild, and some of it is nastier than you expect. So obviously bootloaders need to be signed, since otherwise you'd just replace the signed bootloader with an unsigned one that installed malware and booted your OS.

But what about the kernel? The kernel is just code. If I take a signed Linux bootloader and then use it to boot something that looks like an unsigned Linux kernel, I've instead potentially just booted a piece of malware. And if that malware can attack Windows then the signed Linux bootloader is no longer just a signed Linux bootloader, it's a signed Windows malware launcher and that's the kind of thing that results in that bootloader being added to the list of blacklisted binaries and suddenly your signed Linux bootloader isn't even a signed Linux bootloader. So kernels need to be signed.

And modules? Again, modules are just code. It's a little trickier, but if your signed kernel loads an unsigned module then that unsigned module can set up a fake UEFI environment and chain into a compromised OS bootloader. Now the attacker just has to include a signed kernel and a minimal initramfs that loads their malware module. It'd slow down boot by a couple of seconds, but other than that it'd be undetectable. X? If you can access the registers on a GPU then you can get the GPU to DMA over the kernel and execute arbitrary code. Trickier again, but still achievable - and if you've locked down every other avenue of attack, it's even attractive.

If we produce signed code that can be used to attack other operating systems then those other operating systems are justified in blacklisting us. That doesn't seem like a good outcome.

Customisation


A lot of our users want to build their own kernels. Some even want to build their own distributions. Signing our bootloader and kernel is an impediment to that. We'll be providing all the tools we use for signing our binaries, but for obvious reasons we can't hand out our keys. There's three approaches here. The first is for a user to generate their own key and enrol it in their system firmware. We'll trust anything that's signed with a key that's present in the firmware. The second is to rebuild the shim loader with their own key installed and then pay $99 and sign that with Microsoft. That means that they'll be able to give copies to anyone else and let them install it without any fiddling. The third is to just disable secure boot entirely, at which point the machine should return to granting the same set of freedoms as it currently does.

But I don't trust Microsoft


A system in custom mode should allow you to delete all existing keys and replace them with your own. After that it's just a matter of re-signing the Fedora bootloader (like I said, we'll be providing tools and documentation for that) and you'll have a computer that will boot Fedora but which will refuse to boot any Microsoft code. It may be a little more awkward for desktops because you may have to handle the Microsoft-signed UEFI drivers on your graphics and network cards, but this is also solvable. I'm looking at ways to implement a tool to allow you to automatically whitelist the installed drivers. Barring firmware backdoors, it's possible to configure secure boot such that your computer will only run software you trust. Freedom means being allowed to run the software you want to run, but it also means being able to choose the software you don't want to run.

You've sold out


We've been working on this for months. This isn't an attractive solution, but it is a workable one. We came to the conclusion that every other approach was unworkable. The cause of free software isn't furthered by making it difficult or impossible for unskilled users to run Linux, and while this approach does have its downsides it does also avoid us ending up where we were in the 90s. Users will retain the freedom to run modified software and we wouldn't have accepted any solution that made that impossible.

But is this a compromise? Of course. There's already inequalities between Fedora and users - trademarks prevent the distribution of the Fedora artwork with modified distributions, and much of the Fedora infrastructure is licensed such that some people have more power than others. This adds to that inequality. It's not the ideal outcome for anyone, and I'm genuinely sorry that we weren't able to come up with a solution that was better. This isn't as bad as I feared it would be, but nor is it as good as I hoped it would be.

What about ARM


Microsoft's certification requirements for ARM machines forbid vendors from offering the ability to disable secure boot or enrol user keys. While we could support secure boot in the same way as we plan to on x86, it would prevent users from running modified software unless they paid money for a signing key. We don't find that acceptable and so have no plans to support it.

Thankfully this shouldn't be anywhere near as much of a problem as it would be in the x86 world. Microsoft have far less influence over the ARM market, and the only machines affected by this will be the ones explicitly designed to support Windows. If you want to run Linux on ARM then there'll be no shortage of hardware available to you.

Is this all set in stone?


No. We've spent some time thinking about all of this and are happy that we can implement it in the Fedora 18 timescale, but there's always the possibility that we've missed something or that a new idea will come up. If we can increase user freedom without making awful compromises somewhere else then we'll do it.

[1] In fact, chances are that everything will carry the Microsoft key. Secure boot requires that UEFI drivers also be signed. The signing format only permits a single signature per binary. For compatibility, approximately all add-on hardware shipped will be signed with Microsoft's key, and that means that all system vendors have to recognise Microsoft's key in order to permit that hardware to run on their systems.
[2] Current source is here. It relies on a port of the UEFI crypto library and OpenSSL that I have building with some handholding, and which I'll upload as soon as possible.

(Anonymous) 2012-05-31 12:05 pm (UTC)(link)
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM).

“Installation Information” for a User Product means any methods, procedures, _authorization keys_, or other information required to install and execute _modified versions of a covered work_ in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made.
ext_267968: bjh (Default)

[identity profile] bjh21.me.uk 2012-05-31 12:16 pm (UTC)(link)
There are two reasons why this isn't a problem. First, Fedora is not, in general, conveyed as part of a transaction in which the right of possession of a User Product is transferred, so it doesn't apply to (most) distribution of Fedora.

Second, this clause only requires the provision of information that is required in order to install and execute modified versions. That could simply be instructions on how to disable Secure Boot, or how to enrol your own signing key in Secure Boot.

What this clause prevents is shipping Fedora with hardware and without any facility to either add a user key or disable Secure Boot on that hardware. I don't think Matthew is planning to do that.

On the other hand, I'm no more a lawyer than Matthew is, so I could have misinterpreted everything.
simont: A picture of me in 2016 (Default)

[personal profile] simont 2012-05-31 12:17 pm (UTC)(link)
If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term

This reads to me as saying that if you sell somebody a computer which contains a signed bootloader derived from GPLv3 code, you have to provide them with some means of installing a modified bootloader. Which is fine: you do that by means of the computer having an option whereby the user can tell it to trust their signing key as well as yours, and then you don't have to supply your own private key because it isn't required in order to install and execute modified versions.

If you're offering a Linux distribution for download (or on CDs) and expecting users to have got some hardware from elsewhere to install it on, it's difficult to see how you think this clause would apply at all.

Intent of distribution counts?

(Anonymous) 2012-05-31 07:14 pm (UTC)(link)
That is an interesting interpretation. So then it depends on the intent of the distribution whether or not full installation information has to be provided? So as long as you redistribute Fedora and don't have ties to any hardware company you can use fedora as is, but otherwise you cannot?

Or is the backdoor simply to split the conveying in two transactions, one for the software and one for the hardware?

Isn't that a giant bug/loophole in GPLv3 then? Time for a patch :)

Re: Intent of distribution counts?

(Anonymous) 2012-06-01 03:20 am (UTC)(link)
No, it's GPLv3 having the desired effect. If you're a hardware manufacturer shipping GPLv3 code, then you must either:
1. publish *your* signing keys (bad idea)
2. provide a mechanism for users to add their own trusted keys in addition to yours
3. provide a mechanism for users to disable the integrity check

There's a reason it's called anti-tivoisation: with Tivo, even though you owned the hardware, the integrity check meant you couldn't install and run custom firmware.

If you're not a hardware manufacturer or you're not shipping GPLv3 code then it doesn't apply to you. (You could maybe try to get around it by shipping the hardware and the firmware separately and getting users to combine them, but the user experience would be so awful it's unlikely to ever happen)

(Anonymous) 2012-06-02 01:02 am (UTC)(link)
That actually is what the GPLv3 says, MJG59. It says that if you are distributing a device using GPLv3'd software, the ability to run updated / changed versions of that software must also be included, including any keys necessary. This was one of the largest points of why GPLv3 came about -- to remove the TiVo-ization of software that was released under the GPLv2 accurately, but was unusable in a changed form.

From http://www.gnu.org/licenses/quick-guide-gplv3.html:
"Tivoization: Some companies have created various different kinds of devices that run GPLed software, and then rigged the hardware so that they can change the software that's running, but you cannot. If a device can run arbitrary software, it's a general-purpose computer, and its owner should control what it does. When a device thwarts you from doing that, we call that tivoization."

And:
"Protecting Your Right to Tinker

Tivoization is a dangerous attempt to curtail users' freedom: the right to modify your software will become meaningless if none of your computers let you do it. GPLv3 stops tivoization by requiring the distributor to provide you with whatever information or data is necessary to install modified software on the device. This may be as simple as a set of instructions, or it may include special data such as cryptographic keys or information about how to bypass an integrity check in the hardware. It will depend on how the hardware was designed—but no matter what information you need, you must be able to get it.

This requirement is limited in scope. Distributors are still allowed to use cryptographic keys for any purpose, and they'll only be required to disclose a key if you need it to modify GPLed software on the device they gave you. The GNU Project itself uses GnuPG to prove the integrity of all the software on its FTP site, and measures like that are beneficial to users. GPLv3 does not stop people from using cryptography; we wouldn't want it to. It only stops people from taking away the rights that the license provides you—whether through patent law, technology, or any other means."

(Anonymous) 2012-06-03 05:03 am (UTC)(link)
GRUB2 is GPLv3. You're looking to sign the boot loader process for Fedora (up through at least the grub2 stage as I understand it). This means you're signing something that is released under GPLv3.

Now, we have the ability to turn off the feature in BIOS. So the work-around exists. But without changing that BIOS setting, you are creating a condition whereby the code in grub (under GPLv3) cannot be changed, for if it is changed, it won't be usable. This violates the license.

This is an example of the exact reason GPLv3's TiVo-ization clause was added.

If you do this, you're going to have to provide some access to allow modified versions of grub to be installed by those who wish to do so because it's under GPLv3. If you don't, you cannot use grub or you'll be violating the license.

But more importantly:

Why are you doing this? It is the duty of free/libre open source software companies to stand up for user rights, not just on software but also on hardware. The Linus Torvalds camp believes in the "I don't care, so long as I have powerful and reliable software", but this only takes you so far. At some point you must realize that what you lose by capitulating to dictated terms by monopoly companies like Microsoft is in fact intolerable, and that you cannot continue down that path for one minute longer.

Microsoft has crossed the line here. There were initially demanding that all ARM-based devices be locked down 100% so the disable feature did not even exist. But they BACKED DOWN because of a huge public outcry. This means they are not so dominant after all. So why are you now giving in to their demands?

Fedora is currently the #3 distro. You have weight. You can stand up to Microsoft and win with everybody else who hates this insane policy behind you. But more importantly than that, it's the right thing to do.

I hope Fedora rethinks this decision. It's a bad move and it's going to lead down a very dark path.

(Anonymous) 2012-06-04 04:01 pm (UTC)(link)
"Fedora is currently the #3 distro."

Actually it's the #1 distro. But that doesn't matter. The idea that Fedora has enough "weight" to allow it to not only "stand up" to Microsoft but "win" is ludicrous. You've offered no concrete proposal as to how exactly Fedora would "stand up" at this time (not some imaginary time in the future when "everybody else who hates this insane policy" not only actually gets off their rear end but also manages to come to an agreement on what should be done). In other words,you've added nothing constructive to the discussion.

(Anonymous) 2012-06-03 05:15 am (UTC)(link)
MJG59, by the way I really like your webpage fonts. :-)