Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1541750

Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs

From Eric Biggers <ebiggers3@gmail.com>
Newsgroups linux.kernel
Subject Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs
Date 2016-12-14 09:20 +0100
Message-ID <sOcX7-467-29@gated-at.bofh.it> (permalink)
References <sO7NL-J9-3@gated-at.bofh.it> <sO877-14y-11@gated-at.bofh.it> <sO9Zf-2jA-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Dec 14, 2016 at 01:04:04PM +0800, Herbert Xu wrote:
> On Tue, Dec 13, 2016 at 06:53:03PM -0800, Andy Lutomirski wrote:
> > On Tue, Dec 13, 2016 at 6:48 PM, Andy Lutomirski <luto@kernel.org> wrote:
> > > The driver put a constant buffer of all zeros on the stack and
> > > pointed a scatterlist entry at it in two places.  This doesn't work
> > > with virtual stacks.  Use ZERO_PAGE instead.
> > 
> > Wait a second...
> > 
> > > -       sg_set_buf(&sg_out[1], pad, sizeof pad);
> > > +       sg_set_buf(&sg_out[1], empty_zero_page, 16);
> > 
> > My fix here is obviously bogus (I meant to use ZERO_PAGE(0)), but what
> > exactly is the code trying to do?  The old code makes no sense.  It's
> > setting the *output* buffer to zeroed padding.
> 
> It's decrypting so I presume it just needs to the extra space for
> the padding and the result will be thrown away.
> 

It looks like the data is zero-padded to a 16-byte AES block boundary before
being encrypted with CBC, so the encrypted data may be longer than the original
data.  (I don't know why it doesn't use CTS mode instead, which would make the
lengths the same.)

Since the crypto API can do in-place operations, when *encrypting* I suggest
copying the decrypted data to the output buffer, padding it with 0's, and
encrypting it in-place.  This eliminates the need for the stack buffer.

But when *decrypting* there will be up to 15 extra throwaway bytes of output
produced by the decryption.  There must be space made for these, and since it's
output it can't be empty_zero_page.  I guess either check whether space can be
made for it in-place, or allocate a temporary buffer...

Eric

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs Andy Lutomirski <luto@kernel.org> - 2016-12-14 03:50 +0100
  Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs Andy Lutomirski <luto@amacapital.net> - 2016-12-14 04:10 +0100
    Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs Herbert Xu <herbert@gondor.apana.org.au> - 2016-12-14 06:10 +0100
      Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs Eric Biggers <ebiggers3@gmail.com> - 2016-12-14 09:20 +0100
    Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs David Howells <dhowells@redhat.com> - 2016-12-14 09:40 +0100
      Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs Andy Lutomirski <luto@amacapital.net> - 2016-12-14 17:30 +0100
        Re: [PATCH v2] keys/encrypted: Fix two crypto-on-the-stack bugs David Howells <dhowells@redhat.com> - 2016-12-14 18:10 +0100

csiph-web