mtk-openwrt / arm-trusted-firmware

Read-only mirror of Trusted Firmware-A
https://developer.trustedfirmware.org/dashboard/view/6/
Other
22 stars 20 forks source link

partition: fix unaligned access in load_mbr_header() #9

Open arachsys opened 3 months ago

arachsys commented 3 months ago

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 https://github.com/mtk-openwrt/arm-trusted-firmware/issues/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.

arachsys commented 2 months ago

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

https://github.com/ARM-software/arm-trusted-firmware/commit/21a77e08921a13ac4adc523a136d829333a854f1