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
-Wmissing-braces in drivers/firmware/efi/libstub/efi-stub-helper.c #1547
Comments
It's unclear to me. The standard does mention initializing an array of unknown size in an aggregate, but doesn't appear explicit whether it should be surrounded by braces. I could see a case for both. This is something a language lawyer needs to comment on. |
Oddly enough, I don't even see where It seems like the diff --git a/drivers/firmware/efi/libstub/efi-stub-helper.c b/drivers/firmware/efi/libstub/efi-stub-helper.c
index 0bd01da1f0df..b91679817725 100644
--- a/drivers/firmware/efi/libstub/efi-stub-helper.c
+++ b/drivers/firmware/efi/libstub/efi-stub-helper.c
@@ -628,7 +628,7 @@ efi_status_t efi_load_initrd_cmdline(efi_loaded_image_t *image,
static const struct {
efi_tcg2_event_t event_data;
efi_tcg2_tagged_event_t tagged_event;
- u8 tagged_event_data[];
+ u8 *tagged_event_data;
} initrd_tcg2_event = {
{
sizeof(initrd_tcg2_event) + sizeof("Linux initrd"), breaks the build with both compilers (GCC below):
cc @ardbiesheuvel, would you be opposed to a patch adding the braces like in my comment above? |
I don't mind adding the braces if GCC and Clang both accept it. I just don't see why initializing a char[] using a string literal suddenly needs an additional set of braces when the char[] is a member of a compound type. As for the u8[] to u8* change: this is obviously incorrect. This struct is defined in the TCG PC client spec, and constitutes a API contract between the EFI stub and the firmware, so we cannot change that. |
GCC does not warn with or without braces, clang warns without: https://godbolt.org/z/3YcP5sbKq All of GCC's documentation and nearly all of clang's tests show braces around the initializer so it seems like that is what should be happening; it looks like not having braces is probably an undocumented GCC extension. I do see one commit in the history that changes how clang handles flexible array initialization to explicitly match GCC but the change notes that there will still be a warning in these cases so it does not sound like If I am reading it right, section 6.7.2.1 of the C standard does cover initialization of flexible member arrays but it seems like they are not allowed in the way; reading the GCC docs, it seems like this is an extension so I guess we have to go on what GCC allows. |
@jrtc27 mentioned on IRC:
|
I've fixed this up in the original patch. Should appear in -next tomorrow. |
Thanks a lot Ard! |
In an effort to ensure the initrd observed and used by the OS is the same one that was meant to be loaded, which is difficult to guarantee otherwise, let's measure the initrd if the EFI stub and specifically the newly introduced LOAD_FILE2 protocol was used. Modify the initrd loading sequence so that the contents of the initrd are measured into PCR9. Note that the patch is currently using EV_EVENT_TAG to create the eventlog entry instead of EV_IPL. According to the TCP PC Client specification this is used for PCRs defined for OS and application usage. Co-developed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Link: https://lore.kernel.org/r/20211119114745.1560453-5-ilias.apalodimas@linaro.org [ardb: add braces to initializer of tagged_event_data] Link: ClangBuiltLinux/linux#1547 Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Now fixed in -next. |
In an effort to ensure the initrd observed and used by the OS is the same one that was meant to be loaded, which is difficult to guarantee otherwise, let's measure the initrd if the EFI stub and specifically the newly introduced LOAD_FILE2 protocol was used. Modify the initrd loading sequence so that the contents of the initrd are measured into PCR9. Note that the patch is currently using EV_EVENT_TAG to create the eventlog entry instead of EV_IPL. According to the TCP PC Client specification this is used for PCRs defined for OS and application usage. Co-developed-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Signed-off-by: Ilias Apalodimas <ilias.apalodimas@linaro.org> Link: https://lore.kernel.org/r/20211119114745.1560453-5-ilias.apalodimas@linaro.org [ardb: add braces to initializer of tagged_event_data] Link: ClangBuiltLinux#1547 Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
After commit 2e5006b7634f ("efi/libstub: measure loaded initrd info into the TPM") in -next:
The full variable:
Is
clang
getting something wrong here? GCC accepts the current form without any warnings. The suggestion resolves it but I want to make sure something is not getting missed here.The text was updated successfully, but these errors were encountered: