From fc21a88f801c41a535397a359b3b5bdc3ef8e79f Mon Sep 17 00:00:00 2001 From: Sven Roederer Date: Mon, 27 Apr 2020 02:08:38 +0200 Subject: tools/mkimage: fix handling long filenames The cmdline for calling the dtc was cut-off when using long filenames (e.g. 245 bytes) for output-file and datafile of "-f" parameter. For FIT-images cmd[MKIMAGE_MAX_DTC_CMDLINE_LEN] is declared (hardcoded 512 bytes), and contains some static values, the path of a tmpfile and a datafile. tmpfile is max MKIMAGE_MAX_TMPFILE_LEN (256) and datafile might be also this size. Having two very long pathname results in a truncation os the executed shell command, as the truncated datafile path will not be found. Redefine MKIMAGE_MAX_DTC_CMDLINE_LEN to "2 * MKIMAGE_MAX_TMPFILE_LEN + 35 for the parameters. This likely applies to the "-d" parameter, too. Signed-off-by: Sven Roederer --- tools/mkimage.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/mkimage.h b/tools/mkimage.h index 0254af59fbe..5b096a545b7 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -42,6 +42,6 @@ static inline ulong map_to_sysmem(void *ptr) #define MKIMAGE_TMPFILE_SUFFIX ".tmp" #define MKIMAGE_MAX_TMPFILE_LEN 256 #define MKIMAGE_DEFAULT_DTC_OPTIONS "-I dts -O dtb -p 500" -#define MKIMAGE_MAX_DTC_CMDLINE_LEN 512 +#define MKIMAGE_MAX_DTC_CMDLINE_LEN 2 * MKIMAGE_MAX_TMPFILE_LEN + 35 #endif /* _MKIIMAGE_H_ */ -- cgit v1.3.1 From ea5d3731b843b14f1c48d0d0f2c7d2877ecbf673 Mon Sep 17 00:00:00 2001 From: Sven Roederer Date: Mon, 27 Apr 2020 02:08:39 +0200 Subject: tools/fit-image: print a warning when cmd-line for dtc might be truncated Signed-off-by: Sven Roederer --- tools/fit_image.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 4aeabbcfe97..88ff093d05b 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -17,6 +17,7 @@ #include "fit_common.h" #include "mkimage.h" #include +#include #include #include #include @@ -744,6 +745,9 @@ static int fit_handle_file(struct image_tool_params *params) snprintf(cmd, sizeof(cmd), "cp \"%s\" \"%s\"", params->imagefile, tmpfile); } + if (strlen(cmd) >= MKIMAGE_MAX_DTC_CMDLINE_LEN - 1) { + fprintf(stderr, "WARNING: command-line for FIT creation might be truncated and will probably fail.\n"); + } if (*cmd && system(cmd) == -1) { fprintf (stderr, "%s: system(%s) failed: %s\n", -- cgit v1.3.1 From 20a154f95bfe0a3b5bfba90bea7f001c58217536 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Fri, 1 May 2020 17:40:25 +0200 Subject: mkimage: fit: Do not tail-pad fitImage with external data There is no reason to tail-pad fitImage with external data to 4-bytes, while fitImage without external data does not have any such padding and is often unaligned. DT spec also does not mandate any such padding. Moreover, the tail-pad fills the last few bytes with uninitialized data, which could lead to a potential information leak. $ echo -n xy > /tmp/data ; \ ./tools/mkimage -E -f auto -d /tmp/data /tmp/fitImage ; \ hexdump -vC /tmp/fitImage | tail -n 3 before: 00000260 61 2d 6f 66 66 73 65 74 00 64 61 74 61 2d 73 69 |a-offset.data-si| 00000270 7a 65 00 00 78 79 64 64 |ze..xydd| ^^ ^^ ^^ after: 00000260 61 2d 6f 66 66 73 65 74 00 64 61 74 61 2d 73 69 |a-offset.data-si| 00000270 7a 65 00 78 79 |ze.xy| Signed-off-by: Marek Vasut Reviewed-by: Simon Glass Cc: Heinrich Schuchardt Cc: Tom Rini --- tools/fit_image.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 88ff093d05b..1e0f1e9fce8 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -435,7 +435,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) int image_number; int align_size; - align_size = params->bl_len ? params->bl_len : 4; + align_size = params->bl_len ? params->bl_len : 1; fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false); if (fd < 0) return -EIO; @@ -493,7 +493,6 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) fdt_pack(fdt); new_size = fdt_totalsize(fdt); - new_size = ALIGN(new_size, align_size); fdt_set_totalsize(fdt, new_size); debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt)); debug("External data size %x\n", buf_ptr); -- cgit v1.3.1 From 7946a814a31989998120b4b4aa417222ba21b2fa Mon Sep 17 00:00:00 2001 From: Tom Rini Date: Wed, 6 May 2020 11:05:17 -0400 Subject: Revert "mkimage: fit: Do not tail-pad fitImage with external data" This has been reported to break booting of U-Boot from SPL on a number of platforms due to a lack of alignment of the external data. The issues this commit is addressing will need to be resolved another way. Re-introduce a data leak in the padding for now. This reverts commit 20a154f95bfe0a3b5bfba90bea7f001c58217536. Reported-by: Alex Kiernan Reported-by: Michael Walle Tested-by: Jan Kiszka Signed-off-by: Tom Rini --- tools/fit_image.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/fit_image.c b/tools/fit_image.c index 1e0f1e9fce8..88ff093d05b 100644 --- a/tools/fit_image.c +++ b/tools/fit_image.c @@ -435,7 +435,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) int image_number; int align_size; - align_size = params->bl_len ? params->bl_len : 1; + align_size = params->bl_len ? params->bl_len : 4; fd = mmap_fdt(params->cmdname, fname, 0, &fdt, &sbuf, false, false); if (fd < 0) return -EIO; @@ -493,6 +493,7 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname) fdt_pack(fdt); new_size = fdt_totalsize(fdt); + new_size = ALIGN(new_size, align_size); fdt_set_totalsize(fdt, new_size); debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt)); debug("External data size %x\n", buf_ptr); -- cgit v1.3.1