From: "Bjørn Mork" <bjorn@mork.no>
To: u-boot@lists.denx.de
Subject: Re: [RFC v2 0/2] Prevent alignment issues with "in place" FIT configurations
Date: Mon, 07 Nov 2022 14:33:19 +0100 [thread overview]
Message-ID: <871qqex528.fsf@miraculix.mork.no> (raw)
In-Reply-To: <20221106154111.872209-1-bjorn@mork.no> ("Bjørn Mork"'s message of "Sun, 6 Nov 2022 16:41:09 +0100")
[-- Attachment #1: Type: text/plain, Size: 1032 bytes --]
So if anyone looked at this, then you've noticed that it fails to
consider signing.
The design makes it hard to support the combination. Algnment must run
last since signing may inject variable sized nodes before the fdt data
properties. Signing must run last since it hashes the blob as it is,
inluding FDT_NOP tags and property order.
But we can trick this int working by signing before aligning to create
the signature nodes with their proper size and position, and then
sign again as a final step if we had to inject any FDT_NOP tags.
The attached fix works for me, creating valid signatures with aligned
images no matter how many times I re-sign the FIT with different length
signature comments.
Downsides is the obvious double signing, which we already accept for
resizing, and a build-up of FDT_NOP tags. The latter is only an issue
if you re-sign with signature node size changes. And there's at most one
tag added per fdt node per signature update, so it's hardly a major
problem.
Bjørn
[-- Attachment #2: 0001-fix-re-sign-if-nops-were-added.patch --]
[-- Type: text/x-diff, Size: 1525 bytes --]
From 00f5cf3b08e44856ed826d427f63743180f3ae90 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B8rn=20Mork?= <bjorn@mork.no>
Date: Sun, 6 Nov 2022 22:13:53 +0100
Subject: [RFC v2 3/2] fix: re-sign if nops were added
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Bjørn Mork <bjorn@mork.no>
---
tools/fit_image.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/tools/fit_image.c b/tools/fit_image.c
index 2e215ca2199d..c29e209a8eea 100644
--- a/tools/fit_image.c
+++ b/tools/fit_image.c
@@ -66,6 +66,7 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
struct stat sbuf;
void *ptr;
int ret = 0;
+ size_t oldsize;
tfd = mmap_fdt(params->cmdname, tmpfile, size_inc, &ptr, &sbuf, true,
false);
@@ -115,9 +116,22 @@ static int fit_add_file_data(struct image_tool_params *params, size_t size_inc,
}
if (!ret) {
+ oldsize = fdt_size_dt_struct(ptr);
ret = fit_align_fdt_images(ptr);
}
+ /* new FDT_NOP tags must be included in the signed regions */
+ if (!ret && oldsize != fdt_size_dt_struct(ptr)) {
+ ret = fit_add_verification_data(params->keydir,
+ params->keyfile, dest_blob, ptr,
+ params->comment,
+ params->require_keys,
+ params->engine_id,
+ params->cmdname,
+ params->algo_name,
+ ¶ms->summary);
+ }
+
if (dest_blob) {
munmap(dest_blob, destfd_size);
close(destfd);
--
2.30.2
prev parent reply other threads:[~2022-11-07 13:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-06 15:41 [RFC v2 0/2] Prevent alignment issues with "in place" FIT configurations Bjørn Mork
2022-11-06 15:41 ` [RFC v2 1/2] libfdt: add fdt_alignprop Bjørn Mork
2022-11-07 23:35 ` Simon Glass
2022-11-08 7:41 ` Bjørn Mork
2022-11-06 15:41 ` [RFC v2 2/2] mkimage: Align fdt images in FIT to 8 bytes Bjørn Mork
2022-11-07 13:33 ` Bjørn Mork [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871qqex528.fsf@miraculix.mork.no \
--to=bjorn@mork.no \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox