protos/multiboot2: Validate section_entry_size against expected struct size
diff --git a/common/protos/multiboot2.c b/common/protos/multiboot2.c
index a8e84fa8..23c56a98 100644
--- a/common/protos/multiboot2.c
+++ b/common/protos/multiboot2.c
@@ -521,6 +521,11 @@ reloc_fail:
int bits = elf_bits(kernel);
+ if ((bits == 64 && section_hdr_info.section_entry_size < sizeof(struct elf64_shdr)) ||
+ (bits == 32 && section_hdr_info.section_entry_size < sizeof(struct elf32_shdr))) {
+ panic(true, "multiboot2: ELF section entry size too small");
+ }
+
for (size_t i = 0; i < section_hdr_info.num; i++) {
if (bits == 64) {
struct elf64_shdr *shdr = (void *)tag->sections + i * section_hdr_info.section_entry_size;
