Why no ExitRunTimeServices() for UEFI?

The other week, at the 3rd RISC-V Workshop, there were 2 firmware presentations, coreboot and UEFI, pitching their solution for the new RISC-V chip.

One point mentioned in the coreboot presentation that seems worth raising here on a firmware security blog: the distinction between firmware that fully exits -vs- firmware that stays resident while the operating system runs. An interesting way to frame it.

Click to access Tues1345%20riscvcoreboot.pdf

Starting with the IBM PC’s BIOS, Intel systems have had firmware that runs in the background. The OS or an ap would issue a BIOS (or DOS) interrupt, and the BIOS responded to low-level interrupts, like Int 13h for disk, 10h for video, etc. On original PCs, IHVs extended BIOS via Option ROMs via the same extensibility method that IBM PC-DOS ‘services’ (TSRs, ‘terminate and stay resident’) used: hook an interrupt and replace it with yours. So, BIOS is kind of a ‘terminate and stay resident’ firmware.

UEFI uses the same model, presuming firmware to be present in background for OS to call, the resident portion are called UEFI RunTime Services. Once the operating system initializes, it calls UEFI’s ExitBootServices() function, which terminate most — but not all — of UEFI, discarding the init code and only keeping the runtime service code.

http://wiki.phoenix.com/wiki/index.php/EFI_BOOT_SERVICES#ExitBootServices.28.29

Coreboot — and U-Boot — initialize the hardware, but do not stay resident. However, on Intel systems, use of a BIOS payload in coreboot, eg, SeaBIOS, will result in that BIOS payload staying resident, responding to BIOS interrupts that the OS (or an app) may call.

So, the resident -vs- nonresident firmware seems to be tied to Intel -vs- non-Intel: coreboot on ARM for example has no SeaBIOS payload, and RISC-V likey won’t use an Intel-centric BIOS payload.

As the coreboot presentation points out, the resident firmware is an additional attack vector, UEFI has a larger surface than coreboot — or U-Boot — due to UEFI Runtime Services. UEFI currently only  has the option to terminate Boot Time Services — via ExitBootServices(). I wonder if UEFI could have an additional mode, with an ExitRuntimeServices(), that could make UEFI competitive with coreboot/U-Boot w/r/t attack surface? That could be interesting.

U-Boot and UEFI at Seattle Hardware Startups event

The January 2016 Seattle Hardware Startups event will be firmware focused, hosted by our local group, the Pacific NorthWest FirmWare Hackers (PNWFWH), topics will be on U-Boot and UEFI, Meetup announcement below. If you are in the Seattle area later this month, drop by!

http://www.meetup.com/Seattle-Hardware-Startups/events/227429885/

What: Seattle Hardware Startup: Kirkland Edition
When: Thursday, January 28, 2016, 6:00 PM to 8:00 PM
Where: Nytec Innovation Center, 416 6th Street South, Kirkland, WA

This month we are welcoming Pacific NorthWest FirmWare Hackers. PNWFHW meets randomly at various places, speaking on development and security topics of modern system firmware (UEFI, U-Boot, core boot, etc.). I am pleased to have them lead an event for us.

Speakers:

1. The first speaker is Emergency Mexican (his DEF CON goon nym). He works at a local hardware startup working on ARM32 systems. He’ll be speaking on using building custom payloads with the U-Boot boot loader.

2. The second speaker is Vincent Zimmer, a senior principal engineer at Intel, working on UEFI. Vincent chairs the UEFI Forum network and security subteams. Vincent will talk about the latest updates in the UEFI specifications for security and networking. He’ll also discuss open source community updates.

Please RSVP early so we call the pizza man and make proper arrangements.

Adam
PS: Did you know that January 15th is Hardware Freedom Day?
http://www.hardwarefreedomday.org/main/about.html

EFI app port added to U-Boot!

On December 22th, Alexander Graf of SuSE posted a patch to the U-Boot list, adding EFI payload/application support to U-Boot!

 

This is my Christmas present for my openSUSE friends :).

U-Boot is a great project for embedded devices. However, convincing everyone involved that only for “a few oddball ARM devices” we need to support different configuration formats from grub2 when all other platforms (PPC, System Z, x86) are standardized on a single format is a nightmare.

So we started to explore alternatives. At first, people tried to get grub2 running using the u-boot api interface. However, FWIW that one doesn’t support relocations, so you need to know where to link grub2 to at compile time. It also seems to be broken more often than not. And on top of it all, it’s a one-off interface, so yet another thing to maintain.

That led to a nifty idea. What if we can just implement the EFI application protocol on top of U-Boot? Then we could compile a single grub2 binary for uEFI based systems and U-Boot based systems and as soon as that one’s loaded, everything looks and feels (almost) the same.

This patch set is the result of pursuing this endeavor.

  – I am successfully able to run grub2 and Linux EFI binaries with this code.
  – When enabled, the resulting U-Boot binary only grows by ~10kb, so it’s very light weight.
  – It works on 32bit ARM and AArch64.
  – All storage devices are directly accessible
  – No runtime services (all calls return unimplemented)
  – No EFI variables

Of course, there are still a few things one could do on top:

  – Implement removable media booting (search for /efi/boot/boota{a64,rm}.efi)
  – Improve disk media detection (don’t scan, use what information we have)
  – Add EFI variable support using NVRAM
  – Add GFX support
  – Make EFI Shell work 😉

But so far, I’m very happy with the state of the patches. They completely eliminate potential arguments against U-Boot internally and give users the chance to run with the same level of comfort on all firmware types.

  disk/part.c: Expose a list of available block drivers
  include/efi_api.h: Add more detailed API definitions
  efi_loader: Add PE image loader
  efi_loader: Add boot time services
  efi_loader: Add console interface
  efi_loader: Add runtime services
  efi_loader: Add disk interfaces
  efi_loader: Add “bootefi” command
  efi_loader: hook up in build environment

More information:
http://lists.denx.de/pipermail/u-boot/2015-December/239054.html

Licensing will be interesting. Tianocore demands BSD, U-Boot prefers GPL.

The first person who gets CHIPSEC to work under this patch, please speak up!

Amazon hates U-Boot

DENX, makers of Das U-Boot, one of the main boot loaders, is strangely getting hassled from Amazon for their cloud host, see below email. If you’re at Amazon and can help, Wolfgang’s contact information is listed below.

 

——– Forwarded Message ——–
Subject:     [U-Boot] ACD takedown – new shared link
Date:     Tue, 01 Dec 2015 19:08:42 +0100
From:     Wolfgang Denk <wd@denx.de>
To:     u-boot@lists.denx.de

Hello,

for some reason Amazon Customer Service decided that publishing U-Boot sources on the Amazon Cloud Drive would violate their Terms Of Use:

    Date: November 30, 2015
    Filename: “u-boot”
    …
    We have received a complaint that you have been sharing
    content on your Amazon Cloud Drive that is prohibited by our
    Terms of Use. Upon review, we have disabled the sharing link.

I have read and re-read their TOU carefully and cannot understand what made them think so.  I appealed their decision, but did not receive a reply yet.

In the mean time, I have created a new link [1] and updated the web page [2] to reflect this change.

Sorry for any inconveniences this might be causing.

[1] https://www.amazon.com/clouddrive/share/iQRojZzxJnhZwGGUcyDdQDl6E5MAlTEeVwuCDdgUDo8?ref_=cd_ph_share_link_copy
[2] http://www.denx.de/wiki/U-Boot/SourceCode

Best regards,
Wolfgang Denk

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de
For every complex problem, there is a solution that is simple,  neat,
and wrong.                                           — H. L. Mencken
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

TI adds RapidIO support to U-Boot

Aurelien Jacquiot of TI recently submitted a patch to U-Boot, adding support for RapidIO, initially designed to support the TI KeyStone architecture. Comments from initial patch message:

“RapidIO is a high-performance packet-switched interconnect technology that can be used for messaging or memory transfers like Ethernet or PCIe. This feature adds the RapidIO boot functionality for slave mode (i.e. U-Boot does not fetch the images, images are pushed by a peer device/board). A new ‘rio’ command group allows to initialize and perform basic RapidIO operations. In addition the ‘mem’ group command has been enhanced in order to wait a given value in memory (to be notified that images have been pushed by peer). This feature has been firstly designed for TI KeyStone architecture and patches includes the RapidIO controller device driver for KeyStone architecture but it can used by any device/architecture that has hardware RapidIO support with DirectI/O. There just to add the corresponding RapidIO controller device driver. For more information, read the doc/README.rapidio documentation.”

More Information:
http://www.rapidio.org/
http://lists.denx.de/mailman/listinfo/u-boot
http://www.ti.com/sitesearch/docs/universalsearch.tsp?searchTerm=RapidIO#

FreeScale, High Availability Boot, and U-Boot secure boot

Freescale Semiconductor, Inc. has a few Application Notes on their implementations of a U-Boot-based Secure Boot. One of these app notes is only a few days old. Excerpt:

Secure Boot on i.MX50, i.MX53, and i.MX 6 Series using HABv4

Executing trusted and authentic code on an applications processor starts with securely booting the device. The i.MX family of applications processors provides this capability with the High Availability Boot (HAB) component of the on-chip ROM. The ROM is responsible for loading the initial program image from the boot medium. HAB enables the ROM to authenticate the program image by using digital signatures. This initial program image is usually a bootloader. HAB provides a mechanism to establish a root of trust for the remaining software components and establishes a secure state on the i.MX IC’s secure state machine in hardware. The purpose of this application note is to provide a secure boot reference for i.MX applications processors that include HABv4. It demonstrates an example for generating a signed U-Boot image and configuring the IC to run securely. It is assumed that the reader is familiar with the basics of digital signatures and public key certificates.

This document covers secure boot using i.MX6. HABv4 is present on the following i.MX processors: i.MX50, i.MX53, and i.MX 6 Series. This document applies to all HABv4 processors. Secure boot features for other processors, such as i.MX25, i.MX35, and i.MX51, which use HABv3, are documented in Secure Boot on i.MX25, i.MX35, and i.MX51 using HAB3 application note (document AN4547). Secure boot features for i.MX28 are documented in Secure Boot with i.MX28 HAB v4 application note (document AN4555). i.MX28 supports HABv4, but its boot architecture is significantly different from other processors in the i.MX family.

More information:

Click to access AN4581.pdf

Click to access AN4547.pdf

Click to access AN4555.pdf

libSboot: Secure Boot for U-Boot

Teddy Reed wrote libSboot 3 years ago, and I am just noticing it. 😦 This “Secure Boot” is different than the UEFI definition/implementation, and is U-Boot-specific. Excerpting the readme:


libSboot provides an example ‘Secured Boot’ for U-Boot and a U-Boot Second Phase Loader (SPL). libSboot attempts to define an example of how a platform can measure a pre-OS boot environment, thus providing a capability to ensure that a libSboot-enforced OS is only loaded in an owner-authorized  fashion. A ‘Secure Boot’ concept is a common means to ensure platform security and integrity; understand that there are many implementations of a ‘Secure Boot’.  libSboot uses a TPM v1.2 to implement a secure boot using a static root of trust measurement (SRTM). The static adjective implies a ‘read-only’  attribute, meaning libSboot expects its initialization to occur from ROM code.  During this initialization libSboot performs a TPM_Start, TPM_SelfTest and  checks that the TPM is neither deactivated nor disabled. The TPM must have its NVRAM locked, meaning access control is enforced. Initialization then checks  each PCR used to measure the pre-boot environment and verifies they are reset. Finally Physical Presence is asserted to satisfy NVRAM read/write permissions.

https://github.com/theopolis/sboot
https://github.com/theopolis/u-boot-sboot
http://www.trustedcomputinggroup.org/community/2013/03/securing_embedded_devices_with_the_tpm__a_schmoocon_talk
http://prosauce.org/blog/2013/2/11/embedded-trust-p2-u-boot-secured-boot.html

U-Boot roadmap and upcoming Mini-Summit

I asked on the U-Boot mailing list for a roadmap to current/upcoming architectural changes, and Lukasz Majewski was kind enough to point me to some sources of information.

Please look into ELCE2014 slides from u-boot mini summit at Dusseldorf (slides are available at denx.de webpage). There was a presentation from Simon Glass regarding device model road map.

http://www.denx.de/wiki/U-Boot/MiniSummitELCE2014
http://www.denx.de/wiki/U-Boot/DriverModel

There will be u-boot Mini Summit held at ELCE 2015 in Dublin. I think that the road map issue is a good topic for our overall discussion panel.

http://www.denx.de/wiki/U-Boot/SummitELCE2015
http://events.linuxfoundation.org/events/linuxcon-europe/extend-the-experience/co-located-events

Embedded Programming with Android’s U-Boot chapter

From about a week ago on the Pearson InformIT web site, Roger Ye published an article on using U-Boot with embedded Android, “Embedded Programming with Android: Using U-Boot to Boot the Goldfish Kernel“. The article mentions that this is a chapter from Roger’s book, “Embedded Programming with Android“, which is news to me. It appears the book came out in April.

In this chapter from Embedded Programming with Android: Bringing Up an Android System from Scratch, Roger Ye shows you how to build a goldfish Linux kernel and then how to boot Android from NOR flash and NAND flash using U-Boot and this kernel.

Once we have U-Boot ready for the goldfish platform, we can use it to boot the Linux kernel in the Android emulator. Ideally, the boot process starts from nonvolatile memory (such as flash memory). Many kind of storage devices can be used in an embedded system, though NOR and NAND flash devices are the most popular options. In this chapter, we will build a goldfish Linux kernel first. We then explore how to boot Android from NOR flash and NAND flash using U-Boot and this kernel. […]

http://www.informit.com/articles/article.aspx?p=2431417
http://www.informit.com/store/embedded-programming-with-android-bringing-up-an-android-9780134030005

U-Boot TPM driver model added

Yesterday Simon Glass of Chromium has submitted a large (28-part) patch to U-Boot, adding a driver model for TPMs.

[PATCH v2 00/28] dm: Convert TPM drivers to driver model

This series adds driver model support for Trusted Platform Modules (TPMs). These have a very simple interface and are configured via the device tree.

Two bus types are supported at present: I2C and LPC (Intel Low-Pin-Count).

Most drivers and users are converted over to driver model. The exception is the Atmel TPM and its users.

The I2C driver has been cleaned up and simplified. It was ported from Linux and was pretty hard to follow. This series includes patches to unify the code, remove duplicated data structures and drop unnecessary indirection.

Also this series enables the TPM on all Chromebooks supported by upstream U-Boot (snow, spring, nyan-big, pit, pi, link, panther) since some did not have it fully enabled.

As before, the ‘tpm’ command can be used to implement TPM functionality. In addition a ‘tpmtest’ command provides some basic TPM tests taken from Chrome OS U-Boot. These are fairly rudimentary but are useful if you know what you are doing.

For more information, see the U-boot mailing list:
http://lists.denx.de/mailman/listinfo/u-boot

U-Boot AArch64 and ARM Trusted Boot support

This week Linus Walleij of Linaro posted a long blog article on U-Boot this week, with good background on U-Boot on ARM, as well as current AArch64 support, including integration with ARM Trusted Firmware (ARM TF). Excerpting the concluding paragraphs of the blog:

We now have pieced together a system that will start U-Boot from ARM Trusted Firmware and then have U-Boot load the Linux kernel and a device tree and start it. Are there problems remaining?
* One of the big outstanding issues are those where things are fragile because memory references need be hard-coded in U-Boot or ARM Trusted Firmware. For example U-Boot currently assumes that ARM TF will use 16MB of the DRAM memory. If the ARM TF change things around and use more or less memory, U-Boot needs to be reconfigured and recompiled. U-Boot on the other hand, will then pass whatever knowledge it has about the memory to the Linux kernel by augmenting the device tree. So if ARM TF could communicate the memory available to U-Boot and the OS this would be great.
* U-Boot relies on prior boot stages such as ARM Trusted Firmware to install PSCI handlers, while on ARMv7 this was usually done by augmenting U-Boot to do the same. Letting U-Boot install PSCI handlers is a bit bogus, since it is a piece of resident code left in memory after U-Boot has executed and not really “boot loader” code. U-Boot was augmented to compile these into a special memory area, copy them there and leave them around for the operating system to use later. Still there are people who might like to do this on ARMv8 U-Boot, especially those not using ARM Trusted Firmware.
* People apparently toy with the idea of booting U-Boot on bare metal, using a very small or no ROM nor ARM Trusted Firmware, letting U-Boot just execute immediately on the system. As U-Boot relies on something else to set up main memory and providing PSCI, this currently does not work. Doing this would require U-Boot to initialize memory and install PSCI handlers. It would also need to be small enough to execute from on-chip RAM.
* Chain of trust booting with signed boot levels, signed U-Boot and a signed kernel image and a signed device tree, making an example of a totally locked-down system. The Flattened Image Tree (FIT) supported by U-Boot is likely the best way forward here, but requires U-Boot to access public key infrastructure to verify images unless you want to compile the public key directly into U-Boot, which is often not a good idea.
* Fastboot – the Android boot protocol used by the Little Kernel, exists in U-Boot but has not been tested or verified. It can use USB or Ethernet alike.
* More hardware support – such as booting from the USB stick or MMC/SD card found in the Juno board. This was not covered by the experimental port.

Read the full article here:

https://www.linaro.org/blog/core-dump/u-boot-on-arm32-aarch64-and-beyond/