[PATCH v2 1/5] elf: Validate number of elf section header table entries

2022-08-12 Thread Alec Brown
In bsdXX.c and multiboot_elfxx.c, e_shnum is used to obtain the number of section header table entries, but it wasn't being checked if the value was there. According to the elf(5) manual page, "If the number of entries in the section header table is larger than or equal to SHN_LORESERVE (0xff00),

[PATCH v2 3/5] elf: Validate number of elf program header table entries

2022-08-12 Thread Alec Brown
In bsdXX.c and multiboot_elfxx.c, e_phnum is used to obtain the number of program header table entries, but it wasn't being checked if the value was there. According to the elf(5) manual page, "If the number of entries in the program header table is larger than or equal to PN_XNUM (0x), this m

[PATCH v2 4/5] util/grub-module-verifierXX.c: Changed get_shnum() return type

2022-08-12 Thread Alec Brown
In util/grub-module-verifierXX.c, the function get_shnum() returns the variable shnum, which is of the type Elf_Word. In the function, shnum can be obtained by the e_shnum member of an Elf_Ehdr or the sh_size member of an Elf_Shdr. The sh_size member can either be grub_uint32_t or grub_uint64_t, de

[PATCH v2 0/5] Fix coverity bugs and add checks for elf values in grub-core

2022-08-12 Thread Alec Brown
Updates from v1: - A few patches didn't work on 32-bit platforms. Fixed this by renaming function definitions in multiboot_elfxx.c. The patches that did work were merged with the master branch. - Added a patch to make error conditionals consistent in comparing to

[PATCH v2 2/5] elf: Validate elf section header table index for section name string table

2022-08-12 Thread Alec Brown
In multiboot_elfxx.c, e_shstrndx is used to obtain the section header table index of the section name string table, but it wasn't being checked if the value was there. According to the elf(5) manual page, "If the index of section name string table section is larger than or equal to SHN_LORESERVE (

[PATCH v2 5/5] loader: Update error conditionals to use enums

2022-08-12 Thread Alec Brown
In grub-core/loader/i386/bsdXX.c and grub-core/loader/multiboot_elfxx.c, error conditionals are simplified to statements such as "if (err)". Even though the assumption that non-zero values give errors is correct, it would be clearer and more consistent to compare these conditionals to GRUB_ERR_NONE