coreboot-kgpe-d16/payloads/libpayload/libcbfs
Alex Rebert e5e24107f9 libpayload: cbfs: fix infinite loop in cbfs_get_{handle,attr}
cbfs_get_handle() and cbfs_get_attr() are both looping over elements to
find a particular one. Each element header contains the element's
length, which is used to compute the next element's offset. Invalid or
corrupted CBFS files could lead to infinite loops where the offset would
remain constant across iterations, due to 0-length elements or integer
overflows in the computation of the next offset.

This patch makes both functions more robust by adding a check that
ensure offsets are strictly monotonic. Instead of infinite looping, the
functions are now printing an ERROR and returning a NULL value.

Change-Id: I440e82fa969b8c2aacc5800e7e26450c3b97c74a
Signed-off-by: Alex Rebert <alexandre.rebert@gmail.com>
Found-by: Mayhem
Reviewed-on: https://review.coreboot.org/c/coreboot/+/39177
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
2020-03-02 15:00:24 +00:00
..
Makefile.inc Remove empty lines at end of file 2015-06-08 00:55:07 +02:00
cbfs.c printf: Automatically prefix %p with 0x 2019-12-11 11:38:59 +00:00
cbfs_core.c libpayload: cbfs: fix infinite loop in cbfs_get_{handle,attr} 2020-03-02 15:00:24 +00:00
ram_media.c libpayload: cbfs: Fix ram_media map() error return value 2015-03-21 11:04:39 +01:00