From: David Howells <dhowells@redhat.com>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: dhowells@redhat.com, rusty@rustcorp.com.au, kyle@mcmartin.ca,
linux-kernel@vger.kernel.org,
linux-security-module@vger.kernel.org, keyrings@linux-nfs.org
Subject: Re: [PATCH 00/29] Crypto keys and module signing [ver #4]
Date: Fri, 11 May 2012 15:32:03 +0100 [thread overview]
Message-ID: <11253.1336746723@redhat.com> (raw)
In-Reply-To: <201205112230.EED65669.tQOVFMSOFOFHJL@I-love.SAKURA.ne.jp>
Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> wrote:
> + int npkey = key->algo->n_pub_mpi;
> + int i, ret = -ENOMEM;
> +
> + kenter("");
> +
> + n = (pgp->version < PGP_KEY_VERSION_4) ? 8 : 6;
> + for (i = 0; i < npkey; i++) {
> + nb[i] = mpi_get_nbits(key->mpi[i]);
>
> Is key->algo->n_pub_mpi < ARRAY_SIZE(key->mpi) guaranteed?
Yes. It's hard-coded in the public_key_algorithm struct - for instance the
one to be found at the bottom of security/keys/crypto_rsa.c.
We also check for an excessive quantity of MPIs in pgp_process_public_key().
> + if( pgp->expires_at)
>
> checkpatch.pl
Fixed some of those.
> +error:
> + for (i = 0; i < npkey; i++)
> + kfree(pp[i]);
>
> Stack memory may not be initialized.
Fair point.
> + hashedsz = 4 + 2 + (data[4] << 8) + data[5];
>
> Given the (datalen <= 2) check below, can we trust data[4,5] here?
We've already done some length and content checking on the signature data. In
the module verification case, this happens:
(1) module_verify_sig() has already passed the signature data to
verify_sig_begin(),
(2) which passed it to pgp_pkey_verify_sig_begin(),
(3) which invoked pgp_parse_packets(),
(4) which called back to pgp_pkey_parse_signature(),
(5) which then invoked pgp_parse_sig_params() which did sufficient length
checking to make sure we're okay here.
by the time we get to pgp_pkey_digest_signature() we're at the end of the
process (in verify_sig_end()).
The trailer, however, is not checked at that point - though I suppose it
probably should be. There isn't currently an MPI function to do just a check
rather than an extraction.
I can add comments to this effect if you think it would help reduce confusion.
> +static int module_verify_canonicalise(struct module_verify_data *mvdata)
> +{
> + const Elf_Shdr *sechdrs = mvdata->sections;
> + unsigned *canonlist, canon, loop, tmp;
> + bool changed;
> +
> + canonlist = kmalloc(sizeof(unsigned) * mvdata->nsects * 2, GFP_KERNEL);
> + if (!canonlist)
> + return -ENOMEM;
>
> Can mvdata->nsects == (UINT_MAX + 1) / (sizeof(unsigned) * 2) due to size_t?
> I think we want kmalloc() variant that does not return ZERO_SIZE_PTR.
This line should prevent that:
elfcheck(hdr->e_shnum < SHN_LORESERVE);
given:
#define SHN_LORESERVE 0xff00
Thanks for the thorough review!
David
next prev parent reply other threads:[~2012-05-11 14:32 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-10 23:39 [PATCH 00/29] Crypto keys and module signing [ver #4] David Howells
2012-05-10 23:39 ` [PATCH 01/29] MPILIB: Export some more symbols " David Howells
2012-05-10 23:39 ` [PATCH 02/29] KEYS: Move the key config into security/keys/Kconfig " David Howells
2012-05-10 23:39 ` [PATCH 03/29] KEYS: Announce key type (un)registration " David Howells
2012-05-10 23:39 ` [PATCH 04/29] KEYS: Reorganise keys Makefile " David Howells
2012-05-10 23:39 ` [PATCH 05/29] KEYS: Create a key type that can be used for general cryptographic operations " David Howells
2012-05-10 23:40 ` [PATCH 06/29] KEYS: Add signature verification facility " David Howells
2012-05-10 23:40 ` [PATCH 07/29] KEYS: Asymmetric public-key algorithm crypto key subtype " David Howells
2012-05-10 23:40 ` [PATCH 08/29] KEYS: RSA signature verification algorithm " David Howells
2012-05-10 23:40 ` [PATCH 09/29] Fix signature verification for shorter signatures " David Howells
2012-05-10 23:40 ` [PATCH 10/29] PGPLIB: PGP definitions (RFC 4880) " David Howells
2012-05-10 23:41 ` [PATCH 11/29] PGPLIB: Basic packet parser " David Howells
2012-05-10 23:41 ` [PATCH 12/29] PGPLIB: Signature " David Howells
2012-05-10 23:41 ` [PATCH 13/29] KEYS: PGP data " David Howells
2012-05-10 23:41 ` [PATCH 14/29] KEYS: PGP-based public key signature verification " David Howells
2012-05-10 23:41 ` [PATCH 15/29] KEYS: PGP format signature parser " David Howells
2012-05-10 23:41 ` [PATCH 16/29] KEYS: Provide a function to load keys from a PGP keyring blob " David Howells
2012-05-10 23:42 ` [PATCH 17/29] Provide macros for forming the name of an ELF note and its section " David Howells
2012-05-10 23:42 ` [PATCH 18/29] Guard check in module loader against integer overflow " David Howells
2012-05-10 23:42 ` [PATCH 19/29] MODSIGN: Add indications of module ELF types " David Howells
2012-05-10 23:42 ` [PATCH 20/29] MODSIGN: Provide gitignore and make clean rules for extra files " David Howells
2012-05-10 23:42 ` [PATCH 21/29] MODSIGN: Provide Documentation and Kconfig options " David Howells
2012-05-10 23:43 ` [PATCH 22/29] MODSIGN: Sign modules during the build process " David Howells
2012-05-10 23:43 ` [PATCH 23/29] MODSIGN: Module signature verification stub " David Howells
2012-05-10 23:43 ` [PATCH 24/29] MODSIGN: Provide module signing public keys to the kernel " David Howells
2012-05-10 23:43 ` [PATCH 25/29] MODSIGN: Check the ELF container " David Howells
2012-05-10 23:43 ` [PATCH 26/29] MODSIGN: Produce a filtered and canonicalised section list " David Howells
2012-05-10 23:43 ` [PATCH 27/29] MODSIGN: Create digest of module content and check signature " David Howells
2012-05-10 23:44 ` [PATCH 28/29] MODSIGN: Automatically generate module signing keys if missing " David Howells
2012-05-10 23:44 ` [PATCH 29/29] MODSIGN: Suppress some redundant ELF checks " David Howells
2012-05-11 13:30 ` [PATCH 00/29] Crypto keys and module signing " Tetsuo Handa
2012-05-11 14:32 ` David Howells [this message]
2012-05-11 16:17 ` David Howells
2012-05-19 0:53 ` Rusty Russell
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=11253.1336746723@redhat.com \
--to=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 \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--cc=rusty@rustcorp.com.au \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.