Skip to content

shim fails to load mokmanager image with error "2 sections contain entry point" #517

@iokomin

Description

@iokomin

Seen mokmanager image load failure "2 sections contain entry point" for shim built on Oracle Linux 9 aarch64:

pe.c:574:generate_hash() 00000010  08 56 85 05 fa 24 3b 9f  9f f0 51 ed 20 fc c6 fc  |.V...$;...Q. ...|
pe.c:1192:handle_image() Loading 0xC3000 bytes at 0x238237000
2 sections contain entry point
Failed to load image: Unsupported

Root cause of this failure is supposedly incorrect entry points detection.
In pe.c:handle_image() found_entry_point counter uses SizeOfRawData to calculate image section boundary:

shim/pe.c

Lines 1261 to 1264 in 5c537b3

if (Section->VirtualAddress <= context.EntryPoint &&
(Section->VirtualAddress + Section->SizeOfRawData - 1)
> context.EntryPoint)
found_entry_point++;

According to PE spec:

VirtualSize
The total size of the section when loaded into memory. If this value is greater than SizeOfRawData, 
the section is zero-padded. This field is valid only for executable images and should be set to zero for object files.

SizeOfRawData
The size of the section (for object files) or the size of the initialized data on disk (for image files). For executable 
images, this must be a multiple of FileAlignment from the optional header. If this is less than VirtualSize, the remainder 
of the section is zero-filled. Because the SizeOfRawData field is rounded but the VirtualSize field is not, it is possible
for SizeOfRawData to be greater than VirtualSize as well. When a section contains only uninitialized data, this field should be zero. 

Proposed replacing Section->SizeOfRawData to Section->Misc.VirtualSize as it should define actual size of the section loaded in memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions