Initial integration of AVB2.0
v2 cover Initial integration of AVB2.0
This series of patches introduces support of Android Verified Boot 2.0, which provides integrity checking of Android partitions on MMC.
It integrates libavb into the U-boot, provides implementation of AvbOps, subset of avb commands to run verification chain (and for debugging purposes), and it enables AVB2.0 verification on AM57xx HS SoC by default.
Currently, there is still no support for verification of A/B boot slots and no rollback protection (for storing rollback indexes there are plans to use eMMC RPMB)
Libavb will be deviated from AOSP upstream in the future, that's why minimal amount of changes were introduced into the lib sources, so checkpatch may fail.
For additional details check [1] AVB 2.0 README and doc/README.avb2, which is a part of this patchset.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
Changes for v2:
- Updated libavb from the AOSP upstream
- Removed libavb_ab is it's marked as deprecated
- Added default n to Kconfigs for this feature (both for CONFIG_LIBAVB and CONFIG_CMD_AVB)
- Minor fixes in avb_find_dm_args
- Replaced "reinvented the wheel" str macro with existing __stringify()
- Updated documentation
- Updated avb_slot_verify invocation, supplying with new AvbHashtreeErrorMode param
- Fixed array boundary exceeded error when handling bootargs in avb_find_dm_args
Igor Opaniuk (8):
avb2.0: add Android Verified Boot 2.0 library avb2.0: integrate avb 2.0 into the build system avb2.0: implement AVB ops
cmd: avb2.0: avb command for performing verification avb2.0: add boot states and dm-verity support
am57xx_hs: avb2.0: add support of AVB 2.0 test/py: avb2.0: add tests for avb commands
doc: avb2.0: add README about AVB2.0 integration
cmd/Kconfig | 16 + cmd/Makefile | 3 + cmd/avb.c | 372 ++++++++ common/Makefile | 2 + common/avb_verify.c | 741 +++++++++++++++ doc/README.avb2 | 97 ++ include/avb_verify.h | 96 ++ include/configs/am57xx_evm.h | 11 + include/environment/ti/boot.h | 15 + lib/Kconfig | 14 + lib/Makefile | 1 + lib/libavb/Makefile | 15 + lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_chain_partition_descriptor.h | 54 ++ lib/libavb/avb_cmdline.c | 422 +++++++++ lib/libavb/avb_cmdline.h | 72 ++ lib/libavb/avb_crypto.c | 354 +++++++ lib/libavb/avb_crypto.h | 156 +++ lib/libavb/avb_descriptor.c | 142 +++ lib/libavb/avb_descriptor.h | 113 +++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_footer.h | 68 ++ lib/libavb/avb_hash_descriptor.c | 44 + lib/libavb/avb_hash_descriptor.h | 70 ++ lib/libavb/avb_hashtree_descriptor.c | 52 + lib/libavb/avb_hashtree_descriptor.h | 80 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_kernel_cmdline_descriptor.h | 63 ++ lib/libavb/avb_ops.h | 293 ++++++ lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_property_descriptor.h | 89 ++ lib/libavb/avb_rsa.c | 276 ++++++ lib/libavb/avb_rsa.h | 55 ++ lib/libavb/avb_sha.h | 72 ++ lib/libavb/avb_sha256.c | 364 +++++++ lib/libavb/avb_sha512.c | 362 +++++++ lib/libavb/avb_slot_verify.c | 1367 +++++++++++++++++++++++++++ lib/libavb/avb_slot_verify.h | 341 +++++++ lib/libavb/avb_sysdeps.h | 101 ++ lib/libavb/avb_sysdeps_posix.c | 63 ++ lib/libavb/avb_util.c | 412 ++++++++ lib/libavb/avb_util.h | 269 ++++++ lib/libavb/avb_vbmeta_image.c | 290 ++++++ lib/libavb/avb_vbmeta_image.h | 276 ++++++ lib/libavb/avb_version.c | 16 + lib/libavb/avb_version.h | 41 + lib/libavb/libavb.h | 32 + test/py/tests/test_avb.py | 111 +++ 48 files changed, 8192 insertions(+) create mode 100644 cmd/avb.c create mode 100644 common/avb_verify.c create mode 100644 doc/README.avb2 create mode 100644 include/avb_verify.h create mode 100644 lib/libavb/Makefile create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_chain_partition_descriptor.h create mode 100644 lib/libavb/avb_cmdline.c create mode 100644 lib/libavb/avb_cmdline.h create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_crypto.h create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_descriptor.h create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_footer.h create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hash_descriptor.h create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.h create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.h create mode 100644 lib/libavb/avb_ops.h create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.h create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_rsa.h create mode 100644 lib/libavb/avb_sha.h create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.c create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_slot_verify.h create mode 100644 lib/libavb/avb_sysdeps.h create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_util.h create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_vbmeta_image.h create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb/avb_version.h create mode 100644 lib/libavb/libavb.h create mode 100644 test/py/tests/test_avb.py
Signature · 1 line
2.7.4
PATCH v2 1/8 avb2.0: add Android Verified Boot 2.0 library
Add libavb lib (3rd party library from AOSP), that implements support of AVB 2.0. This library is used for integrity checking of Android partitions on eMMC.
libavb was added as it is and minimal changes were introduced to reduce maintenance cost, because it will be deviated from AOSP upstream in the future.
Changes:
- license headers changed to conform SPDX-style
- avb_crc32.c dropped
- updates in avb_sysdeps_posix.c/avb_sysdeps.h
For additional details check [1] AVB 2.0 README.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
--- lib/libavb/avb_chain_partition_descriptor.c | 46 + lib/libavb/avb_chain_partition_descriptor.h | 54 ++ lib/libavb/avb_cmdline.c | 422 +++++++++ lib/libavb/avb_cmdline.h | 72 ++ lib/libavb/avb_crypto.c | 354 +++++++ lib/libavb/avb_crypto.h | 156 +++ lib/libavb/avb_descriptor.c | 142 +++ lib/libavb/avb_descriptor.h | 113 +++ lib/libavb/avb_footer.c | 36 + lib/libavb/avb_footer.h | 68 ++ lib/libavb/avb_hash_descriptor.c | 44 + lib/libavb/avb_hash_descriptor.h | 70 ++ lib/libavb/avb_hashtree_descriptor.c | 52 + lib/libavb/avb_hashtree_descriptor.h | 80 ++ lib/libavb/avb_kernel_cmdline_descriptor.c | 40 + lib/libavb/avb_kernel_cmdline_descriptor.h | 63 ++ lib/libavb/avb_ops.h | 293 ++++++ lib/libavb/avb_property_descriptor.c | 167 ++++ lib/libavb/avb_property_descriptor.h | 89 ++ lib/libavb/avb_rsa.c | 276 ++++++ lib/libavb/avb_rsa.h | 55 ++ lib/libavb/avb_sha.h | 72 ++ lib/libavb/avb_sha256.c | 364 +++++++ lib/libavb/avb_sha512.c | 362 +++++++ lib/libavb/avb_slot_verify.c | 1367 +++++++++++++++++++++++++++ lib/libavb/avb_slot_verify.h | 341 +++++++ lib/libavb/avb_sysdeps.h | 101 ++ lib/libavb/avb_sysdeps_posix.c | 63 ++ lib/libavb/avb_util.c | 412 ++++++++ lib/libavb/avb_util.h | 269 ++++++ lib/libavb/avb_vbmeta_image.c | 290 ++++++ lib/libavb/avb_vbmeta_image.h | 276 ++++++ lib/libavb/avb_version.c | 16 + lib/libavb/avb_version.h | 41 + lib/libavb/libavb.h | 32 + 35 files changed, 6698 insertions(+) create mode 100644 lib/libavb/avb_chain_partition_descriptor.c create mode 100644 lib/libavb/avb_chain_partition_descriptor.h create mode 100644 lib/libavb/avb_cmdline.c create mode 100644 lib/libavb/avb_cmdline.h create mode 100644 lib/libavb/avb_crypto.c create mode 100644 lib/libavb/avb_crypto.h create mode 100644 lib/libavb/avb_descriptor.c create mode 100644 lib/libavb/avb_descriptor.h create mode 100644 lib/libavb/avb_footer.c create mode 100644 lib/libavb/avb_footer.h create mode 100644 lib/libavb/avb_hash_descriptor.c create mode 100644 lib/libavb/avb_hash_descriptor.h create mode 100644 lib/libavb/avb_hashtree_descriptor.c create mode 100644 lib/libavb/avb_hashtree_descriptor.h create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.c create mode 100644 lib/libavb/avb_kernel_cmdline_descriptor.h create mode 100644 lib/libavb/avb_ops.h create mode 100644 lib/libavb/avb_property_descriptor.c create mode 100644 lib/libavb/avb_property_descriptor.h create mode 100644 lib/libavb/avb_rsa.c create mode 100644 lib/libavb/avb_rsa.h create mode 100644 lib/libavb/avb_sha.h create mode 100644 lib/libavb/avb_sha256.c create mode 100644 lib/libavb/avb_sha512.c create mode 100644 lib/libavb/avb_slot_verify.c create mode 100644 lib/libavb/avb_slot_verify.h create mode 100644 lib/libavb/avb_sysdeps.h create mode 100644 lib/libavb/avb_sysdeps_posix.c create mode 100644 lib/libavb/avb_util.c create mode 100644 lib/libavb/avb_util.h create mode 100644 lib/libavb/avb_vbmeta_image.c create mode 100644 lib/libavb/avb_vbmeta_image.h create mode 100644 lib/libavb/avb_version.c create mode 100644 lib/libavb/avb_version.h create mode 100644 lib/libavb/libavb.h
lib/libavb/avb_chain_partition_descriptor.c new file +46 -0
@@ -0,0 +1,46 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#include "avb_chain_partition_descriptor.h" +#include "avb_util.h" + +bool avb_chain_partition_descriptor_validate_and_byteswap ( +const AvbChainPartitionDescriptor * src,AvbChainPartitionDescriptor * dest) { +uint64_t expected_size; + +avb_memcpy (dest, src,sizeof (AvbChainPartitionDescriptor)); + +if (!avb_descriptor_validate_and_byteswap ((const AvbDescriptor *)src, + (AvbDescriptor *)dest)) +return false; + +if (dest->parent_descriptor.tag !=AVB_DESCRIPTOR_TAG_CHAIN_PARTITION ) { +avb_error ("Invalid tag for chain partition descriptor.\n" ); +return false; + } + + dest->rollback_index_location =avb_be32toh (dest->rollback_index_location); + dest->partition_name_len =avb_be32toh (dest->partition_name_len); + dest->public_key_len =avb_be32toh (dest->public_key_len); + +if (dest->rollback_index_location <1 ) { +avb_error ("Invalid rollback index location value.\n" ); +return false; + } + +/* Check that partition_name and public_key are fully contained. */ + expected_size =sizeof (AvbChainPartitionDescriptor) -sizeof (AvbDescriptor); +if (!avb_safe_add_to (&expected_size, dest->partition_name_len) || + !avb_safe_add_to (&expected_size, dest->public_key_len)) { +avb_error ("Overflow while adding up sizes.\n" ); +return false; + } +if (expected_size > dest->parent_descriptor.num_bytes_following) { +avb_error ("Descriptor payload size overflow.\n" ); +return false; + } +return true; +}
lib/libavb/avb_chain_partition_descriptor.h new file +54 -0
54 lines not on this page · raw message
lib/libavb/avb_cmdline.c new file +422 -0
422 lines not on this page · raw message
lib/libavb/avb_cmdline.h new file +72 -0
72 lines not on this page · raw message
lib/libavb/avb_crypto.c new file +354 -0
354 lines not on this page · raw message
lib/libavb/avb_crypto.h new file +156 -0
156 lines not on this page · raw message
lib/libavb/avb_descriptor.c new file +142 -0
142 lines not on this page · raw message
lib/libavb/avb_descriptor.h new file +113 -0
113 lines not on this page · raw message
lib/libavb/avb_footer.c new file +36 -0
@@ -0,0 +1,36 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#include "avb_footer.h" +#include "avb_util.h" + +bool avb_footer_validate_and_byteswap (const AvbFooter * src,AvbFooter * dest) { +avb_memcpy (dest, src,sizeof (AvbFooter)); + + dest->version_major =avb_be32toh (dest->version_major); + dest->version_minor =avb_be32toh (dest->version_minor); + + dest->original_image_size =avb_be64toh (dest->original_image_size); + dest->vbmeta_offset =avb_be64toh (dest->vbmeta_offset); + dest->vbmeta_size =avb_be64toh (dest->vbmeta_size); + +/* Check that magic is correct. */ +if (avb_safe_memcmp (dest->magic,AVB_FOOTER_MAGIC ,AVB_FOOTER_MAGIC_LEN ) != +0 ) { +avb_error ("Footer magic is incorrect.\n" ); +return false; + } + +/* Ensure we don't attempt to access any fields if the footer major +* version is not supported. +*/ +if (dest->version_major >AVB_FOOTER_VERSION_MAJOR ) { +avb_error ("No support for footer version.\n" ); +return false; + } + +return true; +}
lib/libavb/avb_footer.h new file +68 -0
68 lines not on this page · raw message
lib/libavb/avb_hash_descriptor.c new file +44 -0
44 lines not on this page · raw message
lib/libavb/avb_hash_descriptor.h new file +70 -0
70 lines not on this page · raw message
lib/libavb/avb_hashtree_descriptor.c new file +52 -0
52 lines not on this page · raw message
lib/libavb/avb_hashtree_descriptor.h new file +80 -0
80 lines not on this page · raw message
lib/libavb/avb_kernel_cmdline_descriptor.c new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (C) 2016 The Android Open Source Project +* +* SPDX-License-Identifier: MIT +*/ + +#include "avb_kernel_cmdline_descriptor.h" +#include "avb_util.h" + +bool avb_kernel_cmdline_descriptor_validate_and_byteswap ( +const AvbKernelCmdlineDescriptor * src,AvbKernelCmdlineDescriptor * dest) { +uint64_t expected_size; + +avb_memcpy (dest, src,sizeof (AvbKernelCmdlineDescriptor)); + +if (!avb_descriptor_validate_and_byteswap ((const AvbDescriptor *)src, + (AvbDescriptor *)dest)) +return false; + +if (dest->parent_descriptor.tag !=AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE ) { +avb_error ("Invalid tag for kernel cmdline descriptor.\n" ); +return false; + } + + dest->flags =avb_be32toh (dest->flags); + dest->kernel_cmdline_length =avb_be32toh (dest->kernel_cmdline_length); + +/* Check that kernel_cmdline is fully contained. */ + expected_size =sizeof (AvbKernelCmdlineDescriptor) -sizeof (AvbDescriptor); +if (!avb_safe_add_to (&expected_size, dest->kernel_cmdline_length)) { +avb_error ("Overflow while adding up sizes.\n" ); +return false; + } +if (expected_size > dest->parent_descriptor.num_bytes_following) { +avb_error ("Descriptor payload size overflow.\n" ); +return false; + } + +return true; +}
lib/libavb/avb_kernel_cmdline_descriptor.h new file +63 -0
63 lines not on this page · raw message
lib/libavb/avb_ops.h new file +293 -0
293 lines not on this page · raw message
lib/libavb/avb_property_descriptor.c new file +167 -0
167 lines not on this page · raw message
lib/libavb/avb_property_descriptor.h new file +89 -0
89 lines not on this page · raw message
lib/libavb/avb_rsa.c new file +276 -0
276 lines not on this page · raw message
lib/libavb/avb_rsa.h new file +55 -0
55 lines not on this page · raw message
lib/libavb/avb_sha.h new file +72 -0
72 lines not on this page · raw message
lib/libavb/avb_sha256.c new file +364 -0
236 lines not on this page · raw message
lib/libavb/avb_sha512.c new file +362 -0
362 lines not on this page · raw message
lib/libavb/avb_slot_verify.c new file +1367 -0
1,367 lines not on this page · raw message
lib/libavb/avb_slot_verify.h new file +341 -0
341 lines not on this page · raw message
lib/libavb/avb_sysdeps.h new file +101 -0
101 lines not on this page · raw message
lib/libavb/avb_sysdeps_posix.c new file +63 -0
63 lines not on this page · raw message
lib/libavb/avb_util.c new file +412 -0
412 lines not on this page · raw message
lib/libavb/avb_util.h new file +269 -0
269 lines not on this page · raw message
lib/libavb/avb_vbmeta_image.c new file +290 -0
290 lines not on this page · raw message
lib/libavb/avb_vbmeta_image.h new file +276 -0
276 lines not on this page · raw message
lib/libavb/avb_version.h new file +41 -0
41 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
PATCH v2 1/8 avb2.0: add Android Verified Boot 2.0 library
Quoted 12 lines · Igor Opaniuk
Add libavb lib (3rd party library from AOSP), that implements support of AVB 2.0. This library is used for integrity checking of Android partitions on eMMC.
libavb was added as it is and minimal changes were introduced to reduce maintenance cost, because it will be deviated from AOSP upstream in the future.
Changes:
- license headers changed to conform SPDX-style
-avb_crc32.cdropped
- updates inavb_sysdeps_posix.c/avb_sysdeps.h
Quoted 5 lines
For additional details check [1] AVB 2.0 README.
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
Signed-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/968d5e70/attachment.sig>
PATCH v2 2/8 avb2.0: integrate avb 2.0 into the build system
In reply to Igor OpaniukIntegrate libavb into the build system. Introduce CONFIG_LIBAVB build option.
--- lib/Kconfig | 14 ++++++++++++++ lib/Makefile | 1 + lib/libavb/Makefile | 15 +++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 lib/libavb/Makefile
lib/Kconfig +14 -0
@@ -142,6 +142,20 @@ config TPM endmenu +menu "Android Verified Boot" + +config LIBAVB + bool "Android Verified Boot 2.0 support" + depends on ANDROID_BOOT_IMAGE + default n + help + This enables support of Android Verified Boot 2.0 which can be used + to assure the end user of the integrity of the software running on a + device. Introduces such features as boot chain of trust, rollback + protection etc. + +endmenu + menu "Hashing Support" config SHA1
lib/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_$(SPL_)ZLIB) += zlib/ obj-$(CONFIG_$(SPL_)GZIP) += gunzip.o obj-$(CONFIG_$(SPL_)LZO) += lzo/ +obj-$(CONFIG_LIBAVB) += libavb/ obj-$(CONFIG_$(SPL_TPL_)SAVEENV) += qsort.o obj-$(CONFIG_$(SPL_TPL_)OF_LIBFDT) += libfdt/
lib/libavb/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +# +# (C) Copyright 2017 Linaro Limited +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_LIBAVB) += avb_chain_partition_descriptor.o avb_cmdline.o +obj-$(CONFIG_LIBAVB) += avb_crypto.o avb_footer.o avb_hashtree_descriptor.o +obj-$(CONFIG_LIBAVB) += avb_property_descriptor.o avb_sha256.o +obj-$(CONFIG_LIBAVB) += avb_slot_verify.o avb_util.o avb_version.o +obj-$(CONFIG_LIBAVB) += avb_descriptor.o avb_hash_descriptor.o +obj-$(CONFIG_LIBAVB) += avb_kernel_cmdline_descriptor.o avb_rsa.o avb_sha512.o +obj-$(CONFIG_LIBAVB) += avb_sysdeps_posix.o avb_vbmeta_image.o + +ccflags-y = -DAVB_COMPILATION
Signature · 1 line
2.7.4
PATCH v2 2/8 avb2.0: integrate avb 2.0 into the build system
Quoted 4 lines · Igor Opaniuk
Integrate libavb into the build system. Introduce
CONFIG_LIBAVBbuild option.Signed-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/8e32cfcb/attachment.sig>
PATCH v2 3/8 avb2.0: implement AVB ops
In reply to Igor OpaniukImplement AVB ops on top of existing mmc subsystem API. Currently there is a full implementation of such operations, defined by [1] AVB2.0 specification:
.read_from_partition() - reads N bytes from a partition identified by a name.
.write_to_partition() - Writes N bytes to a partition identified by a name. .validate_vbmeta_public_key() - checks if the given public ‘vbmeta’ partition is trusted.
.get_unique_guid_for_partition() - Gets the GUID for a partition identified by a string name.
As [1] specification recommends to use tamper-evident storage for storing rollback indexes and device state (LOCKED/UNLOCKED),
currently are only stubs instead of full implementation for these ops:
.read_rollback_index() - Gets the rollback index for a given index location .write_rollback_index() - Sets the rollback index to a given location .read_is_device_unlocked() - Gets where the device is unlocked
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
--- common/Makefile | 2 + common/avb_verify.c | 610 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/avb_verify.h | 79 +++++++ 3 files changed, 691 insertions(+) create mode 100644 common/avb_verify.c create mode 100644 include/avb_verify.h
common/Makefile +2 -0
@@ -136,3 +136,5 @@ obj-$(CONFIG_$(SPL_)LOG) += log.o obj-$(CONFIG_$(SPL_)LOG_CONSOLE) += log_console.o obj-y += s_record.o obj-y += xyzModem.o + +obj-$(CONFIG_LIBAVB) += avb_verify.o
common/avb_verify.c new file +610 -0
610 lines not on this page · raw message
include/avb_verify.h new file +79 -0
79 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 3/8 avb2.0: implement AVB ops
Quoted 19 lines · Igor Opaniuk
Implement AVB ops on top of existing mmc subsystem API. Currently there is a full implementation of such operations, defined by [1] AVB2.0 specification:
.read_from_partition() - reads N bytes from a partition identified by a name.
.write_to_partition() - Writes N bytes to a partition identified by a name. .validate_vbmeta_public_key() - checks if the given public ‘vbmeta’ partition is trusted.
.get_unique_guid_for_partition() - Gets the GUID for a partition identified by a string name.As [1] specification recommends to use tamper-evident storage for storing rollback indexes and device state (LOCKED/UNLOCKED),
currently are only stubs instead of full implementation for these ops:
.read_rollback_index() - Gets the rollback index for a given index location .write_rollback_index() - Sets the rollback index to a given location .read_is_device_unlocked() - Gets where the device is unlocked
Quoted 3 lines
[1] https://android.googlesource.com/platform/external/avb/+/master/README.md
Signed-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/b3a1caa6/attachment.sig>
PATCH v2 4/8 cmd: avb2.0: avb command for performing verification
In reply to Igor OpaniukEnable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avb read_rb - read rollback index
avb write_rb - write rollback index
avb is_unlocked - check device lock state
avb get_uuid - read and print uuid of a partition
avb read_part - read data from partition
avb read_part_hex - read data from partition and output to stdout avb write_part - write data to partition
avb verify - run full verification chain
--- cmd/Kconfig | 16 +++ cmd/Makefile | 3 + cmd/avb.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 376 insertions(+) create mode 100644 cmd/avb.c
cmd/Kconfig +16 -0
@@ -1675,6 +1675,22 @@ config CMD_TRACE for analsys (e.g. using bootchart). See doc/README.trace for full details. +config CMD_AVB + bool "avb - Android Verified Boot 2.0 operations" + depends on LIBAVB + default n + help + Enables a "avb" command to perform verification of partitions using + Android Verified Boot 2.0 functionality. It includes such subcommands: + avb init - initialize avb2 subsystem + avb read_rb - read rollback index + avb write_rb - write rollback index + avb is_unlocked - check device lock state + avb get_uuid - read and print uuid of a partition + avb read_part - read data from partition + avb read_part_hex - read data from partition and output to stdout + avb write_part - write data to partition + avb verify - run full verification chain endmenu config CMD_UBI
cmd/Makefile +3 -0
@@ -151,6 +151,9 @@ obj-$(CONFIG_CMD_REGULATOR) += regulator.o obj-$(CONFIG_CMD_BLOB) += blob.o +# Android Verified Boot 2.0 +obj-$(CONFIG_CMD_AVB) += avb.o + obj-$(CONFIG_X86) += x86/ endif # !CONFIG_SPL_BUILD
cmd/avb.c new file +357 -0
357 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 4/8 cmd: avb2.0: avb command for performing verification
Quoted 12 lines · Igor Opaniuk
Enable a "avb" command to execute Android Verified
Boot 2.0 operations. It includes such subcommands:
avb init - initialize avb2 subsystem
avbread_rb- read rollback index
avbwrite_rb- write rollback index
avbis_unlocked- check device lock state
avbget_uuid- read and print uuid of a partition
avbread_part- read data from partition
avbread_part_hex- read data from partition and output to stdout avbwrite_part- write data to partition
avb verify - run full verification chain
Quoted 1 line
Signed-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/90cb81ca/attachment.sig>
PATCH v2 5/8 avb2.0: add boot states and dm-verity support
In reply to Igor Opaniuk1. Add initial support of boot states mode (red, green, yellow)
2. Add functions for enforcing dm-verity configurations
--- cmd/avb.c | 17 ++++++- common/avb_verify.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++-- include/avb_verify.h | 19 ++++++- 3 files changed, 168 insertions(+), 5 deletions(-)
cmd/avb.c +16 -1
@@ -218,6 +218,8 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag, {AvbSlotVerifyResult slot_result;AvbSlotVerifyData *out_data; +char *cmdline; +char *extra_args;bool unlocked = false;int res =CMD_RET_FAILURE ;
@@ -249,10 +251,23 @@ int do_avb_verify_part(cmd_tbl_t *cmdtp, int flag,switch (slot_result) {case AVB_SLOT_VERIFY_RESULT_OK : +/* Until we don't have support of changing unlock states, we +* assume that we are by default in locked state. +* So in this case we can boot only when verification is +* successful; we also supply in cmdline GREEN boot state +*/ printf ("Verification passed successfully\n" );/* export additional bootargs to AVB_BOOTARGS env var */ -env_set (AVB_BOOTARGS , out_data->cmdline); + + extra_args =avb_set_state (avb_ops,AVB_GREEN ); +if (extra_args) + cmdline =append_cmd_line (out_data->cmdline, + extra_args); +else + cmdline = out_data->cmdline; + +env_set (AVB_BOOTARGS , cmdline); res =CMD_RET_SUCCESS ;break ;
common/avb_verify.c +134 -3
161 lines not on this page · raw message
include/avb_verify.h +18 -1
@@ -11,11 +11,22 @@#include <../lib/libavb/libavb.h> #include <mmc.h> -#define ALLOWED_BUF_ALIGN 8 +#define AVB_MAX_ARGS 1024 +#define VERITY_TABLE_OPT_RESTART "restart_on_corruption" +#define VERITY_TABLE_OPT_LOGGING "ignore_corruption" +#define ALLOWED_BUF_ALIGN 8 + +enum avb_boot_state { +AVB_GREEN , +AVB_YELLOW , +AVB_ORANGE , +AVB_RED , +};struct AvbOpsData {struct AvbOps ops;int mmc_dev; +enum avb_boot_state boot_state; };struct mmc_part {
@@ -33,6 +44,12 @@ enum mmc_io_type {AvbOps *avb_ops_alloc (int boot_device);void avb_ops_free (AvbOps *ops); +char *avb_set_state (AvbOps *ops,enum avb_boot_state boot_state); +char *avb_set_enforce_verity (const char *cmdline); +char *avb_set_ignore_corruption (const char *cmdline); + +char *append_cmd_line (char *cmdline_orig,char *cmdline_new); +/** * ============================================================================ * I/O helper inline functions
Signature · 1 line
2.7.4
PATCH v2 5/8 avb2.0: add boot states and dm-verity support
Quoted 4 lines · Igor Opaniuk
1. Add initial support of boot states mode (red, green, yellow)
2. Add functions for enforcing dm-verity configurationsSigned-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/9d99da65/attachment.sig>
PATCH v2 6/8 am57xx_hs: avb2.0: add support of AVB 2.0
In reply to Igor Opaniuk1. Add vbmeta partition info to android partition layout for am57xx SoC
2. Add support of AVB 2.0 (including avb subset of commands) for am57xx HS
--- include/configs/am57xx_evm.h | 11 +++++++++++ include/environment/ti/boot.h | 15 +++++++++++++++ 2 files changed, 26 insertions(+)
include/configs/am57xx_evm.h +11 -0
@@ -38,6 +38,16 @@#define CONFIG_SYS_OMAP_ABE_SYSCK +#define VBMETA_PART_SIZE (64 * 1024) + +#if defined(CONFIG_LIBAVB ) +#define VBMETA_PART \ + "name=vbmeta,size=" __stringify(VBMETA_PART_SIZE) \ + ",uuid=${uuid_gpt_vbmeta};" +#else +#define VBMETA_PART "" +#endif +/* Define the default GPT table for eMMC */ #define PARTS_DEFAULT \/* Linux partitions */ \
@@ -61,6 +71,7 @@"name=cache,size=256M,uuid=${uuid_gpt_cache};" \"name=ipu1,size=1M,uuid=${uuid_gpt_ipu1};" \"name=ipu2,size=1M,uuid=${uuid_gpt_ipu2};" \ +VBMETA_PART \"name=userdata,size=-,uuid=${uuid_gpt_userdata}" #define DFUARGS \
include/environment/ti/boot.h +15 -0
@@ -18,6 +18,19 @@#define PARTS_DEFAULT #endif +#if defined(CONFIG_CMD_AVB ) +#define AVB_VERIFY_CHECK "if run avb_verify; then " \ + "echo AVB verification OK.;" \ + "set bootargs $bootargs $avb_bootargs;" \ + "else " \ + "echo AVB verification failed.;" \ + "exit; fi;" +#define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify;\0" +#else +#define AVB_VERIFY_CHECK "" +#define AVB_VERIFY_CMD "" +#endif +#define DEFAULT_COMMON_BOOT_TI_ARGS \ "console=" CONSOLEDEV ",115200n8\0" \ "fdtfile=undefined\0" \
@@ -26,6 +39,7 @@"bootfile=zImage\0" \"usbtty=cdc_acm\0" \"vram=16M\0" \ +AVB_VERIFY_CMD \"partitions=" PARTS_DEFAULT "\0" \"optargs=\0" \"dofastboot=0\0" \
@@ -43,6 +57,7 @@"setenv machid fe6; " \"mmc dev $mmcdev; " \"mmc rescan; " \ +AVB_VERIFY_CHECK \"part start mmc ${mmcdev} environment fdt_start; " \"part size mmc ${mmcdev} environment fdt_size; " \"part start mmc ${mmcdev} boot boot_start; " \
Signature · 1 line
2.7.4
PATCH v2 6/8 am57xx_hs: avb2.0: add support of AVB 2.0
Quoted 4 lines · Igor Opaniuk
1. Add vbmeta partition info to android partition layout for am57xx SoC
2. Add support of AVB 2.0 (including avb subset of commands) for am57xx HSSigned-off-by Igor Opaniuk <[email protected]>
I re-worded this slightly as it only updates include/environment/ti/boot.h now, a follow-up is still needed to enable CMD_AVB on the platform. That said, applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/dbcad26f/attachment.sig>
PATCH v2 7/8 test/py: avb2.0: add tests for avb commands
In reply to Igor Opaniuk1. Run AVB 2.0 full verification chain, avb verify
2. Check if 'avb get_uuid' works, compare results with 'part list mmc 1' output
3. Test avb read commands, which reads N bytes from a partition identified by a name
--- test/py/tests/test_avb.py | 111 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/py/tests/test_avb.py
test/py/tests/test_avb.py new file +111 -0
@@ -0,0 +1,111 @@ +# Copyright (c) 2018, Linaro Limited +# +# SPDX-License-Identifier: GPL-2.0+ +# +# Android Verified Boot 2.0 Test + +""" +This tests Android Verified Boot 2.0 support in U-boot: + +For additional details about how to build proper vbmeta partition +check doc/README.avb2 + +For configuration verification: +- Corrupt boot partition and check for failure +- Corrupt vbmeta partition and check for failure +""" + +import pytest +import u_boot_utils as util + +# defauld mmc id +mmc_dev = 1 +temp_addr = 0x90000000 +temp_addr2 = 0x90002000 + +def test_avb_verify(u_boot_console): + """Run AVB 2.0 boot verification chain with avb subset of commands + """ + + success_str = "Verification passed successfully" + + response = u_boot_console.run_command('avb init %s' %str(mmc_dev)) + assert response == '' + response = u_boot_console.run_command('avb verify') + assert response.find(success_str) + + +def test_avb_mmc_uuid(u_boot_console): + """Check if 'avb get_uuid' works, compare results with + 'part list mmc 1' output + """ + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('mmc rescan; mmc dev %s' % + str(mmc_dev)) + assert response.find('is current device') + + part_lines = u_boot_console.run_command('mmc part').splitlines() + part_list = {} + cur_partname = "" + + for line in part_lines: + if "\"" in line: + start_pt = line.find("\"") + end_pt = line.find("\"", start_pt + 1) + cur_partname = line[start_pt + 1: end_pt] + + if "guid:" in line: + guid_to_check = line.split("guid:\t") + part_list[cur_partname] = guid_to_check[1] + + # lets check all guids with avb get_guid + for part, guid in part_list.iteritems(): + avb_guid_resp = u_boot_console.run_command('avb get_uuid %s' % part) + assert guid == avb_guid_resp.split("UUID: ")[1] + + +def test_avb_read_rb(u_boot_console): + """Test reading rollback indexes + """ + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('avb read_rb 1') + + +def test_avb_is_unlocked(u_boot_console): + """Test if device is in the unlocked state + """ + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('avb is_unlocked') + + +def test_avb_mmc_read(u_boot_console): + """Test mmc read operation + """ + + response = u_boot_console.run_command('mmc rescan; mmc dev %s 0' % + str(mmc_dev)) + assert response.find('is current device') + + response = u_boot_console.run_command('mmc read 0x%x 0x100 0x1' % temp_addr) + assert response.find('read: OK') + + response = u_boot_console.run_command('avb init %s' % str(mmc_dev)) + assert response == '' + + response = u_boot_console.run_command('avb read_part xloader 0 100 0x%x' % + temp_addr2) + assert response.find('Read 512 bytes') + + # Now lets compare two buffers + response = u_boot_console.run_command('cmp 0x%x 0x%x 40' % + (temp_addr, temp_addr2)) + assert response.find('64 word')
Signature · 1 line
2.7.4
PATCH v2 7/8 test/py: avb2.0: add tests for avb commands
Quoted 7 lines · Igor Opaniuk
1. Run AVB 2.0 full verification chain, avb verify
2. Check if 'avbget_uuid' works, compare results with 'part list mmc 1' output
3. Testavb readcommands, which reads N bytes from a partition identified by a nameSigned-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/0af8e8b6/attachment.sig>
PATCH v2 8/8 doc: avb2.0: add README about AVB2.0 integration
In reply to Igor OpaniukContains:
1. Overview of Android Verified Boot 2.0
2. Description of avb subset of commands
3. Examples of errors when boot/vendor/system/vbmeta partitions are tampered
4. Examples of enabling AVB2.0 on your setup
--- doc/README.avb2 | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 doc/README.avb2
doc/README.avb2 new file +97 -0
@@ -0,0 +1,97 @@ +Android Verified Boot 2.0 + +This file contains information about the current support of Android Verified +Boot 2.0 in U-boot + +1. OVERVIEW +--------------------------------- +Verified Boot establishes a chain of trust from the bootloader to system images +* Provides integrity checking for: + - Android Boot image: Linux kernel + ramdisk. RAW hashing of the whole + partition is done and the hash is compared with the one stored in + the VBMeta image + - system/vendor partitions: verifying root hash of dm-verity hashtrees. +* Provides capabilities for rollback protection. + +Integrity of the bootloader (U-boot BLOB and environment) is out of scope. + +For additional details check: +https://android.googlesource.com/platform/external/avb/+/master/README.md + + +2. AVB 2.0 U-BOOT SHELL COMMANDS +----------------------------------- +Provides CLI interface to invoke AVB 2.0 verification + misc. commands for +different testing purposes: + +avb init <dev> - initialize avb 2.0 for <dev> +avb verify - run verification process using hash data from vbmeta structure +avb read_rb <num> - read rollback index at location <num> +avb write_rb <num> <rb> - write rollback index <rb> to <num> +avb is_unlocked - returns unlock status of the device +avb get_uuid <partname> - read and print uuid of partition <partname> +avb read_part <partname> <offset> <num> <addr> - read <num> bytes from +partition <partname> to buffer <addr> +avb write_part <partname> <offset> <num> <addr> - write <num> bytes to +<partname> by <offset> using data from <addr> + + +3. PARTITIONS TAMPERING (EXAMPLE) +----------------------------------- +Boot or system/vendor (dm-verity metadata section) is tampered: +=> avb init 1 +=> avb verify +avb_slot_verify.c:175: ERROR: boot: Hash of data does not match digest in +descriptor. +Slot verification result: ERROR_IO + +Vbmeta partition is tampered: +=> avb init 1 +=> avb verify +avb_vbmeta_image.c:206: ERROR: Hash does not match! +avb_slot_verify.c:388: ERROR: vbmeta: Error verifying vbmeta image: +HASH_MISMATCH +Slot verification result: ERROR_IO + + +4. ENABLE ON YOUR BOARD +----------------------------------- +The following options must be enabled: +CONFIG_LIBAVB=y +CONFIG_CMD_AVB=y + + +Then add `avb verify` invocation to your android boot sequence of commands, +e.g.: + +=> avb_verify=avb init $mmcdev; avb verify; +=> if run avb_verify; then \ + echo AVB verification OK. Continue boot; \ + set bootargs $bootargs $avb_bootargs; \ + else \ + echo AVB verification failed; \ + exit; \ + fi; \ + +=> emmc_android_boot= \ + echo Trying to boot Android from eMMC ...; \ + ... \ + run avb_verify; \ + mmc read ${fdtaddr} ${fdt_start} ${fdt_size}; \ + mmc read ${loadaddr} ${boot_start} ${boot_size}; \ + bootm $loadaddr $loadaddr $fdtaddr; \ + + +To switch on automatic generation of vbmeta partition in AOSP build, add these +lines to device configuration mk file: + +BOARD_AVB_ENABLE := true +BOARD_AVB_ALGORITHM := SHA512_RSA4096 +BOARD_BOOTIMAGE_PARTITION_SIZE := <boot partition size> + +After flashing U-boot don't forget to update environment and write new +partition table: +=> env default -f -a +=> setenv partitions $partitions_android +=> env save +=> gpt write mmc 1 $partitions_android
Signature · 1 line
2.7.4
PATCH v2 8/8 doc: avb2.0: add README about AVB2.0 integration
Quoted 8 lines · Igor Opaniuk
Contains:
1. Overview of Android Verified Boot 2.0
2. Description of avb subset of commands
3. Examples of errors when boot/vendor/system/vbmeta partitions are tampered
4. Examples of enabling AVB2.0 on your setupSigned-off-by Igor Opaniuk <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180619/9e6f6d48/attachment.sig>