fwtool: do not omit final 16 byte when image does not contain signature
authorJo-Philipp Wich <jo@mein.io>
Thu, 17 Oct 2019 14:59:11 +0000 (16:59 +0200)
committerRISCi_ATOM <bob@bobcall.me>
Sat, 19 Oct 2019 00:03:14 +0000 (20:03 -0400)
The fwutil command will interpret the final 16 byte of a given firmware
image files as "struct fwimage_trailer".

In case these bytes do look like a valid trailer, we must ensure that we
print them out along with the remainder of the image to not accidentally
truncate non-trailer-images by 16 bytes when they're piped through fwtool,
e.g. as part of an image verification command sequence.

Some command sequences pipe images through fwtool in order to strip any
possible metadata, certificate or signature trailers and do not expect
bare images without any of that metadata to get truncated as other non-
fwtool specific metadata is expected at the end of the file, e.g. an
information block with an md5sum in case of the combined image format.

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 889b841048c5eb7f975135cab363f1fdd9b6cfa1)

package/system/fwtool/Makefile
package/system/fwtool/src/fwtool.c

index 901081c1f4acb942c084a01ff9cc69249636455b..283be8d77a0ea2c4cc3e06ef15f32c545dda5a32 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fwtool
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_FLAGS:=nonshared
 
index 3adc1e02492ccea546761dd05c033c46c5925a37..89e89514ad35f4539b55cc9eddc9d977871e22cc 100644 (file)
@@ -328,12 +328,14 @@ extract_data(const char *name)
                if (extract_tail(&dbuf, &tr, sizeof(tr)))
                        break;
 
-               data_len = be32_to_cpu(tr.size) - sizeof(tr);
                if (tr.magic != cpu_to_be32(FWIMAGE_MAGIC)) {
                        msg("Data not found\n");
+                       metadata_keep = true;
                        break;
                }
 
+               data_len = be32_to_cpu(tr.size) - sizeof(tr);
+
                if (be32_to_cpu(tr.crc32) != tail_crc32(&dbuf, crc32)) {
                        msg("CRC error\n");
                        break;