rhboot / shim

UEFI shim loader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Second-stage's loaded image `ImageSize` is wrong on IA32

nicholasbishop opened this issue · comments

In pe.c, it sets the ImageBase and ImageSize in EFI_LOADED_IMAGE for the second stage: https://github.com/rhboot/shim/blob/main/pe.c#L1394

On the IA32 target, this doesn't work properly because the ImageSize field is not correctly aligned. ImageSize is a UINT64. Fields are supposed to be "naturally aligned". Naturally the spec doesn't bother to specify exactly what "naturally aligned" means, but other toolchains such as EDK2 seem to think it means a UINT64 should be 8-byte aligned.

In other words, offsetof(EFI_LOADED_IMAGE, ImageSize) on IA32 is 40 in EDK2, but 36 in shim due to the missing padding.

I think a straightforward fix would be to add -malign-double on IA32 (as EDK2 does), which will align "double, long double, and long long variables on a two-word boundary".