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

sbat: append NUL byte to .sbat section #412

Closed
wants to merge 1 commit into from

Conversation

xypron
Copy link
Contributor

@xypron xypron commented Sep 6, 2021

When the UEFI firmware loads the .sbat section into memory it only
intializes VirtSize bytes. Directly behind the .sbat section will be
unintialized memory with unknown content.

Shim's image file header is not available at runtime. Up to now the
.sbat section ended with LF. So it was not possible to determine the
end of the .bat section in memory.

By appending a NUL byte to the .sbat section we get a well defined
file end.

Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com

When the UEFI firmware loads the .sbat section into memory it only
intializes VirtSize bytes. Directly behind the .sbat section will be
unintialized memory with unknown content.

Shim's image file header is not available at runtime. Up to now the
.sbat section ended with LF. So it was not possible to determine the
end of the .bat section in memory.

By appending a NUL byte to the .sbat section we get a well defined
file end.

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
@xypron
Copy link
Contributor Author

xypron commented Sep 8, 2021

The check for the NUL byte was added in #404 "csv: detect end of csv file correctly"

@vathpela
Copy link
Contributor

I don't understand why we would need this? We're already padding it before parsing the section, at https://github.com/rhboot/shim/blob/main/pe.c#L843 :

	sbat_size = SBATSize + 1;
	sbat_data = AllocatePool(sbat_size);
	if (!sbat_data) {
		console_print(L"Failed to allocate .sbat section buffer\n");
		return EFI_OUT_OF_RESOURCES;
	}
	CopyMem(sbat_data, SBATBase, SBATSize);
	sbat_data[SBATSize] = '\0';

	efi_status = parse_sbat_section(sbat_data, sbat_size, &n, &entries);

@xypron
Copy link
Contributor Author

xypron commented Sep 10, 2021

@vathpela:
Thanks for pointing me to the code section.

It seems I misplaced _esbat in my elf_riscv64_efi.lds.

@xypron xypron closed this Sep 10, 2021
@xypron xypron deleted the sbat_append_0x00 branch December 3, 2021 17:34
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.

2 participants