diff mbox series

[v2,2/3] core/parser: add 'size' attribute to sw-description

Message ID 20241031055741.91045-2-dominique.martinet@atmark-techno.com
State Accepted
Headers show
Series [1/3] cpio_util: remove unused cpio_scan | expand

Commit Message

Dominique MARTINET Oct. 31, 2024, 5:57 a.m. UTC
This allows specifying the size of each cpio file in the sw-description

The motivation behind this change is that files are only verified as
they are copied to temporary directory or streamed, but without the size
information a file could be streamed forever and easily fill in the tmp
directory by replacing the files of a valid (signed) SWU.

This will be useful even if a chunked checksum is implemented, because
while the chunked checksum implicitly also validates the files length it
is not useful to include chunked checksums for files that have an
intermediate copy stored, and it is more efficient and simpler to only
have this size information.

Signed-off-by: Dominique Martinet <dominique.martinet@atmark-techno.com>
---
v1->v2: remove cpio_scan bit.

 core/installer.c              | 6 ++++++
 doc/source/sw-description.rst | 5 +++++
 parser/parser.c               | 1 +
 3 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/core/installer.c b/core/installer.c
index 0cb06b2ca419..e3abfd30ddf6 100644
--- a/core/installer.c
+++ b/core/installer.c
@@ -58,6 +58,12 @@  swupdate_file_t check_if_required(struct imglist *list, struct filehdr *pfdh,
 		if (strcmp(pfdh->filename, img->fname) == 0) {
 			skip = COPY_FILE;
 			img->provided = 1;
+			if (img->size && img->size != (unsigned int)pfdh->size) {
+				ERROR("Size in sw-description %llu does not match size in cpio %u",
+					img->size, (unsigned int)pfdh->size);
+				return -EINVAL;
+
+			}
 			img->size = (unsigned int)pfdh->size;
 
 			if (snprintf(img->extract_file,
diff --git a/doc/source/sw-description.rst b/doc/source/sw-description.rst
index d4cb8971b4ed..7d13e1e65d18 100644
--- a/doc/source/sw-description.rst
+++ b/doc/source/sw-description.rst
@@ -1491,3 +1491,8 @@  There are 4 main sections inside sw-description:
    |             |          |            | the mtd to update, instead of         |
    |             |          |            | specifying the devicenode             |
    +-------------+----------+------------+---------------------------------------+
+   | size        | int64    | images     | size of the file as it is expected    |
+   |             |          | files      | in the SWU. If set and the cpio size  |
+   |             |          | scripts    | does not match for some reason the    |
+   |             |          |            | update will fail with an error.       |
+   +-------------+----------+------------+---------------------------------------+
diff --git a/parser/parser.c b/parser/parser.c
index f5113f94841b..52bee8cbf11d 100644
--- a/parser/parser.c
+++ b/parser/parser.c
@@ -420,6 +420,7 @@  static int parse_common_attributes(parsertype p, void *elem, struct img_type *im
 	GET_FIELD_STRING(p, elem, "filesystem", image->filesystem);
 	GET_FIELD_STRING(p, elem, "type", image->type);
 	GET_FIELD_STRING(p, elem, "data", image->type_data);
+	GET_FIELD_INT64(p, elem, "size", &image->size);
 	get_hash_value(p, elem, image->sha256);
 
 	/*