From 6209ce58c3711a5ccdcd080651e604ba8fd3a067 Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Tue, 23 Sep 2025 12:27:20 +0200 Subject: mkimage: fit: do not overwrite fdt_setprop return value The return code of fdt_setprop is overwritten by the one from fdt_delprop meaning we could very well have an issue when setting the property that would be ignored if the deletion of the property that comes right after passes. Let's add a separate check for each. Fixes: 4860ee9b09e0 ("mkimage: allow internalization of data-position") Signed-off-by: Quentin Schulz --- tools/fit_image.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/fit_image.c b/tools/fit_image.c index 10849733816..7e2a12aa7d0 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -793,14 +793,20 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) debug("Importing data size %x\n", len); ret = fdt_setprop(fdt, node, FIT_DATA_PROP, data, len); - ret = fdt_delprop(fdt, node, ext_data_prop); - if (ret) { debug("%s: Failed to write property: %s\n", __func__, fdt_strerror(ret)); ret = -EINVAL; goto err_munmap; } + + ret = fdt_delprop(fdt, node, ext_data_prop); + if (ret) { + debug("%s: Failed to erase property: %s\n", __func__, + fdt_strerror(ret)); + ret = -EINVAL; + goto err_munmap; + } } confs = fdt_path_offset(fdt, FIT_CONFS_PATH); -- cgit v1.2.3 From abab733fc24158f0195967e5b6fc69a0de4658a3 Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Tue, 23 Sep 2025 12:27:21 +0200 Subject: mkimage: fit: do not ignore fdt_setprop return code All explicit calls to fdt_setprop* in tools/ are checked except those three. Let's add a check for the return code of fdt_setprop_u32() calls. Signed-off-by: Quentin Schulz --- tools/fit_image.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tools/fit_image.c b/tools/fit_image.c index 7e2a12aa7d0..d026f6ff9c8 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -658,13 +658,25 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) } if (params->external_offset > 0) { /* An external offset positions the data absolutely. */ - fdt_setprop_u32(fdt, node, FIT_DATA_POSITION_PROP, - params->external_offset + buf_ptr); + ret = fdt_setprop_u32(fdt, node, FIT_DATA_POSITION_PROP, + params->external_offset + buf_ptr); } else { - fdt_setprop_u32(fdt, node, FIT_DATA_OFFSET_PROP, - buf_ptr); + ret = fdt_setprop_u32(fdt, node, FIT_DATA_OFFSET_PROP, + buf_ptr); } - fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len); + + if (ret) { + ret = -EINVAL; + goto err_munmap; + } + + ret = fdt_setprop_u32(fdt, node, FIT_DATA_SIZE_PROP, len); + + if (ret) { + ret = -EINVAL; + goto err_munmap; + } + buf_ptr += ALIGN(len, align_size); } -- cgit v1.2.3 From b3ab77345e3d1e7f40f1991e5072daf0f2d972dc Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Tue, 23 Sep 2025 12:27:22 +0200 Subject: mkimage: fit: erase data-size property when importing data When importing data, the data-offset property is removed and the data content is imported inside the data property of the node. When mkimage is run twice on the same FIT, data-size property is already set in the second run, from the first run (via the fit_export_data function). If we don't remove the data-size property, nothing guarantees it matches the actual size of data within the data property. To avoid possible mistakes when handling the data property, let's simply remove the data-size property as well. This also fixes an ordering issue of the data-size and data-offset properties in FIT when comparing the FIT after one run of mkimage and a second run. This is due to fit_export_data setting data-offset property first (it doesn't exist so it's added) and then data-size (it doesn't exist so it's added) for the first run, while it sets data-offset property first (removed in fit_import_data, so it doesn't exist so it's added) and then data-size (it exists already from the first run, so it's simply modified) for the second run. Signed-off-by: Quentin Schulz --- tools/fit_image.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/fit_image.c b/tools/fit_image.c index d026f6ff9c8..0306333141e 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -819,6 +819,14 @@ static int fit_import_data(struct image_tool_params *params, const char *fname) ret = -EINVAL; goto err_munmap; } + + ret = fdt_delprop(fdt, node, FIT_DATA_SIZE_PROP); + if (ret) { + debug("%s: Failed to erase %s property: %s\n", __func__, + FIT_DATA_SIZE_PROP, fdt_strerror(ret)); + ret = -EINVAL; + goto err_munmap; + } } confs = fdt_path_offset(fdt, FIT_CONFS_PATH); -- cgit v1.2.3