Giter VIP home page Giter VIP logo

linuxboot / heads Goto Github PK

View Code? Open in Web Editor NEW
1.4K 66.0 180.0 8.21 MB

A minimal Linux that runs as a coreboot or LinuxBoot ROM payload to provide a secure, flexible boot environment for laptops, workstations and servers.

Home Page: https://osresearch.net/

License: GNU General Public License v2.0

Makefile 82.90% Shell 14.49% Perl 0.23% Go 0.03% Python 2.16% Nix 0.18%
coreboot bootrom xen firmware linux tpm verifiedboot rom

heads's Introduction

Heads booting on an x230

Heads: the other side of TAILS

Heads is a configuration for laptops and servers that tries to bring more security to commodity hardware. Among its goals are:

  • Use free software on the boot path
  • Move the root of trust into hardware (or at least the ROM bootblock)
  • Measure and attest to the state of the firmware
  • Measure and verify all filesystems

Flashing Heads into the boot ROM

NOTE: It is a work in progress and not yet ready for non-technical users. If you're interested in contributing, please get in touch. Installation requires disassembly of your laptop or server, external SPI flash programmers, possible risk of destruction and significant frustration.

More information is available in the 33C3 presentation of building "Slightly more secure systems".

Documentation

Please refer to Heads-wiki for your Heads' documentation needs.

Building heads

Under QubesOS?

Build docker from nix develop layer locally

Set up Nix and flakes

  • If you don't already have Nix, install it:
    • [ -d /nix ] || sh <(curl -L https://nixos.org/nix/install) --no-daemon
    • . /home/user/.nix-profile/etc/profile.d/nix.sh
  • Enable flake support in nix
    • mkdir -p ~/.config/nix
    • echo 'experimental-features = nix-command flakes' >>~/.config/nix/nix.conf

Build image

  • Build nix developer local environment with flakes locked to specified versions
    • nix --print-build-logs --verbose develop --ignore-environment --command true
  • Build docker image with current develop created environment (this will take a while and create "linuxboot/heads:dev-env" local docker image):
    • nix build .#dockerImage && docker load < result

On some hardened OSes, you may encounter problems with ptrace.

       > proot error: ptrace(TRACEME): Operation not permitted

The most likely reason is that your kernel.yama.ptrace_scope variable is too high and doesn't allow docker+nix to run properly. You'll need to set kernel.yama.ptrace_scope to 1 while you build the heads binary.

sudo sysctl kernel.yama.ptrace_scope #show you the actual value, probably 2 or 3
sudo sysctl -w kernel.yama.ptrace_scope=1 #setup the value to let nix+docker run properly

(don't forget to put back the value you had after finishing build head)

Done!

Your local docker image "linuxboot/heads:dev-env" is ready to use, reproducible for the specific Heads commit used and will produce ROMs reproducible for that Heads commit ID.

Jump into nix develop created docker image for interactive workflow

docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) linuxboot/heads:dev-env

From there you can use the docker image interactively.

make BOARD=board_name where board_name is the name of the board directory under ./boards directory.

One such useful example is to build and test qemu board roms and test them through qemu/kvm/swtpm provided in the docker image. Please refer to qemu documentation for more information.

Eg:

make BOARD=qemu-coreboot-fbwhiptail-tpm2 # Build rom, export public key to emulated usb storage from qemu runtime
make BOARD=qemu-coreboot-fbwhiptail-tpm2 PUBKEY_ASC=~/pubkey.asc inject_gpg # Inject pubkey into rom image
make BOARD=qemu-coreboot-fbwhiptail-tpm2 USB_TOKEN=Nitrokey3NFC PUBKEY_ASC=~/pubkey.asc ROOT_DISK_IMG=~/qemu-disks/debian-9.cow2 INSTALL_IMG=~/Downloads/debian-9.13.0-amd64-xfce-CD-1.iso run # Install

Alternatively, you can use locally built docker image to build a board ROM image in a single call.

Eg: docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) linuxboot/heads:dev-env -- make BOARD=nitropad-nv41

Pull docker hub image to prepare reproducible ROMs as CircleCI in one call

docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) tlaurion/heads-dev-env:latest -- make BOARD=x230-hotp-maximized
docker run -e DISPLAY=$DISPLAY --network host --rm -ti -v $(pwd):$(pwd) -w $(pwd) tlaurion/heads-dev-env:latest -- make BOARD=nitropad-nv41

Maintenance notes on docker image

Redo the steps above in case the flake.nix or nix.lock changes. Commit changes. Then publish on docker hub:

#put relevant things in variables:
docker_version="vx.y.z" && docker_hub_repo="tlaurion/heads-dev-env"
#update pinned packages to latest available ones if needed, modify flake.nix derivatives if needed:
nix flakes update
#modify CircleCI image to use newly pushed docker image
sed "s@\(image: \)\(.*\):\(v[0-9]*\.[0-9]*\.[0-9]*\)@\1\2:$docker_version@" -i .circleci/config.yml
# commit changes
git commit --signoff -m "Bump nix develop based docker image to $docker_hub_repo:$docker_version"
#use commited flake.nix and flake.lock in nix develop
nix --print-build-logs --verbose develop --ignore-environment --command true
#build new docker image from nix develop environement
nix build .#dockerImage && docker load < result
#tag produced docker image with new version
docker tag linuxboot/heads:dev-env "$docker_hub_repo:$docker_version"
#push newly created docker image to docker hub
docker push "$docker_hub_repo:$docker_version"
#test with CircleCI in PR. Merge.
git push ...
#make last tested docker image version the latest
docker tag "$docker_hub_repo:$docker_version" "$docker_hub_repo:latest"
docker push "$docker_hub_repo:latest"

This can be put in reproducible oneliners to ease maintainership.

Test image in dirty mode:

docker_version="vx.y.z" && docker_hub_repo="tlaurion/heads-dev-env" && sed "s@\(image: \)\(.*\):\(v[0-9]*\.[0-9]*\.[0-9]*\)@\1\2:$docker_version@" -i .circleci/config.yml && nix --print-build-logs --verbose develop --ignore-environment --command true && nix build .#dockerImage && docker load < result && docker tag linuxboot/heads:dev-env "$docker_hub_repo:$docker_version" && docker push "$docker_hub_repo:$docker_version"

Notes:

  • Local builds can use ":latest" tag, which will use latest tested successful CircleCI run
  • To reproduce CirlceCI results, make sure to use the same versioned tag declared under .circleci/config.yml's "image:"

General notes on reproducible builds

In order to build reproducible firmware images, Heads builds a specific version of gcc and uses it to compile the Linux kernel and various tools that go into the initrd. Unfortunately this means the first step is a little slow since it will clone the musl-cross-make tree and build gcc...

Once that is done, the top level Makefile will handle most of the remaining details -- it downloads the various packages, verifies the hashes, applies Heads specific patches, configures and builds them with the cross compiler, and then copies the necessary parts into the initrd directory.

There are still dependencies on the build system's coreutils in /bin and /usr/bin/, but any problems should be detectable if you end up with a different hash than the official builds.

The various components that are downloaded are in the ./modules directory and include:

We also recommend installing Qubes OS, although there Heads can kexec into any Linux or multiboot kernel.

Notes:

  • Building coreboot's cross compilers can take a while. Luckily this is only done once.
  • Builds are finally reproducible! The reproduciblebuilds tag tracks any regressions.
  • Currently only tested in QEMU, the Thinkpad x230, Librem series and the Chell Chromebook. ** Xen does not work in QEMU. Signing, HOTP, and TOTP do work; see below.
  • Building for the Lenovo X220 requires binary blobs to be placed in the blobs/x220/ folder. See the readme.md file in that folder
  • Building for the Librem 13 v2/v3 or Librem 15 v3/v4 requires binary blobs to be placed in the blobs/librem_skl folder. See the readme.md file in that folder

QEMU:

OS booting can be tested in QEMU using a software TPM. HOTP can be tested by forwarding a USB token from the host to the guest.

For more information and setup instructions, refer to the qemu documentation.

coreboot console messages

The coreboot console messages are stored in the CBMEM region and can be read by the Linux payload with the cbmem --console | less command. There is lots of interesting data about the state of the system.

heads's People

Contributors

3hhh avatar alex-nitrokey avatar danielp96 avatar daringer avatar eganonoa avatar flammit avatar flawedworld avatar jgrip avatar jonathonhall-purism avatar kakaroto avatar krystian-hebel avatar kylerankin avatar mdrobnak avatar merge avatar miczyg1 avatar mkopec avatar mmlb avatar mrchromebox avatar osresearch avatar paulmenzel avatar rbreslow avatar root-hardenedvault avatar saper avatar sergiidmytruk avatar snmcmillan avatar theplexus avatar thrilleratplay avatar tlaurion avatar tonux599 avatar undeaddevel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

heads's Issues

coreboot rebuilds every time

Something in the new per-board Makefile is causing coreboot to rebuild everything. This doesn't happen when make -C "/build/heads/build/coreboot-git" obj=./x230 DOTCONFIG=../../config/coreboot-x230.config -j 8 is run by hand, so it might be an environment variable.

Building system fails

A make on a clean cloned copy of heads produces the following errors under ubuntu 16.04:
sudo apt-get install m4 bison flex zlib1g-dev git build-essential
git clone https://github.com/osresearch/heads.git

1- initrd/bin directory is not created:
make
[...]
cmp --quiet "initrd/bin/kexec" "/media/user/7725fbc2-4b2d-4ade-9f1d-337ad8203dc3/Qubes/heads/build/kexec-tools-2.0.12/build/sbin/kexec" || cp -a "/media/user/7725fbc2-4b2d-4ade-9f1d-337ad8203dc3/Qubes/heads/build/kexec-tools-2.0.12/build/sbin/kexec" "initrd/bin/kexec"
cp: cannot create regular file 'initrd/bin/kexec': No such file or directory
Makefile:121: recipe for target 'initrd/bin/kexec' failed
make: *** [initrd/bin/kexec] Error 1

fix:
mkdir -p initrd/bin/

2- initrd/lib/x86_64-linux-gnu directory is not created:
make
[...]
cmp --quiet "initrd/lib/x86_64-linux-gnu/libtpm.so" "/media/user/7725fbc2-4b2d-4ade-9f1d-337ad8203dc3/Qubes/heads/build/tpmtotp-git/libtpm/libtpm.so" || cp -a "/media/user/7725fbc2-4b2d-4ade-9f1d-337ad8203dc3/Qubes/heads/build/tpmtotp-git/libtpm/libtpm.so" "initrd/lib/x86_64-linux-gnu/libtpm.so"
cp: cannot create regular file 'initrd/lib/x86_64-linux-gnu/libtpm.so': No such file or directory
Makefile:124: recipe for target 'initrd/lib/x86_64-linux-gnu/libtpm.so' failed
make: *** [initrd/lib/x86_64-linux-gnu/libtpm.so] Error 1

fix:
mkdir -p initrd/lib/x86_64-linux-gnu/

qr codes are too big

The QR codes don't fit on the 80x25 screen that coreboot's native VGA initializes. Can it use half height characters instead?

Coreboot config should support multiple targets

The makefile target for coreboot config only supports the x230; it should support building the qemu target or the (soon to be create) chell chromebook target without having to copy files around.

Disable the ME

What happens if the ME firmware is zeroed out? Does coreboot still start up ok?

Coreboot crossgcc is not verified

The Coreboot crossgcc target is not verified and does not check certs. In util/crossgcc/buildgcc:

download_showing_percentage() {
        url=$1
        printf " ..${red}  0%%"
        wget --no-check-certificate $url 2>&1 | while read line; do
                printf "${red}"
                echo $line | grep -o "[0-9]\+%" | awk '{printf("\b\b\b\b%4s", $1)}'
                printf "${NC}"
        done
}

Trusted Boot

Hey,

in order to get the maximum sealing against the platform it would be useful to have a well documented and feature complete trusted boot in coreboot. I started to refactor the tpm stack and implement the missing features. Take a look at https://review.coreboot.org/#/q/status:open+tpm

tpm takeown doesn't output srk

Do we need the storage root public key for anything? The mbedtls RSA wrapper would need to be improved to use it correctly.

cryptsetup should be in initrd

This will allow the LUKS headers to be included in the PCRs, as well as record the TPM stored keys into a LUKS key slot.

Downside: it requires an additional several MB of libraries. Can a simpler one be built?

tpmtotp make is executed lots of times

The top level Makefile doesn't know that all of the tpmtotp executables (for TPM operations) are generated with the same command, so it runs make -C build/tpmtotp-git many, many times.

Should use the .INTERMEDIATE: trick to let it know that they will be generated together.

SPI flash BP3-0 bits are not set

Once the bootblock is more stabilized, the BP3-0 bits should be set to avoid overwriting it and prevent the root of trust from being subverted by a software attack on the flash chip.

USB modules should be measured

The Linux kernel bootloader should not have USB enabled; loading the modules should require measurement and adjustment of the PCRs (to invalidate the disk encryption keys).

Firmware updates without reflashing

It should be possible to update the firmware (other than the locked boot block) without a hardware programmer. Perhaps reserve the 4 MB upper flash chip for the bootblock, coreboot and the Linux recovery image, and use the lower 8 MB chip for the normal boot image?

Enable VT-d early in boot process

The coreboot code should enable VT-d early in the boot process to avoid rogue hardware attacks prior to measuring bootlbock, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.