Skip to content

Commit f94eae0

Browse files
SudhakarKuppusamy1Daniel Kiper
authored andcommitted
grub-mkimage: Do not generate empty SBAT metadata
When creating core.elf with SBAT the grub-mkimage does not check if an SBAT metadata file contains at least an SBAT header or not. It leads to adding an empty SBAT ELF note for PowerPC and the .sbat section for EFI. Fix this by checking the SBAT metadata file size against the SBAT header size before adding SBAT contents to the ELF note or .sbat section. Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
1 parent 1aa0dd0 commit f94eae0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

util/mkimage.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656

5757
#pragma GCC diagnostic ignored "-Wcast-align"
5858

59+
#define SBAT_HEADER "sbat,1,SBAT Version,sbat,1,https://github.com/rhboot/shim/blob/main/SBAT.md"
60+
#define SBAT_HEADER_SIZE (sizeof (SBAT_HEADER))
61+
5962
#define TARGET_NO_FIELD 0xffffffff
6063

6164
/* 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,
963966

964967
if (sbat_path != NULL && (image_target->id != IMAGE_EFI && image_target->id != IMAGE_PPC))
965968
grub_util_error (_("SBAT data can be added only to EFI or powerpc-ieee1275 images"));
969+
else if (sbat_path != NULL)
970+
{
971+
sbat_size = grub_util_get_image_size (sbat_path);
972+
if (sbat_size < SBAT_HEADER_SIZE)
973+
grub_util_error (_("%s file should contain at least an SBAT header"), sbat_path);
974+
}
966975

967976
if (appsig_size != 0 && image_target->id != IMAGE_PPC)
968977
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,
13961405

13971406
if (sbat_path != NULL)
13981407
{
1399-
sbat_size = ALIGN_ADDR (grub_util_get_image_size (sbat_path));
1408+
sbat_size = ALIGN_ADDR (sbat_size);
14001409
sbat_size = ALIGN_UP (sbat_size, GRUB_PE32_FILE_ALIGNMENT);
14011410
}
14021411

@@ -1857,7 +1866,6 @@ grub_install_generate_image (const char *dir, const char *prefix,
18571866
char *sbat = NULL;
18581867
if (sbat_path != NULL)
18591868
{
1860-
sbat_size = grub_util_get_image_size (sbat_path);
18611869
sbat = xmalloc (sbat_size);
18621870
grub_util_load_image (sbat_path, sbat);
18631871
layout.sbat_size = sbat_size;

0 commit comments

Comments
 (0)