diff mbox series

[u-boot,v2019.04-aspeed-openbmc,7/7] image-fit: fit_check_format check for valid FDT

Message ID 20210128105304.401058-8-joel@jms.id.au
State New
Headers show
Series Blackport SHA512 for FIT | expand

Commit Message

Joel Stanley Jan. 28, 2021, 10:53 a.m. UTC
From: Heinrich Schuchardt <xypron.glpk@gmx.de>

fit_check_format() must check that the buffer contains a flattened device
tree before calling any device tree library functions.

Failure to do may cause segmentation faults.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
(cherry picked from commit ea1a9ec5f430359720d9a0621ed1acfbba6a142a)
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 common/image-fit.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Klaus Heinrich Kiwi Jan. 28, 2021, 7:52 p.m. UTC | #1
On 1/28/2021 7:53 AM, Joel Stanley wrote:
> From: Heinrich Schuchardt <xypron.glpk@gmx.de>
> 
> fit_check_format() must check that the buffer contains a flattened device
> tree before calling any device tree library functions.
> 
> Failure to do may cause segmentation faults.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> (cherry picked from commit ea1a9ec5f430359720d9a0621ed1acfbba6a142a)
> Signed-off-by: Joel Stanley <joel@jms.id.au>

Reviewed-by: Klaus Heinrich Kiwi <klaus@linux.vnet.ibm.com>
diff mbox series

Patch

diff --git a/common/image-fit.c b/common/image-fit.c
index be4d9dc9c3b1..e64949dfa73d 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1473,6 +1473,12 @@  int fit_image_check_comp(const void *fit, int noffset, uint8_t comp)
  */
 int fit_check_format(const void *fit)
 {
+	/* A FIT image must be a valid FDT */
+	if (fdt_check_header(fit)) {
+		debug("Wrong FIT format: not a flattened device tree\n");
+		return 0;
+	}
+
 	/* mandatory / node 'description' property */
 	if (fdt_getprop(fit, 0, FIT_DESC_PROP, NULL) == NULL) {
 		debug("Wrong FIT format: no description\n");