linux/drivers/firmware/efi/libstub/zboot.lds
Vitaly Kuznetsov f8b53cc917 efi: Fix .data section size calculations when .sbat is present
Commit 0f9a1739dd ("efi: zboot specific mechanism for embedding SBAT
section") neglected to adjust the sizes of the .data section when
CONFIG_EFI_SBAT_FILE is set. As the result, the produced PE binary is
incorrect and some tools complain about it. E.g. 'sbsign' reports:

 # sbsign --key my.key --cert my.crt arch/arm64/boot/vmlinuz.efi
 warning: file-aligned section .data extends beyond end of file
 warning: checksum areas are greater than image size. Invalid section table?

Note, '__data_size' is also used in the PE optional header and it is not
entirely clear whether .sbat needs to be accounted as part of
SizeOfInitializedData or not. As the header seems to be unused by the real
world firmware, keeping the field equal to __data_size.

Fixes: 0f9a1739dd ("efi: zboot specific mechanism for embedding SBAT section")
Reported-by: Heinrich Schuchardt <heinrich.schuchardt@gmx.de>
Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2025-06-20 13:36:14 +02:00

63 lines
1 KiB
Text

/* SPDX-License-Identifier: GPL-2.0 */
ENTRY(__efistub_efi_zboot_header);
PROVIDE(zboot_code_size = ABSOLUTE(0));
SECTIONS
{
.head : ALIGN(4096) {
*(.head)
}
.text : {
*(.text* .init.text*)
}
.rodata : ALIGN(8) {
__efistub__gzdata_start = .;
*(.gzdata)
__efistub_payload_size = . - 4;
__efistub__gzdata_end = .;
*(.rodata* .init.rodata* .srodata*)
. = ALIGN(4);
__efistub_code_size = .;
LONG(zboot_code_size);
_etext = ALIGN(4096);
. = _etext;
}
.sbat : ALIGN(4096) {
_sbat = .;
*(.sbat)
_esbat = ALIGN(4096);
. = _esbat;
}
.data : ALIGN(4096) {
_data = .;
*(.data* .init.data*)
_edata = ALIGN(512);
. = _edata;
}
.bss : {
*(.bss* .init.bss*)
_end = ALIGN(512);
. = _end;
}
/DISCARD/ : {
*(.discard .discard.*)
*(.modinfo .init.modinfo)
}
}
PROVIDE(__efistub__gzdata_size =
ABSOLUTE(__efistub__gzdata_end - __efistub__gzdata_start));
PROVIDE(__data_rawsize = ABSOLUTE(_edata - _data));
PROVIDE(__data_size = ABSOLUTE(_end - _data));
PROVIDE(__sbat_size = ABSOLUTE(_esbat - _sbat));