blob: d4ac9e2ed99f5624e5977d7bc9cece9c2f55be9a [file] [log] [blame]
Andrew Geissler95ac1b82021-03-31 14:34:31 -05001From ea1a9ec5f430359720d9a0621ed1acfbba6a142a Mon Sep 17 00:00:00 2001
2From: Heinrich Schuchardt <xypron.glpk@gmx.de>
3Date: Wed, 13 Jan 2021 02:09:12 +0100
4Subject: [PATCH] image-fit: fit_check_format check for valid FDT
5
6fit_check_format() must check that the buffer contains a flattened device
7tree before calling any device tree library functions.
8
9Failure to do may cause segmentation faults.
10
11Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
12
13Upstream-Status: Backport[https://github.com/u-boot/u-boot/commit/ea1a9ec5f430359720d9a0621ed1acfbba6a142a]
14Signed-off-by: Scott Murray <scott.murray@konsulko.com>
15
16---
17 common/image-fit.c | 6 ++++++
18 1 file changed, 6 insertions(+)
19
20diff --git a/common/image-fit.c b/common/image-fit.c
21index 6a8787ca0a..21c44bdf69 100644
22--- a/common/image-fit.c
23+++ b/common/image-fit.c
24@@ -1553,6 +1553,12 @@ int fit_image_check_comp(const void *fit, int noffset, uint8_t comp)
25 */
26 int fit_check_format(const void *fit)
27 {
28+ /* A FIT image must be a valid FDT */
29+ if (fdt_check_header(fit)) {
30+ debug("Wrong FIT format: not a flattened device tree\n");
31+ return 0;
32+ }
33+
34 /* mandatory / node 'description' property */
35 if (fdt_getprop(fit, 0, FIT_DESC_PROP, NULL) == NULL) {
36 debug("Wrong FIT format: no description\n");