Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1 | From ea1a9ec5f430359720d9a0621ed1acfbba6a142a Mon Sep 17 00:00:00 2001 |
| 2 | From: Heinrich Schuchardt <xypron.glpk@gmx.de> |
| 3 | Date: Wed, 13 Jan 2021 02:09:12 +0100 |
| 4 | Subject: [PATCH] image-fit: fit_check_format check for valid FDT |
| 5 | |
| 6 | fit_check_format() must check that the buffer contains a flattened device |
| 7 | tree before calling any device tree library functions. |
| 8 | |
| 9 | Failure to do may cause segmentation faults. |
| 10 | |
| 11 | Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> |
| 12 | |
| 13 | Upstream-Status: Backport[https://github.com/u-boot/u-boot/commit/ea1a9ec5f430359720d9a0621ed1acfbba6a142a] |
| 14 | Signed-off-by: Scott Murray <scott.murray@konsulko.com> |
| 15 | |
| 16 | --- |
| 17 | common/image-fit.c | 6 ++++++ |
| 18 | 1 file changed, 6 insertions(+) |
| 19 | |
| 20 | diff --git a/common/image-fit.c b/common/image-fit.c |
| 21 | index 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"); |