From: Jeremy Linton <jeremy.linton@arm.com>
To: linux-kernel@vger.kernel.org
Cc: akpm@linux-foundation.org, hch@lst.de,
gregkh@linuxfoundation.org, graf@amazon.com, lukas@wunner.de,
wufan@linux.microsoft.com, brauner@kernel.org,
jsperbeck@google.com, ardb@kernel.org,
linux-crypto@vger.kernel.org, linux-kbuild@vger.kernel.org,
keyrings@vger.kernel.org, Jeremy Linton <jeremy.linton@arm.com>
Subject: [RFC 4/5] sign-file: Add -i option to sign initramfs images
Date: Tue, 15 Oct 2024 17:22:34 -0500 [thread overview]
Message-ID: <20241015222235.71040-5-jeremy.linton@arm.com> (raw)
In-Reply-To: <20241015222235.71040-1-jeremy.linton@arm.com>
The initramfs signature is the mod signature with a differing string
to assure that cpio archives with a signed module at the end can never
be confused for a valid signed initramfs.
To support this, add a -i option to sign-file, which replaces the
"Module signature appended" string with "initrd signature appended",
which is the same length.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
scripts/sign-file.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/scripts/sign-file.c b/scripts/sign-file.c
index 7070245edfc1..bbf97a57311a 100644
--- a/scripts/sign-file.c
+++ b/scripts/sign-file.c
@@ -75,6 +75,7 @@ struct module_signature {
#define PKEY_ID_PKCS7 2
static char magic_number[] = "~Module signature appended~\n";
+static char magic_initrd[] = "~initrd signature appended~\n";
static __attribute__((noreturn))
void format(void)
@@ -226,6 +227,7 @@ int main(int argc, char **argv)
bool save_sig = false, replace_orig;
bool sign_only = false;
bool raw_sig = false;
+ bool initrd_sig = false;
unsigned char buf[4096];
unsigned long module_size, sig_size;
unsigned int use_signed_attrs;
@@ -253,7 +255,7 @@ int main(int argc, char **argv)
#endif
do {
- opt = getopt(argc, argv, "sdpk");
+ opt = getopt(argc, argv, "sdpki");
switch (opt) {
case 's': raw_sig = true; break;
case 'p': save_sig = true; break;
@@ -261,6 +263,7 @@ int main(int argc, char **argv)
#ifndef USE_PKCS7
case 'k': use_keyid = CMS_USE_KEYID; break;
#endif
+ case 'i': initrd_sig = true; break;
case -1: break;
default: format();
}
@@ -398,7 +401,11 @@ int main(int argc, char **argv)
sig_size = BIO_number_written(bd) - module_size;
sig_info.sig_len = htonl(sig_size);
ERR(BIO_write(bd, &sig_info, sizeof(sig_info)) < 0, "%s", dest_name);
- ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
+ if (initrd_sig)
+ ERR(BIO_write(bd, magic_initrd, sizeof(magic_initrd) - 1) < 0, "%s", dest_name);
+ else
+ ERR(BIO_write(bd, magic_number, sizeof(magic_number) - 1) < 0, "%s", dest_name);
+
ERR(BIO_free(bd) != 1, "%s", dest_name);
--
2.46.0
next prev parent reply other threads:[~2024-10-15 22:22 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-15 22:22 [RFC 0/5] Another initramfs signature checking set Jeremy Linton
2024-10-15 22:22 ` [RFC 1/5] initramfs: Add initramfs signature checking Jeremy Linton
2024-10-15 22:22 ` [RFC 2/5] KEYS/certs: Start the builtin key and cert system earlier Jeremy Linton
2024-10-15 22:22 ` [RFC 3/5] initramfs: Use existing module signing infrastructure Jeremy Linton
2024-10-15 22:22 ` Jeremy Linton [this message]
2024-10-15 22:22 ` [RFC 5/5] initramfs: Enforce initramfs signature Jeremy Linton
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=20241015222235.71040-5-jeremy.linton@arm.com \
--to=jeremy.linton@arm.com \
--cc=akpm@linux-foundation.org \
--cc=ardb@kernel.org \
--cc=brauner@kernel.org \
--cc=graf@amazon.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@lst.de \
--cc=jsperbeck@google.com \
--cc=keyrings@vger.kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=wufan@linux.microsoft.com \
/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