device_tree: Add version checks

This patch adds a few more sanity checks to the FDT header parsing to
make sure that our code can support the version that is passed in.

This patch was adapted from depthcharge's http://crosreview.com/1536384

Change-Id: I06c112f540213c8db7c2455c2e8a4e8e4f337b78
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/32862
Reviewed-by: Hung-Te Lin <hungte@chromium.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Julius Werner
2019-05-03 17:58:07 -07:00
committed by Patrick Georgi
parent 9636a106d4
commit 73eaec8168
3 changed files with 23 additions and 6 deletions

View File

@@ -423,19 +423,17 @@ static void fit_update_compat(const void *fdt_blob,
struct fit_config_node *fit_load(void *fit)
{
struct fdt_header *header = (struct fdt_header *)fit;
struct fit_image_node *image;
struct fit_config_node *config;
struct compat_string_entry *compat_node;
printk(BIOS_DEBUG, "FIT: Loading FIT from %p\n", fit);
if (be32toh(header->magic) != FDT_HEADER_MAGIC) {
printk(BIOS_ERR, "FIT: Bad header magic value 0x%08x.\n",
be32toh(header->magic));
struct device_tree *tree = fdt_unflatten(fit);
if (!tree) {
printk(BIOS_ERR, "ERROR: Failed to unflatten FIT image!\n");
return NULL;
}
struct device_tree *tree = fdt_unflatten(fit);
const char *default_config_name = NULL;
struct fit_config_node *default_config = NULL;