From: Rusty Russell <rusty@rustcorp.com.au>
To: David Howells <dhowells@redhat.com>
Cc: dhowells@redhat.com, kyle@mcmartin.ca,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, keyrings@linux-nfs.org
Subject: Re: [PATCH 00/23] Crypto keys and module signing
Date: Thu, 24 May 2012 21:34:04 +0930 [thread overview]
Message-ID: <8762blyedn.fsf@rustcorp.com.au> (raw)
In-Reply-To: <7474.1337782847@redhat.com>
On Wed, 23 May 2012 15:20:47 +0100, David Howells <dhowells@redhat.com> wrote:
> Rusty Russell <rusty@rustcorp.com.au> wrote:
>
> > That's pretty weird. Why not put the "@This Is A Crypto Signed
> > Module\n" before the signature? Then module-size is implied: everything
> > before that signature. The signature size is implied: everything after
> > that signature.
>
> This makes it simpler. No scanning required. The magic number can only be in
> one place and you can find it by dead reckoning.
Scanning isn't complicated. Slow, sure, but I doubt you can really
measure it when you're doing crypto.
Compare:
(1) Your scheme signing looks something like this:
gpg --sign $m > $m.sig
MSIZE=`ls -l $m | awk '{ print $5 }'`
SSIZE=`ls -l $m.sig | awk '{ print $5 }'`
printf '@%-10i@%-10i@This Is A Crypto Signed Module' $MSIZE $SSIZE >> $m
(2) Your verification scheme looks like this:
+ magic_size = sizeof(modsign_magic) - 1;
+ if (size <= 11 + 11 + magic_size)
+ return 1;
+
+ if (memcmp(data + size - magic_size, modsign_magic, magic_size) != 0)
+ return 1;
+ size -= 11 + 11 + magic_size;
+
+ cp = data + size;
+ if (cp[ 0] != '@' && cp[ 9] != '@' && cp[10] != '\n' &&
+ cp[11] != '@' && cp[20] != '@' && cp[21] != '\n')
+ return -ELIBBAD;
+ mod_size = simple_strtoul(cp + 1, &end, 10);
+ if (mod_size > size || (*end != ' ' && *end != '@'))
+ return -ELIBBAD;
+ sig_size = simple_strtoul(cp + 12, &end, 10);
+ if (sig_size > size || (*end != ' ' && *end != '@'))
+ return -ELIBBAD;
+
+ pr_devel("sig at %zu, size %zu (to %zu)\n", mod_size, sig_size,
size);
+ if (size - mod_size != sig_size)
+ return -ELIBBAD;
Now, the scheme I suggested looks like this:
(1) Signing:
gpg --sign $m > $m.sig
(echo @This Is A Crypto Signed Module; cat $m.sig) >> $m
(2) Verification:
size_t i;
if (i < modsign_magic)
return 1;
for (i = size - modsign_magic;
memcmp(data + i, modsign_magic, magic_size) != 0);
i++) {
if (i == 0)
return 1;
}
/* module: "data", size "i".
* sig: "data + i + magic_size", size "size - (i + magic_size)" */
> > In fact, I'd modify this slightly, to allow multiple signatures.
> > This would work nicely with a deterministic strip. Find the signatures
> > backward, and truncate as they fail.
>
> Why would you want multiple signatures? That just complicates things.
The code above stays pretty simple; if the signature fails, you set size
to i, and loop again. As I said, if you know exactly how you're going
to strip the modules, you can avoid storing the stripped module and
simply append both signatures.
> If you're in FIPS mode, you probably have to panic if any of them fail.
I had to look up what FIPS was, so I'm not qualified to comment.
> I suppose I may as well punt the signature detection and removal to userspace
> and pass the signature as an argument to init_module() as Dmitry suggested.
> Then the signature need not be in the file at all (he wants to use an xattr or
> hardware, I think). mkinitrd and rpmbuild/kernel spec have to be changed to
> accommodate enablement of these patches, so why not module-init-tools, dracut
> and busybox whilst we're at it?
In some ways that is cleaner, but it's also nice to avoid adding another
syscall.
Cheers,
Rusty.
next prev parent reply other threads:[~2012-05-24 12:08 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-22 23:02 [PATCH 00/23] Crypto keys and module signing David Howells
2012-05-22 23:02 ` [PATCH 01/23] Guard check in module loader against integer overflow David Howells
2012-05-22 23:02 ` [PATCH 02/23] KEYS: Move the key config into security/keys/Kconfig David Howells
2012-05-22 23:02 ` [PATCH 03/23] KEYS: Announce key type (un)registration David Howells
2012-05-22 23:02 ` [PATCH 04/23] KEYS: Reorganise keys Makefile David Howells
2012-05-22 23:02 ` [PATCH 05/23] KEYS: Create a key type that can be used for general cryptographic operations David Howells
2012-05-22 23:03 ` [PATCH 06/23] KEYS: Add signature verification facility David Howells
2012-05-22 23:03 ` [PATCH 07/23] KEYS: Asymmetric public-key algorithm crypto key subtype David Howells
2012-05-22 23:03 ` [PATCH 08/23] KEYS: RSA signature verification algorithm David Howells
2012-05-22 23:03 ` [PATCH 09/23] Fix signature verification for shorter signatures David Howells
2012-05-22 23:03 ` [PATCH 10/23] PGPLIB: PGP definitions (RFC 4880) David Howells
2012-05-22 23:03 ` [PATCH 11/23] PGPLIB: Basic packet parser David Howells
2012-05-22 23:03 ` [PATCH 12/23] PGPLIB: Signature parser David Howells
2012-05-22 23:03 ` [PATCH 13/23] KEYS: PGP data parser David Howells
2012-05-22 23:04 ` [PATCH 14/23] KEYS: PGP-based public key signature verification David Howells
2012-05-22 23:04 ` [PATCH 15/23] KEYS: PGP format signature parser David Howells
2012-05-22 23:04 ` [PATCH 16/23] KEYS: Provide a function to load keys from a PGP keyring blob David Howells
2012-05-22 23:04 ` [PATCH 17/23] MODSIGN: Provide gitignore and make clean rules for extra files David Howells
2012-05-22 23:04 ` [PATCH 18/23] MODSIGN: Provide Documentation and Kconfig options David Howells
2012-05-22 23:04 ` [PATCH 19/23] MODSIGN: Sign modules during the build process David Howells
2012-05-22 23:04 ` [PATCH 20/23] MODSIGN: Provide module signing public keys to the kernel David Howells
2012-05-22 23:05 ` [PATCH 21/23] MODSIGN: Module signature verification David Howells
2012-05-22 23:05 ` [PATCH 22/23] MODSIGN: Automatically generate module signing keys if missing David Howells
2012-05-22 23:05 ` [PATCH 23/23] MODSIGN: Panic the kernel if FIPS is enabled upon module signing failure David Howells
2012-05-23 12:51 ` [PATCH 00/23] Crypto keys and module signing Rusty Russell
2012-05-23 14:20 ` David Howells
2012-05-24 12:04 ` Rusty Russell [this message]
2012-05-24 14:00 ` David Howells
2012-05-27 5:41 ` Rusty Russell
2012-05-31 14:11 ` David Howells
2012-05-31 15:35 ` Josh Boyer
2012-06-04 1:16 ` Rusty Russell
2012-06-04 13:38 ` Josh Boyer
2012-06-05 0:23 ` Rusty Russell
2012-06-22 1:53 ` Greg KH
2012-06-22 3:29 ` Lucas De Marchi
2012-06-22 4:05 ` Rusty Russell
2012-06-22 11:03 ` David Howells
2012-06-23 0:20 ` Rusty Russell
2012-05-25 11:15 ` Kasatkin, Dmitry
2012-05-25 11:37 ` David Howells
2012-05-25 13:08 ` Mimi Zohar
2012-05-25 13:53 ` David Howells
2012-05-25 14:40 ` Mimi Zohar
2012-05-25 12:18 ` David Howells
2012-05-25 15:42 ` David Howells
2012-06-04 1:31 ` Rusty Russell
2012-06-04 12:47 ` Mimi Zohar
2012-06-05 1:05 ` Rusty Russell
2012-06-05 11:39 ` Mimi Zohar
2012-06-05 13:37 ` David Howells
2012-06-05 14:36 ` Kasatkin, Dmitry
2012-06-05 13:35 ` David Howells
2012-06-10 5:47 ` Rusty Russell
2012-06-11 8:30 ` Kasatkin, Dmitry
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=8762blyedn.fsf@rustcorp.com.au \
--to=rusty@rustcorp.com.au \
--cc=dhowells@redhat.com \
--cc=keyrings@linux-nfs.org \
--cc=kyle@mcmartin.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).