Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using the zerocopy crate for all parsers #384

Merged
merged 11 commits into from
Dec 1, 2024
Merged

Conversation

chenxiaolong
Copy link
Owner

All parsers now read and write headers as entire structs (safely) via the zerocopy crate instead of reading/writing them field-by-field.

This PR also fixes a bug in how the AVB/vbmeta parser handled the release_string field. The field is 48 bytes in length, but the string must be NULL terminated. When writing the AVB header, a 48-byte string was accepted as valid and left not-NULL-terminated, instead of failing.

In practice, the security concern is extremely minimal. avbroot preserves the original release_string, which is always avbtool 1.2.0 or avbtool 1.3.0 for AVB headers created by AOSP's avbtool (it is hardcoded). However, even if it the AVB headers had a 48-byte string, any bootloader that's based on AOSP's reference libavb implementation will not perform an out-of-bounds read because it checks that the last byte is 0. (And even if it doesn't, the 80 reserved bytes that immediately follow release_string are almost certainly filled with zeros.)

Finally, the FEC parser was extended so that it can parse FEC images with unknown extra custom fields.

>=0.8.10 is needed for the new read_from_io()/write_to_io() helper
functions.

Signed-off-by: Andrew Gunnerson <[email protected]>
This commit also adds support for parsing FEC images with unknown extra
custom fields.

Signed-off-by: Andrew Gunnerson <[email protected]>
Signed-off-by: Andrew Gunnerson <[email protected]>
Signed-off-by: Andrew Gunnerson <[email protected]>
Signed-off-by: Andrew Gunnerson <[email protected]>
This commit also fixes a bug where avb::Header::release_string was
allowed to take the full 48-bytes, which was incorrect because libavb
expects the field to be NULL-terminated. This was not a problem in
practice because the release string is usually short and even if it
wasn't, the 80 reserved bytes that immediately follow it are all zeros.

Signed-off-by: Andrew Gunnerson <[email protected]>
Signed-off-by: Andrew Gunnerson <[email protected]>
Signed-off-by: Andrew Gunnerson <[email protected]>
chenxiaolong added a commit that referenced this pull request Dec 1, 2024
Signed-off-by: Andrew Gunnerson <[email protected]>
@chenxiaolong chenxiaolong merged commit 5c353a5 into master Dec 1, 2024
5 checks passed
@chenxiaolong chenxiaolong deleted the zerocopy branch December 1, 2024 22:27
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.

1 participant