Skip to content

Fully update AVB hash header to match repacked contents. - #9831

Draft
kousu wants to merge 2 commits into
topjohnwu:masterfrom
kousu:repack-avb-header
Draft

Fully update AVB hash header to match repacked contents.#9831
kousu wants to merge 2 commits into
topjohnwu:masterfrom
kousu:repack-avb-header

Conversation

@kousu

@kousu kousu commented Apr 27, 2026

Copy link
Copy Markdown

This follows (=> is drafted until) #9830 by adding the full recompution of the AVB hash.

Apparently few (no?) devices actually respect this hash in the wild at the moment, but it is good to be prepared!

@kousu

kousu commented Apr 27, 2026

Copy link
Copy Markdown
Author

To see the effect of this, use this script: examine_avb.py

Stock

digest match: True

$ curl -sJLO https://mirrorbits.lineageos.org/full/kiev/20260419/boot.img
$ ./examine_avb.py boot.img

=== boot.img ===
  file_size:       0x6000000 (100663296)
  orig_size:       0x23bd000
  vbmeta_offset:   0x23bd000
  vbmeta_size:     0x2c0
  gap:             0x0 (0)
  vbmeta flags:    0x00000000  (none)
  algorithm:       0
  release_string:  'avbtool 1.3.0'
  descriptors at:  [0x23bd100..0x23bd2a8]
  HASH descriptor:
    partition:     'boot'
    image_size:    0x23bd000
    hash_algo:     'sha256'
    flags:         0x00000000
    salt:          a7a8220ea5d051979b4e8baa35fdabfb6e150d16e1b73b5f4cbb707f7f8c7980
    digest:        8946f4dc4ab8cbc7e774560d98c0811e3fc41ef27521d7b763473731e663c3b5
    actual digest: 8946f4dc4ab8cbc7e774560d98c0811e3fc41ef27521d7b763473731e663c3b5
    digest match:  True
  AOSP tail [0x23bcfc0..0x23bd000]:
    hex: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    ascii: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

Before

digest match: False

$ ./examine_avb.py magisk_patched-30700_iuojB.img

=== magisk_patched-30700_iuojB.img ===
  file_size:       0x6000000 (100663296)
  orig_size:       0x2396000
  vbmeta_offset:   0x2396000
  vbmeta_size:     0x2c0
  gap:             0x0 (0)
  vbmeta flags:    0x00000000  (none)
  algorithm:       0
  release_string:  'avbtool 1.3.0'
  descriptors at:  [0x2396100..0x23962a8]
  HASH descriptor:
    partition:     'boot'
    image_size:    0x2396000
    hash_algo:     'sha256'
    flags:         0x00000000
    salt:          a7a8220ea5d051979b4e8baa35fdabfb6e150d16e1b73b5f4cbb707f7f8c7980
    digest:        8946f4dc4ab8cbc7e774560d98c0811e3fc41ef27521d7b763473731e663c3b5
    actual digest: c571809a1591b1008e9e95170a985e61a4bd9ffd604d25bbdbab32869efc94ec
    digest match:  False
  AOSP tail [0x2395fc0..0x2396000]:
    hex: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    ascii: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

After

digest match: True

$ ./examine_avb.py magisk_patched-30700_iNrlO.img 

=== magisk_patched-30700_iNrlO.img ===
  file_size:       0x6000000 (100663296)
  orig_size:       0x2396000
  vbmeta_offset:   0x2396000
  vbmeta_size:     0x2c0
  gap:             0x0 (0)
  vbmeta flags:    0x00000000  (none)
  algorithm:       0
  release_string:  'avbtool 1.3.0'
  descriptors at:  [0x2396100..0x23962a8]
  HASH descriptor:
    partition:     'boot'
    image_size:    0x2396000
    hash_algo:     'sha256'
    flags:         0x00000000
    salt:          a7a8220ea5d051979b4e8baa35fdabfb6e150d16e1b73b5f4cbb707f7f8c7980
    digest:        ccbd7bb4f4aacec80109f9e96edb45c8f15d556891cd45d00e1e04ce7d3d116a
    actual digest: ccbd7bb4f4aacec80109f9e96edb45c8f15d556891cd45d00e1e04ce7d3d116a
    digest match:  True
  AOSP tail [0x2395fc0..0x2396000]:
    hex: 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
    ascii: b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

@kousu
kousu force-pushed the repack-avb-header branch from 5922503 to 2c11dd4 Compare April 27, 2026 08:08
kousu and others added 2 commits April 27, 2026 21:51
Fixes topjohnwu#8389

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This follows topjohnwu#9830
by recomputing the AVB hash.

Apparently few (no?) devices actually respect this hash in
the wild at the moment, but it's good to be prepared.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kousu
kousu force-pushed the repack-avb-header branch from 2c11dd4 to c736c8b Compare April 28, 2026 01:56
@osm0sis

osm0sis commented May 3, 2026

Copy link
Copy Markdown
Collaborator

I might be mistaken since it's been awhile, but IIRC part of the reason the headers/footers were hacked and not updated was to appear (at least in passing) as though the partition was unmodified. Perhaps that's proven pointless now though, given the recent issue your other PR fixed, but thought I'd mention it.

@kousu

kousu commented May 3, 2026

Copy link
Copy Markdown
Author

No, really, thank you for mentioning that. This works on my phone but I am very aware that bootloaders are touchy and this could backfire on other devices. If there is experience from live devices that should trump the written specs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants