grub-mkimage: Add SBAT metadata check
PATCH 1/1 grub-mkimage: Add SBAT metadata check
The grub-mkimage does not check if the SBAT metadata file is empty or not when creating core image 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 before adding it to the ELF note or .sbat section.
--- util/mkimage.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
util/mkimage.c +7 -2
@@ -963,6 +963,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) +grub_util_error (_ ("%s file does not contains SBAT metadata" ), 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 +1402,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 +1863,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 15 lines · Sudhakar Kuppusamy
The grub-mkimage does not check if the SBAT metadata file is empty or not when creating core image 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 before adding it to the ELF note or .sbat section.
Signed-off-by Sudhakar Kuppusamy <[email protected]>--- util/mkimage.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)util/mkimage.c +0
-0
util/mkimage.c grub_install_generate_image (const char *dir, const char *prefix, · line 969
Quoted 7 lines
util/mkimage.c +4
-0@@ -963,6 +963,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)
I think it is not fully correct. SBAT should contain at least header.
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 21 lines · Daniel Kiper
Quoted 16 lines · Sudhakar Kuppusamy
The grub-mkimage does not check if the SBAT metadata file is empty or not when creating core image 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 before adding it to the ELF note or .sbat section.
Signed-off-by Sudhakar Kuppusamy <[email protected]>---
util/mkimage.c| 9 +++++++--1 file changed, 7 insertions(+), 2 deletions(-)util/mkimage.c +0
-0@@ -963,6 +963,12 @@ grub_install_generate_image (const char *dir, const char *prefix,
Quoted 8 lines
util/mkimage.c grub_install_generate_image (const char *dir, const char *prefix, · line 969
Quoted 6 lines
util/mkimage.c +4
-0if (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)I think it is not fully correct. SBAT should contain at least header.
Yes, you are correct.
Thank you Daniel. I will correct it on v1
Thanks,
Sudhakar
Quoted 2 lines
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel