Commit Graph

450 Commits

Author SHA1 Message Date
Andrew Gunnerson 446e87289f CHANGELOG.md: Add entry for PR #234
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 22:14:44 -05:00
Andrew Gunnerson 04b8e3c315 Merge pull request #234 from chenxiaolong/fec_param_order
fec: Change update() parameter order to be more consistent
2023-12-17 22:14:09 -05:00
Andrew Gunnerson 03809a1e88 fec: Change update() parameter order to be more consistent
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 22:07:00 -05:00
Andrew Gunnerson 1fcb29532d CHANGELOG.md: Add entry for PR #233
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 21:08:28 -05:00
Andrew Gunnerson b383c8a0ab Merge pull request #233 from chenxiaolong/hash_tree
Split dm-verify hash tree logic out of avb module
2023-12-17 21:06:07 -05:00
Andrew Gunnerson 7ea8e8fa9e Split dm-verify hash tree logic out of avb module
* Refactor hash tree computation to work on a preallocated hash tree
  buffer. This makes it possible to partially update a hash tree, which
  is now supported.

* Add new subcommands for working with hash trees. There's no standard
  header format for dm-verity information, so these commands write hash
  tree files with a custom header. The commands are not really useful
  outside of debugging avbroot's hash tree implementation.

  Using AVB was considered, but it has no support for the hash tree data
  living in a separate file from the input. If other parties agree on a
  standard header in the future, avbroot will switch to that format.

* Add tests for the hash tree implementation.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 20:48:00 -05:00
Andrew Gunnerson ce43b3c657 CHANGELOG.md: Add entry for PR #232
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 15:08:43 -05:00
Andrew Gunnerson 05e5e59d65 Merge pull request #232 from chenxiaolong/small_hash_tree
avb: hashtree: Fix incorrect I/O read size for input smaller than one block
2023-12-17 15:07:51 -05:00
Andrew Gunnerson 72b8120bf9 avb: hashtree: Fix incorrect I/O read size for input smaller than one block
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 15:00:50 -05:00
Andrew Gunnerson 8110f82b17 CHANGELOG.md: Add entry for PR #231
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 14:59:47 -05:00
Andrew Gunnerson 64dbfa241e Merge pull request #231 from chenxiaolong/overlap
util: merge_overlapping: Skip empty and invalid ranges
2023-12-17 14:59:11 -05:00
Andrew Gunnerson 7041c8ef2c util: merge_overlapping: Skip empty and invalid ranges
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 14:50:21 -05:00
Andrew Gunnerson 7296eed51f CHANGELOG.md: Add entry for PR #230
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 00:48:36 -05:00
Andrew Gunnerson 698810d256 Merge pull request #230 from chenxiaolong/fec_update
fec: Add support for partially updating FEC data
2023-12-17 00:47:45 -05:00
Andrew Gunnerson acf57272a7 fec: Add support for partially updating FEC data
FEC data can be updated efficiently with "round" granularity when the
regions where the input file was modified are known.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-17 00:39:04 -05:00
Andrew Gunnerson 2b50e4527f CHANGELOG.md: Add entry for PR #229
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-16 23:09:09 -05:00
Andrew Gunnerson cd7b5ab23c Merge pull request #229 from chenxiaolong/partition_hashes
cli/ota: Also verify whole-partition hashes
2023-12-16 23:07:45 -05:00
Andrew Gunnerson f73c451d23 cli/ota: Also verify whole-partition hashes
Previously, when running `avbroot ota verify`, only the payload chunk
hashes were verified.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-16 22:59:33 -05:00
Andrew Gunnerson a801e18595 CHANGELOG.md: Add entry for PR #228
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-16 22:51:06 -05:00
Andrew Gunnerson 3932ff9092 Merge pull request #228 from chenxiaolong/parallel_compress
Split new partition images into chunks and compress in parallel
2023-12-16 22:49:22 -05:00
Andrew Gunnerson 1a36fbd46c Split new partition images into chunks and compress in parallel
Previously, all replacement partition images (those that have been
patched or `--replace`d) were compressed as a whole, which would be very
slow for larger images. Instead, we'll split the images into 2 MiB
chunks and compress them in parallel. This more closely matches what
AOSP's payload_generator does and scales linearly with the number of CPU
cores. The compression is less efficient, but the file size generally
only increases by 10s of KiB.

This commit also reworks the implementation so that patched images are
stored in temp files instead of in memory again. In hindsight, doing
everything in memory only made things more complex and causes the memory
usage to blow up when doing things like `--replace system <path>`.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-16 22:38:18 -05:00
Andrew Gunnerson 077a80f4ce CHANGELOG.md: Add entry for PR #226
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 21:41:30 -05:00
Andrew Gunnerson 1e43930f3c Merge pull request #226 from chenxiaolong/critical
cli/ota: Limit critical partition check to bootloader-verified partitions
2023-12-12 21:39:39 -05:00
Andrew Gunnerson d00e53fb2a cli/ota: Limit critical partition check to bootloader-verified partitions
dm-verity partitions don't necessarily have AVB descriptors inside the
root vbmeta images. The fstab might verify them against a public key on
disk using the `avb_keys` fs_mgr option. We have no way to statically
check for this scenario and it's becoming increasingly common on newer
OnePlus devices. Instead, we'll just limit the checks to partitions that
are verified by the bootloader.

Fixes: #223

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 21:30:24 -05:00
Andrew Gunnerson 0b5f3b30cf CHANGELOG.md: Add entry for PR #227
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 21:30:09 -05:00
Andrew Gunnerson 10c2a0969f Merge pull request #227 from chenxiaolong/symlink
workflows/ci: Fix overwriting symlink for target/output
2023-12-12 21:29:25 -05:00
Andrew Gunnerson 83218a747d workflows/ci: Fix overwriting symlink for target/output
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 21:19:26 -05:00
Andrew Gunnerson 6fb7d568cd CHANGELOG.md: Add entry for PR #224
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 19:12:11 -05:00
Andrew Gunnerson 6cbf690e17 Merge pull request #224 from chenxiaolong/static
workflows/ci: Build statically linked executables where possible
2023-12-12 19:07:02 -05:00
Andrew Gunnerson e097f98404 workflows/ci: Build statically linked executables where possible
This way, the precompiled executables can run on distros that ship an
older version of glibc or don't use glibc at all.

Fixes: #222

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 18:34:02 -05:00
Andrew Gunnerson d5605eabc0 workflows/ci: Use Rust triple instead of LLVM triple
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-12 18:05:00 -05:00
Andrew Gunnerson d1bcf2da80 CHANGELOG.md: Add entry for PR #221
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-11 18:23:49 -05:00
Andrew Gunnerson bbf8e28a28 Merge pull request #221 from chenxiaolong/otacerts
cli/ota: Add new --otacerts-partition option for the patch subcommand
2023-12-11 18:22:03 -05:00
Andrew Gunnerson dc93b17888 cli/ota: Add new --otacerts-partition option
The autodetection logic for `@otacerts` is based on the presence of the
`recovery`, `vendor_boot`, and `boot` partitions (in that order). Some
devices have `vendor_boot`, but put `system/etc/security/otacerts.zip`
inside `boot`.

With the way things are written now, we don't have the ability to
inspect the actual partition images for the autodetection. It is based
on the name only. So, for now, we'll just allow the user to override the
autodetected partition similar to what we already do with the
`--boot-partition` option.

Issue: #218

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-10 23:32:14 -05:00
Andrew Gunnerson f83a408dc4 CHANGELOG.md: Add entry for PR #220
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-10 16:03:08 -05:00
Andrew Gunnerson 798fddc4d5 Merge pull request #220 from chenxiaolong/odm
cli/ota: Fine tune `is_critical_to_avb()` for odm partition
2023-12-10 16:01:43 -05:00
Andrew Gunnerson dfed06dcf8 cli/ota: Fine tune is_critical_to_avb() for odm partition
AOSP primarily cares about `odm` and `odm_dlkm`, so update the logic to
check for that specifically. This fixes patching some OTAs that include
an unprotected OEM-specific `odm_ext` image.

Issue: #218

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-10 15:54:02 -05:00
Andrew Gunnerson 02fd92a640 CHANGELOG.md: Add entry for PR #219
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-10 13:47:33 -05:00
Andrew Gunnerson dd4faf72ae Merge pull request #219 from chenxiaolong/decode-avb
key: Add new decode-avb subcommand
2023-12-10 13:43:58 -05:00
Andrew Gunnerson adbe249edb key: Add new decode-avb subcommand
This does the reverse of `avbroot key extract-avb`. It's useful for
reconstructing a PKCS8-encoded RSA public key when working with the
`public_key` fields in `avb.toml`.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-10 13:29:45 -05:00
Andrew Gunnerson b7028b13a2 CHANGELOG.md: Add entry for PR #214
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-03 18:44:11 -05:00
Andrew Gunnerson 8122b0eece Merge pull request #214 from chenxiaolong/RUSTSEC-2023-0071
deny.toml: Temporarily ignore RUSTSEC-2023-0071
2023-12-03 18:41:17 -05:00
Andrew Gunnerson 0613de4ee4 deny.toml: Temporarily ignore RUSTSEC-2023-0071
https://rustsec.org/advisories/RUSTSEC-2023-0071

This is a side-channel vulnerability where secrets can be leaked to an
attacker that is able to measure the timing of a large number of RSA
operations. As of 2023-12-03, there is no released version of the rsa
crate that contains a fix.

For avbroot specifically, this vulnerability is not too critical for a
couple reasons:

1. avbroot performs RSA signing only at the end of lengthy processes
   that involve a lot of disk I/O. It's very expensive to run avbroot
   the millions of times needed to capture a sufficient amount of timing
   data.
2. During a single run of avbroot, it will only perform RSA signing a
   handful of times. To get sufficient measurements, the attacker would
   need to rerun avbroot. If they are able to rerun avbroot, then they
   are also able to just read and steal the private key directly.

avbroot has no network capabilities, so this is not inherently remotely
exploitable.

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-03 18:02:48 -05:00
Andrew Gunnerson 1a18eb7f85 README.md: Document OnePlus boot issues
Issue: #186
Issue: #195
Issue: #212

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-12-03 14:58:38 -05:00
Andrew Gunnerson 1e1ca9dcbf CHANGELOG.md: Add entry for PR #211
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-11-22 19:51:39 -05:00
Andrew Gunnerson 6924783f48 Merge pull request #211 from chenxiaolong/lints
Fix new lint warnings from rustc and clippy 1.74.0
2023-11-22 19:50:27 -05:00
Andrew Gunnerson 98071daa33 Fix new lint warnings from rustc and clippy 1.74.0
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-11-22 19:30:52 -05:00
Andrew Gunnerson 8e1adae947 CHANGELOG.md: Add entry for PR #210
Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-11-22 19:29:00 -05:00
Andrew Gunnerson d6705f4f00 Merge pull request #210 from chenxiaolong/avb_2.0_format_1.3
avb: Add support for AVB 2.0 format 1.3.0
2023-11-22 19:27:24 -05:00
Andrew Gunnerson a648df1695 avb: Add support for AVB 2.0 format 1.3.0
Format version 1.3.0 adds a new 32-bit big endian `flags` field to
chain descriptors, carved out from the `reserved` array. There is only
one possible flag, which indicates that the target partition is not A/B
and so the bootloader should not append the `_a` or `_b` suffix.

There are no known AVB images in the wild where the first four bytes of
the `reserved` field are not zero. Thus, to keep the logic simple, the
AVB parser will unconditionally parse those bytes as if they were the
`flags` field, regardless of the file format version.

AOSP changes:

* https://android.googlesource.com/platform/external/avb/+/a1fe228b86543a21739c51352f5ce72f134fccfa%5E%21/
* https://android.googlesource.com/platform/external/avb/+/d00d02c390e267ef43d93562864dd6e45966c435%5E%21/

Signed-off-by: Andrew Gunnerson <accounts+github@chiller3.com>
2023-11-22 18:47:35 -05:00