Commit Graph

507 Commits

Author SHA1 Message Date
Bill Richardson
f5db4b86fa Modifying the kernel_utility tool to create our magic blob.
For the --generate operation, the --in <file> option is gone and there are
three new required options:

  --vmlinuz <file>         Embedded kernel image
  --config <file>          Embedded kernel command-line parameters
  --bootloader <file>      Embedded bootloader stub

This takes the specified kernel, extracts the 32-bit component, and combines
that with the configuration file (essentially just the kernel cmdline
string) and the bootstub image . The resulting blob is signed and ready to
put in a kernel partition.

There's also an optional --padding parameter, to specify how much extra
(unsigned) space to leave between the signature header and the kernel blob.
The default is 0x4000, which is about four times as much needed when using
the largest signature size we currently support.

Review URL: http://codereview.chromium.org/2283005
2010-05-27 11:15:14 -07:00
Randall Spangler
3003c1dd50 Moved cgptlib into vboot_firmware
Moved cgptlib tests into tests

Review URL: http://codereview.chromium.org/2303003
2010-05-27 09:20:11 -07:00
Gaurav Shah
bcd8f4a07c Make kernel signature a part of the kernel preamble.
With this change, the kernel signature is a part of the preamble block (and therefore, used during preamble signature verification).

BUG=670
TEST=image verification tests still pass. corrected splicing test expectations (and it passes).

Review URL: http://codereview.chromium.org/2292001
2010-05-26 13:19:00 -07:00
Gaurav Shah
bf7615bc31 Change kernel vboot header layout and add support for separate header verification.
This CL adds 2 things:
- Instead of having a kernel config, now we have a kernel preamble which contains some important parameters needed by the bootloader in the firmware to kernel hand-off. These parameters are verified using a separate preamble signature in addition to the kernel signature on actual kernel image data.

- Adds a new VerifyKernelHeader() API function which verifies the kernel verified boot header excluding the kernel data and also extracts parameters out of this header needed to verify the actual kernel image data (if deemed necessary). This allows for vboot header verification and data verification to be performed separately.

Review URL: http://codereview.chromium.org/2234003
2010-05-26 10:26:00 -07:00
Bill Richardson
0b8f35c6a5 Rearrange vboot_reference directories to isolate external components.
This creates a new vboot_firmware subdirectory, and which contains the
entirety of the BIOS code. There shouldn't be anything in this directory
that is NOT required by the BIOS.

Review URL: http://codereview.chromium.org/2219004
2010-05-26 09:18:38 -07:00
Gaurav Shah
bd52fc793a VBoot Reference: Make kernel_config a 4K byte block, and move it after the verified boot block.
The kernel_config is now stored as a 4K binary block instead of the kconfig_options structure that was being used before. Since the verified boot code doesn't care what kernel config options are (other than the length of the kernel image and for verifying them before the rest of kernel), it is ok to keep them as a blackbox.

This CL also changes the verified boot kernel layout - VBlock Data followed by Kernel Config followed by the Kernel Image. This will allow them to be stored separately, or as a concatenated block (for easy memory mapping during kernel load). This should ease the process of generating a layout for verified boot kernel images which is also compatible with legacy BIOSes that don't support this mechanism.

Finally, there is also a new firmware API function to determine the size of a kernel verified boot block, given a pointer to its beginning (for determining the offset to the kernel config and data).

Review URL: http://codereview.chromium.org/1732022
2010-04-29 15:30:25 -07:00
Gaurav Shah
0265882a34 Change VerifyFirmware() to take separate pointers to firmware verification header and firmware data.
The firmware verification code no longer assumes that verification data and firmware data are contiguous and follow each other. Needed for EFI where the actual firmware must be stored in its own firmware volume.

BUG=1704
TEST=modified existing tests for the new API, and they still pass

Review URL: http://codereview.chromium.org/1578035
2010-04-18 16:35:07 -07:00
Gaurav Shah
c7686471b8 Remove big_[firmware|kernel]_tests from the script used in the autotest.
These tests wouldn't work on a 32-bit system.

Review URL: http://codereview.chromium.org/1624002
2010-04-05 18:44:05 -07:00
Gaurav Shah
f3dd1a6784 VBoot Reference: Output debug information using debug() instead of fprintf().
This should make it easier to switch off debug messages if needed.

TESTS=builds fine, autotest builds fine (using both arm/x86-generic)

Review URL: http://codereview.chromium.org/1607006
2010-04-05 15:50:00 -07:00
Gaurav Shah
fc70d72aaa VBoot Reference: Refactoring Part 3
Refactor and restructure reference code into individual self-contain modules. I have revamped the way the code is structured to make it easy to determine which parts belong in the firmware and which are used by userland tools.

common/ - common utilities and stub functions (Firmware)
cryptolib/ - crypto library (Firmware)
misclibs/ - miscellaneous userland libraries (Userland)
sctips/ - Miscellaenous scripts (Userland)
tests/ - Tests (Userland)
vfirmware/ - Verified Firmware Implementation
vfirmware/firmware_image_fw.c (Firmware)
vfirmware/firmware_image.c (Userland)

vkernel/ - Verified Kernel Implementation
vkernel/kernel_image_fw.c (Firmware)
vkernel/kernel_image.c (Userland)

Review URL: http://codereview.chromium.org/1581005
2010-03-31 13:26:55 -07:00
Gaurav Shah
5411c7a9f0 combined patch for:
http://codereview.chromium.org/1574005
http://codereview.chromium.org/1604001

Review URL: http://codereview.chromium.org/1585007
2010-03-31 10:56:49 -07:00
David Garcia
21c3f7fef7 Revert "VBoot Reference: Refactor Part 2 - Crypto Libraries"
This reverts commit e018a80a37aaa45681f45f5852f04d20aedd8b2d.

Review URL: http://codereview.chromium.org/1593002
2010-03-31 09:04:15 -07:00
Gaurav Shah
d46c347018 VBoot Reference: Refactor Part 2 - Crypto Libraries
Removing multiple top level includes - now padding.h, rsa.h and sha.h are used internally and cryptolib.h must be used instead for all modules that wish to use crypto functions.

I am trying to separate refactors involving code movement from one file to another, and the movement of files themselves into separate CLs so that it's clear what changed.

Review URL: http://codereview.chromium.org/1574005
2010-03-30 23:08:10 -07:00
Gaurav Shah
ed9c96a7aa VBoot Reference: Refactor Pass 1: Split {firmware|kernel}_image
This CL refactors verified boot firmware and kernel image functions into firmware and userland portions. Data Types and Functions that need to be a part of the final firmware implementation reside in files with "_fw" suffix - firmware_image_fw.{c|h} and kernel_image_fw.{c|h}.

Also some Makefile cleanups.

Review URL: http://codereview.chromium.org/1599001
2010-03-30 18:56:07 -07:00
Gaurav Shah
091dfdf425 Make image verification test script call big_{firmware|kernel} tests.
Review URL: http://codereview.chromium.org/1530009
2010-03-30 16:01:46 -07:00
Gaurav Shah
7982ed3ae5 Use UINT64_C macros from stdint.h.
Review URL: http://codereview.chromium.org/1587005
2010-03-30 14:01:50 -07:00
Gaurav Shah
d0f3298bb1 Explicitly use the ULL suffix to specify a large constant.
This hopefully fixes the ARM build error.

TBR = wad@chromium.org

Review URL: http://codereview.chromium.org/1591001
2010-03-30 00:37:38 -07:00
Gaurav Shah
e450be4ce4 Propagate use of uint64_t to more functions that may need to deal with arbitrary length data.
This CL fixes some functions to use uint64_t that I missed the first time around. It ended up requiring some minor changes to how some of the helper functions work (StatefulMemcpy*()).

Also adds new tests to make sure that reference code can verify/process big firmware and kernel images.

BUG=670
TEST=Adds some new, old ones still pass.

Review URL: http://codereview.chromium.org/1519008
2010-03-29 21:27:08 -07:00
Gaurav Shah
463be3f135 VBoot Reference: Fix splicing bugs in Firmware and Kernel verification.
BUG=670
TESTS=Adds new tests which verify this doesn't occur anymore. Existing tests still pass.

The existing code computes and verifies signatures on firmware/kernel data and firmware/kernel versions separately. This causes a image splicing bug where it is possible to combine together a version signature from a valid new firmware with firmware data and signature from an older version. The same problem exists with kernel verification.

This CL fixes this by changing the firmware/kernel signatures to also include the version information.

For the Firmware, there's a separate signature on the preamble (which contains the version) but the firmware signature now also includes this preamble in addition to the firmware data.

For the Kernel, there's a separate signature on the kernel config/options (wich also contains the version), but the kernel signature now also includes these config/options in addition to the kernel data.

Review URL: http://codereview.chromium.org/1430001
2010-03-29 16:13:45 -07:00
Gaurav Shah
f37ae21b3c Fix benchmark output label.
Review URL: http://codereview.chromium.org/1456002
2010-03-26 13:47:05 -07:00
Gaurav Shah
a82bf268b2 VBoot Reference: Add kernel rollback prevention and choosing logic.
Also adds tests for kernel rollback prevention.

Review URL: http://codereview.chromium.org/1320010
2010-03-26 10:38:08 -07:00
Gaurav Shah
3199eed3d3 Move test utility functions to a common place.
Also removes the dev_mode flag from Firmware Image verification as key signature for the firmware should be checked whether or not dev mode is enabled.

BUG=670
TEST=All tests still pass.

Merge remote branch 'refs/remotes/origin/master' into fixtests

Fix tests, remove dev mode. Move common code.

Review URL: http://codereview.chromium.org/1280002
2010-03-25 13:04:45 -07:00
Gaurav Shah
ce0cc30e55 VBoot Reference: Add version checking to for preventing rollbacks.
This CL adds a new function VerifyFirmwareDriver_f() means to be a part of the RO firmware which determine which copy of the firmware to boot from. It is meant to ensure that a particular firmware is only booted if 1) it verifies successfully, 2) its version is newer or equal to current stored version. In addition, the driver function also updates the stored version if needed.

Currently I am using the TLCL API with stub calls, (in fact, most of the TPM interaction is done in rollback_index.c which implements the actual version query/update API) used by the firmware.

Review URL: http://codereview.chromium.org/1241002
2010-03-24 13:48:55 -07:00
Gaurav Shah
1e56693763 Fix test return values (otherwise, autotest mistakenly thinks it failed).
Review URL: http://codereview.chromium.org/1138006
2010-03-22 18:25:11 -07:00
Gaurav Shah
13937119e6 Vboot Reference: Add kernel image verification benchmark.
Refactor duplicate code for the firmware image benchmark. Also fixes some functions that manipulate kernel blobs (use uint64_t instead if int).

Review URL: http://codereview.chromium.org/1079009
2010-03-22 17:59:09 -07:00
Gaurav Shah
e268eefd6a Vboot Reference: Add a firmware verification benchmark.
The benchmark calculates the time taken to verify a firmware image of various sizes for various combinations of signature algorithm. This is meant to be called through autotest.

Review URL: http://codereview.chromium.org/1127007
2010-03-22 16:02:12 -07:00
Gaurav Shah
445925fe0f Vboot Reference: Spring cleaning of test scripts.
Moved duplicated code to "common.sh". Make directory detection more robust.

Review URL: http://codereview.chromium.org/1101004
2010-03-19 16:19:09 -07:00
Gaurav Shah
528a2c113e Add --describe flag to {firmware|kernel}_utility.
This spews out useful information about a verified boot firmware/kernel image. Also adds a helper function to calculate header checksum. That code was being duplicated at multiple places.

Review URL: http://codereview.chromium.org/1088001
2010-03-18 13:10:10 -07:00
Gaurav Shah
ccaa90f735 Add fuzz testing driver programs for kernel and firmware verification.
The driver programs are useful in quick and dirty fuzz testing of the verification code with blind smartfuzzers like Bunny (http://code.google.com/p/bunny-the-fuzzer/).

Also fixes a bug with image generation in kernel_utility.

Tests: All existing tests still pass. VerifyKernel() and VerifyFirmware() can successfully verify images generated by {firmware|kernel}_utility.

Review URL: http://codereview.chromium.org/975007
2010-03-17 20:40:23 -07:00
Gaurav Shah
4f39386902 Add a command line string field to verified boot kernel config image.
Also some cleanup of duplicated code.

BUG=670
TEST=Existing image verification tests still pass.

Review URL: http://codereview.chromium.org/874006
2010-03-12 18:13:24 -08:00
Gaurav Shah
259de40640 VBoot Reference: Fix many memory leaks.
Fix memory leaks found using Valgrind, adds sanity checking to RSAPublicKey parsing code to prevent crazy behavior.

Review URL: http://codereview.chromium.org/858008
2010-03-12 17:42:03 -08:00
Gaurav Shah
456678b0c4 Vboot Reference: Make length types explicitly sized.
Review URL: http://codereview.chromium.org/744002
2010-03-10 18:38:45 -08:00
Gaurav Shah
cb3d22e971 Fix RSA verification test.
I previously refactored some of the signature generation code to directly use the OpenSSL library instead of invoking the "openssl" command line utility. The signature_digest command line utility got lost in the process. This restores the utility which in turn fixes the RSA verification test.

Review URL: http://codereview.chromium.org/669040
2010-03-04 10:22:36 -08:00
Gaurav Shah
f5564fa98c Vboot Reference: Refactor Code.
This CL does the following:
1) It adds a SignatureBuf function which uses the OpenSSL library to generate RSA signature. This is more robust than the previous way of invoking the command line "openssl" utility and capturing its output. No more unnecessary temporary files for signature operations.
2) It adds functions that allow direct manipulation of binary verified Firmware and Kernel Image blobs in memory.
3) It changes the structure field members for FirmwareImage to make it consistent with KernelImage. Now it's clearer which key is used when.
4) Minor bug fixes and slightly improved API for dealing verified boot firmware and kernel images.
5) Renames the RSA_verify function to prevent conflicts with OpenSSL since it's linked into the firmware utility binary.

Review URL: http://codereview.chromium.org/661353
2010-03-02 15:40:01 -08:00
Gaurav Shah
444e1e19f2 Make SHA benchmark output follow convention.
Review URL: http://codereview.chromium.org/660317
2010-03-01 20:25:03 -08:00
Gaurav Shah
c7daf38f70 Fix a typo in the RSA benchmark.
Also fix error handling in RSAPublicKeyFromBuf().

BUG=1210
TEST=none

Review URL: http://codereview.chromium.org/660310
2010-03-01 20:24:37 -08:00
Gaurav Shah
cae5fa613a Refactor siglen_map[] to store key size in bytes instead of 32-bit words.
Review URL: http://codereview.chromium.org/660261
2010-02-28 20:02:29 -08:00
Gaurav Shah
f67bcaa9a6 Vboot Reference: Add functions to verify signed kernel images.
BUG=670
TEST=Adds kernel_image_test which tests the new functions.

The kernel image verification pretty much exactly mirror the already existing firmware image verification functions except with a few different/additional fields in a signed kernel image. The firmware signing key is the root key equivalent for kernel images.

This CL also moves the image verification tests to a different script. There's some additional cleanup of the code that I will be submitting separately after this and another pending patches get LGTMed and land.

Review URL: http://codereview.chromium.org/660161
2010-02-28 19:18:24 -08:00
Gaurav Shah
8b95c70373 Make crypto benchmark output compatible with autotest.
Review URL: http://codereview.chromium.org/660228
2010-02-28 12:50:29 -08:00
Gaurav Shah
23a2f3a6c5 Vboot reference: A basic user-land verified boot firmware signing and verification utility.
This is a first cut at what I envision as a utility we can use to manage our firmware/kernel signing needs. Currently, it implements firmware signing (given a binary image, create a verified boot header) and verification (given a verified boot image, verify it using the given public root key).

This CL also fixes the ReadFirmwareImage function from firmware_image to make it more consistent and fixes some bugs.

Review URL: http://codereview.chromium.org/652216
2010-02-26 15:09:43 -08:00
Gaurav Shah
7d122e2a47 Add a test for RSA PKCS #1 v1.5 signature verification.
This test checks that signatures with improper padding do not get accepted by the RSA signature verification implementation.

Review URL: http://codereview.chromium.org/661038
2010-02-24 16:41:32 -08:00
Gaurav Shah
08df9b88a3 Vboot Reference: Add the "real" reference firmware verification function (VerifyFirmware).
The old VerifyFirmware function (now called VerifyFirmwareImage) works on the FirmwareImage structure. This CL adds a verification function which can be used directly on packed binary verified boot firmware blobs. This function can be used as the reference implementation for verified boot in firmware. In addition, all functions that work on FirmwareImage structure have been renames to distinguish them from those which work on binary firmware blobs.

In addition, this adds some new crypto utility functions and refactors old ones.
BUG=670
TEST=Added tests for the new function and they pass.

Review URL: http://codereview.chromium.org/650105
2010-02-23 16:16:23 -08:00
Gaurav Shah
4a3189fb26 Vboot Reference: Make firmware image verification test handle errors gracefully.
The test should bail immediately on an unrecoverable error.

Review URL: http://codereview.chromium.org/647027
2010-02-18 10:53:05 -08:00
Gaurav Shah
52898d3c26 Vboot Reference: Add a RSA verify benchmark.
In addtion, add test cases and a script to generate them for benchmarking. Also fixes a path problem with the run_rsa_tests.sh script.

Review URL: http://codereview.chromium.org/626011
2010-02-17 16:37:33 -08:00
Gaurav Shah
7ca31f3e4d Vboot Reference: Misc style fixes to Makefile and fix testing script.
Review URL: http://codereview.chromium.org/600114
2010-02-16 19:04:11 -08:00
Gaurav Shah
431b98886e Data structure and interface for manipulating and handing firmware images for verified boot.
Review URL: http://codereview.chromium.org/564020
2010-02-12 15:54:37 -08:00
Gaurav Shah
1a055adf7b VBoot Reference: Make RSA verification test script return the right error code.
Also rename and modify run_tests.sh to only run the RSA verification tests. The SHA message digest tests must now be invoked separately.

Review URL: http://codereview.chromium.org/596080
2010-02-12 13:05:03 -08:00
Gaurav Shah
cc1dd99ae7 SHA* digest function speed test.
BUG=1210
TEST=This is a test,

Review URL: http://codereview.chromium.org/596079
2010-02-12 11:21:18 -08:00
Gaurav Shah
e3ef9c9f40 Vboot Reference: Move test key generation to a separate script and add sample test keys.
Key generation takes a long time. This will be useful in driving the cryptosuite through autotest.

Review URL: http://codereview.chromium.org/604016
2010-02-10 23:07:02 -08:00
Gaurav Shah
1f81a6f936 Refactor code from test/ to utils/ since they are not just used by tests.
Also, adds a simple analog of verify_data.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/578025
2010-02-06 14:34:31 -08:00