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

partition: fix unaligned access in load_mbr_header() #9

Open
wants to merge 1 commit into
base: mtksoc
Choose a base branch
from

Conversation

arachsys
Copy link

@arachsys arachsys commented Jun 7, 2024

load_mbr_header() casts an unaligned pointer to (mbr_entry_t *) then dereferences struct members with non-trivial alignment requirements.

This causes a bl2 with BOOT_DEVICE=emmc to hang when compiled with clang 18.1.5, although it works when compiled with gcc 14.1.0, as described in #8. Presumably gcc's -mstrict-align papers over the undefined behaviour whereas clang's doesn't.

Replace the unaligned cast with a safe memcpy() into an mbr_entry_t.

load_mbr_header() casts an unaligned pointer to (mbr_entry_t *) then
dereferences struct members with non-trivial alignment requirements.

This causes a bl2 with BOOT_DEVICE=emmc to hang when compiled with clang
18.1.5, although it works when compiled with gcc 14.1.0. Presumably gcc's
-mstrict-align papers over the undefined behaviour whereas clang's doesn't.

Replace the unaligned cast with a safe memcpy() into an mbr_entry_t.

Signed-off-by: Chris Webb <chris@arachsys.com>
@arachsys
Copy link
Author

arachsys commented Jul 5, 2024

This bugfix has now also landed in upstream ARM trusted-firmware-a:

ARM-software@21a77e0

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