Skip to contentSkip to conversation

mkimage: fit: Do not tail-pad fitImage with external data

RFC PATCH New Marek Vasut 3 participants 4 messages Apr 24, 2020 – May 1, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 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.

Test:
echo -n x > /tmp/data ; ./tools/mkimage -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage echo -n x > /tmp/data ; ./tools/mkimage -E -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage

Cc Heinrich Schuchardt <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
 tools/fit_image.c | 1 -
 1 file changed, 1 deletion(-)
tools/fit_image.c +0 -1
index dd61a816c9..2fc4c3630d 100644
@@ -488,7 +488,6 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 	debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt));
 	debug("External data size %x\n", buf_ptr);
 	new_size = fdt_totalsize(fdt);
-	new_size = (new_size + 3) & ~3;
 	munmap(fdt, sbuf.st_size);
 
 	if (ftruncate(fd, new_size)) {
Signature · 1 line
2.25.1
#1 lore raw

RFC PATCH 1/1 mkimage: fit: Do not tail-pad fitImage with external data

Quoted 12 lines · Marek Vasut

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.

Test:
echo -n x > /tmp/data ; ./tools/mkimage -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage echo -n x > /tmp/data ; ./tools/mkimage -E -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage

Quoted 7 lines
Cc Heinrich Schuchardt <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
 tools/fit_image.c | 1 -
 1 file changed, 1 deletion(-)

Would be good to get this in early for testing.

#2 lore raw

RFC PATCH 1/1 mkimage: fit: Do not tail-pad fitImage with external data

Quoted 21 lines · Simon Glass
Quoted 12 lines · Marek Vasut

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.

Test:
echo -n x > /tmp/data ; ./tools/mkimage -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage echo -n x > /tmp/data ; ./tools/mkimage -E -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage

Quoted 7 lines
Cc Heinrich Schuchardt <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
 tools/fit_image.c | 1 -
 1 file changed, 1 deletion(-)
Quoted 3 lines

Would be good to get this in early for testing.

Tom ? This missed rc1 ...

#3 lore raw

RFC PATCH 1/1 mkimage: fit: Do not tail-pad fitImage with external data

In reply to Marek Vasut
Quoted 25 lines · Marek Vasut

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.

Test:
echo -n x > /tmp/data ; ./tools/mkimage -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage echo -n x > /tmp/data ; ./tools/mkimage -E -f auto -d /tmp/data /tmp/fitImage ; hexdump -vC /tmp/fitImage

Cc Heinrich Schuchardt <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
 tools/fit_image.c | 1 -
 1 file changed, 1 deletion(-)
tools/fit_image.c +0 -0
index dd61a816c9..2fc4c3630d 100644

tools/fit_image.c static int fit_extract_data(struct image_tool_params *params, const char *fname) · line 493

Quoted 7 lines
tools/fit_image.c +0 -1
@@ -488,7 +488,6 @@ static int fit_extract_data(struct image_tool_params *params, const char *fname)
 	debug("Size reduced from %x to %x\n", fit_size, fdt_totalsize(fdt));
 	debug("External data size %x\n", buf_ptr);
 	new_size = fdt_totalsize(fdt);
-	new_size = (new_size + 3) & ~3;
 	munmap(fdt, sbuf.st_size);
 
 	if (ftruncate(fd, new_size)) {

As of:
commit ebfe611be91e0075c040588a30a9996519d30aa6

Author: Kever Yang <[email protected]>
Date:   Mon Mar 30 11:56:24 2020 +0800

mkimage: fit_image: Add option to make fit header align

this doesn't apply and the area in question has changed. Can you please see if your use-case is supported correctly now? Or v2 this, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200501/8a7a8498/attachment.sig>