All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH] verify: search keyid in hashed signature subpackets
Date: Wed, 30 Mar 2016 07:44:29 +0300	[thread overview]
Message-ID: <56FB59AD.9020804@gmail.com> (raw)
In-Reply-To: <C91F0381-2C9A-4A8A-AEE4-4743F238D34B@cloudflare.com>

29.03.2016 22:02, Ignat Korchagin пишет:
> Currently GRUB2 verify logic searches PGP keyid only in unhashed subpackets of PGP signature packet. As a result, signatures generated with GoLang openpgp package (https://godoc.org/golang.org/x/crypto/openpgp) could not be verified, because this package puts keyid in hashed subpackets and GRUB code never initializes the keyid variable, therefore is not able to find "verification key" with id 0x0.
> 
> diff --git a/grub-core/commands/verify.c b/grub-core/commands/verify.c
> index 166d0aa..dde37c4 100644
> --- a/grub-core/commands/verify.c
> +++ b/grub-core/commands/verify.c
> @@ -532,33 +532,15 @@
>  
>      hash->write (context, &v, sizeof (v));
>      hash->write (context, &v4, sizeof (v4));
> -    while (rem)
> -      {
> -	r = grub_file_read (sig, readbuf,
> -			    rem < READBUF_SIZE ? rem : READBUF_SIZE);
> -	if (r < 0)
> -	  goto fail;
> -	if (r == 0)
> -	  break;
> -	hash->write (context, readbuf, r);
> -	rem -= r;
> -      }
> -    hash->write (context, &v, sizeof (v));
> -    s = 0xff;
> -    hash->write (context, &s, sizeof (s));
> -    hash->write (context, &headlen, sizeof (headlen));
> -    r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub));
> -    if (r != sizeof (unhashed_sub))
> +    if (rem > READBUF_SIZE)
> +      goto fail;

This changes behavior. It accepted hashed subpackets of arbitrary length
before. If this was not appropriate, please explain why.

> +    r = grub_file_read (sig, readbuf, rem);
> +    if (r != rem)
>        goto fail;
>      {
>        grub_uint8_t *ptr;
>        grub_uint32_t l;
> -      rem = grub_be_to_cpu16 (unhashed_sub);
> -      if (rem > READBUF_SIZE)
> -	goto fail;
> -      r = grub_file_read (sig, readbuf, rem);
> -      if (r != rem)
> -	goto fail;
> +
>        for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
>  	{
>  	  if (*ptr < 192)
> @@ -581,6 +563,46 @@
>  	    keyid = grub_get_unaligned64 (ptr + 1);
>  	}
>      }
> +    hash->write (context, readbuf, r);
> +    hash->write (context, &v, sizeof (v));
> +    s = 0xff;
> +    hash->write (context, &s, sizeof (s));
> +    hash->write (context, &headlen, sizeof (headlen));
> +    r = grub_file_read (sig, &unhashed_sub, sizeof (unhashed_sub));
> +    if (r != sizeof (unhashed_sub))
> +      goto fail;
> +    if (keyid == 0)
> +      {
> +        grub_uint8_t *ptr;
> +        grub_uint32_t l;
> +        rem = grub_be_to_cpu16 (unhashed_sub);
> +        if (rem > READBUF_SIZE)
> +	  goto fail;
> +        r = grub_file_read (sig, readbuf, rem);
> +        if (r != rem)
> +	  goto fail;
> +        for (ptr = readbuf; ptr < readbuf + rem; ptr += l)
> +	  {
> +	    if (*ptr < 192)
> +	      l = *ptr++;
> +	    else if (*ptr < 255)
> +	      {
> +	        if (ptr + 1 >= readbuf + rem)
> +		  break;
> +	        l = (((ptr[0] & ~192) << GRUB_CHAR_BIT) | ptr[1]) + 192;
> +	        ptr += 2;
> +	      }
> +	    else
> +	      {
> +	        if (ptr + 5 >= readbuf + rem)
> +		  break;
> +	        l = grub_be_to_cpu32 (grub_get_unaligned32 (ptr + 1));
> +	        ptr += 5;
> +	      }
> +	    if (*ptr == 0x10 && l >= 8)
> +	      keyid = grub_get_unaligned64 (ptr + 1);
> +	  }
> +      }
>  
>      hash->final (context);
>  
> 
> 
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
> 



  reply	other threads:[~2016-03-30  4:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-29 19:02 [PATCH] verify: search keyid in hashed signature subpackets Ignat Korchagin
2016-03-30  4:44 ` Andrei Borzenkov [this message]
2016-03-30  8:47   ` Ignat Korchagin
2016-03-30  9:38     ` Andrei Borzenkov
2016-03-30 14:09       ` Ignat Korchagin
2016-04-09  4:27         ` Andrei Borzenkov
2016-04-10 18:34           ` Ignat Korchagin
2016-04-19 14:28             ` Ignat Korchagin
2016-04-21 16:54               ` Ignat Korchagin
2016-04-28 21:32                 ` Ignat Korchagin
2016-11-10 13:50                   ` Daniel Kiper
2016-11-13  9:18                     ` Andrei Borzenkov
2016-11-15 12:42                       ` Daniel Kiper
2016-11-15 12:43                         ` Ignat Korchagin

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=56FB59AD.9020804@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=grub-devel@gnu.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 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.