]> git.ipfire.org Git - thirdparty/grub.git/commit
util/grub-module-verifierXX: Validate number of elf section header table entries
authorAlec Brown <alec.r.brown@oracle.com>
Thu, 3 Feb 2022 00:26:58 +0000 (19:26 -0500)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 8 Feb 2022 15:06:50 +0000 (16:06 +0100)
commitcdb21e0b9cbbde8f60e481f245092c7d61f90905
tree391e7d33de514bdcbc38b8e9f42526d3c5d72a38
parente92633850c99983070bd15f98b53c4c11525f7e0
util/grub-module-verifierXX: Validate number of elf section header table entries

In grub-module-verifierXX.c, grub_target_to_host16 (e->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), e_shnum holds the value zero and the real number of
entries in the section header table is held in the sh_size member of the intial
entry in section header table. Otherwise, the sh_size member of the initial
entry in the section header table holds the value zero."

Since this check wasn't being made, the function get_shnum() is being added to
make this check and use whichever member doesn't have a value of zero. If both
are zero, then we must return an error. We also need to make sure that e_shnum
doesn't have a value greater than or equal to SHN_LORESERVE and sh_size isn't
less than SHN_LORESERVE.

Note that it may look as though the argument *arch isn't being used, it's
actually required in order to use the macros grub_target_to_host*(x) which are
unwinded to grub_target_to_host*_real(arch, (x)) based on defines earlier in
the file.

Fixes: CID 314021
Fixes: CID 314027
Fixes: CID 314033
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
util/grub-module-verifierXX.c