grub-mkimage: Fix empty SBAT metadata file issue
PATCH v2 1/1 grub-mkimage: Fix empty SBAT metadata file issue
The grub-mkimage does not check if the SBAT metadata file is contains at least the SBAT header or not when creating core.elf with the SBAT metadata file. It leads to adding the empty SBAT ELF note for PowerPC and the .sbat section for EFI. Fixing this by checking the SBAT metadata file size against the SBAT header size before adding it to the ELF note or .sbat section.
--- util/mkimage.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
util/mkimage.c +10 -2
@@ -56,6 +56,9 @@#pragma GCC diagnostic ignored "-Wcast-align" +#define SBAT_HEADER "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md" +#define SBAT_HEADER_SIZE (sizeof(SBAT_HEADER)) +#define TARGET_NO_FIELD 0xffffffff/* use 2015-01-01T00:00:00+0000 as a stock timestamp */
@@ -963,6 +966,12 @@ grub_install_generate_image (const char *dir, const char *prefix,if (sbat_path !=NULL && (image_target->id !=IMAGE_EFI && image_target->id !=IMAGE_PPC ))grub_util_error (_ ("SBAT data can be added only to EFI or powerpc-ieee1275 images" )); +else if (sbat_path !=NULL ) + { + sbat_size =grub_util_get_image_size (sbat_path); +if (sbat_size <SBAT_HEADER_SIZE ) +grub_util_error (_ ("%s file should contain at least an SBAT header" ), sbat_path); + }if (appsig_size !=0 && image_target->id !=IMAGE_PPC )grub_util_error (_ ("appended signature can be support only to powerpc-ieee1275 images" ));
@@ -1396,7 +1405,7 @@ grub_install_generate_image (const char *dir, const char *prefix,if (sbat_path !=NULL ) { - sbat_size =ALIGN_ADDR (grub_util_get_image_size (sbat_path)); + sbat_size =ALIGN_ADDR (sbat_size); sbat_size =ALIGN_UP (sbat_size,GRUB_PE32_FILE_ALIGNMENT ); }
@@ -1857,7 +1866,6 @@ grub_install_generate_image (const char *dir, const char *prefix,char *sbat =NULL ;if (sbat_path !=NULL ) { - sbat_size =grub_util_get_image_size (sbat_path); sbat =xmalloc (sbat_size);grub_util_load_image (sbat_path, sbat); layout.sbat_size = sbat_size;
Signature · 7 lines
2.50.1 (Apple Git-155) _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 16 lines · Sudhakar Kuppusamy
The grub-mkimage does not check if the SBAT metadata file is contains at least the SBAT header or not when creating core.elf with the SBAT metadata file. It leads to adding the empty SBAT ELF note for PowerPC and the .sbat section for EFI. Fixing this by checking the SBAT metadata file size against the SBAT header size before adding it to the ELF note or .sbat section.
Signed-off-by Sudhakar Kuppusamy <[email protected]>--- util/mkimage.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)util/mkimage.c +0
-0
util/mkimage.c line 59
Quoted 4 lines
util/mkimage.c +1
-0@@ -56,6 +56,9 @@#pragma GCC diagnostic ignored "-Wcast-align" +#define SBAT_HEADER "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md"
You copy an example which is different from real SBAT. Please take a look at real file and update the line accordingly.
util/mkimage.c line 60
Quoted 1 line
util/mkimage.c +1
-0+#define SBAT_HEADER_SIZE (sizeof(SBAT_HEADER))
Missing space after "sizeof".
Otherwise patch LGTM...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Daniel Kiper
Reviewed-byQuoted 18 lines · Daniel Kiper
Quoted 17 lines · Sudhakar Kuppusamy
The grub-mkimage does not check if the SBAT metadata file is contains at least the SBAT header or not when creating core.elf with the SBAT metadata file. It leads to adding the empty SBAT ELF note for PowerPC and the .sbat section for EFI. Fixing this by checking the SBAT metadata file size against the SBAT header size before adding it to the ELF note or .sbat section.
Signed-off-by Sudhakar Kuppusamy <[email protected]>--- util/mkimage.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)util/mkimage.c +0
-0@@ -56,6 +56,9 @@
Quoted 6 lines
util/mkimage.c line 59
Quoted 3 lines
util/mkimage.c +1
-0#pragma GCC diagnostic ignored "-Wcast-align" +#define SBAT_HEADER "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md"You copy an example which is different from real SBAT. Please take a look at real file and update the line accordingly.
Ugh! It looks that I have wrongly remembered real usage or mixed up different things somehow. Sorry for the noise...
Quoted 3 lines
util/mkimage.c line 60
Quoted 1 line
util/mkimage.c +1
-0+#define SBAT_HEADER_SIZE (sizeof(SBAT_HEADER))Missing space after "sizeof".
I will fix this for you.
Quoted 1 line
Otherwise patch LGTM...
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel