[PATCH 1/1] image-fit: fit_check_format check for valid FDT

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH 1/1] image-fit: fit_check_format check for valid FDT

Heinrich Schuchardt
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 <[hidden email]>
---
 common/image-fit.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/common/image-fit.c b/common/image-fit.c
index 6a8787ca0a..21c44bdf69 100644
--- a/common/image-fit.c
+++ b/common/image-fit.c
@@ -1553,6 +1553,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");
--
2.29.2

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH 1/1] image-fit: fit_check_format check for valid FDT

Simon Glass-3
On Tue, 12 Jan 2021 at 18:36, Heinrich Schuchardt <[hidden email]> wrote:

>
> 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 <[hidden email]>
> ---
>  common/image-fit.c | 6 ++++++
>  1 file changed, 6 insertions(+)

Reviewed-by: Simon Glass <[hidden email]>