[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAGXu5j+bpLK=EQ9LHkO8V=sdaQwt==6fbGhgn2Vi1E9_WxSGRQ@mail.gmail.com>
Date: Thu, 13 Sep 2018 10:40:16 -0700
From: Kees Cook <keescook@...omium.org>
To: Herbert Xu <herbert@...dor.apana.org.au>
Cc: Ard Biesheuvel <ard.biesheuvel@...aro.org>,
Eric Biggers <ebiggers@...gle.com>,
Gilad Ben-Yossef <gilad@...yossef.com>,
Alexander Stein <alexander.stein@...tec-electronic.com>,
Antoine Tenart <antoine.tenart@...tlin.com>,
Boris Brezillon <boris.brezillon@...tlin.com>,
Arnaud Ebalard <arno@...isbad.org>,
Corentin Labbe <clabbe.montjoie@...il.com>,
Maxime Ripard <maxime.ripard@...tlin.com>,
Chen-Yu Tsai <wens@...e.org>,
Christian Lamparter <chunkeey@...il.com>,
Philippe Ombredanne <pombredanne@...b.com>,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
"open list:HARDWARE RANDOM NUMBER GENERATOR CORE"
<linux-crypto@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-arm-kernel <linux-arm-kernel@...ts.infradead.org>
Subject: Re: [PATCH v2 2/4] crypto: skcipher - Enforce non-ASYNC for on-stack requests
On Thu, Sep 13, 2018 at 9:46 AM, Kees Cook <keescook@...omium.org> wrote:
> On Mon, Sep 10, 2018 at 10:52 PM, Herbert Xu
> <herbert@...dor.apana.org.au> wrote:
>> On Fri, Sep 07, 2018 at 08:56:23AM +0200, Ard Biesheuvel wrote:
>>>
>>> OK, so given that all SKCIPHER_REQUEST_ON_STACK occurrences are
>>> updated in this series anyway, perhaps we should add
>>> skcipher_[en|de]crypt_onstack() flavors that encapsulate the
>>> additional check? Only question is how to enforce at compile time that
>>> those are used instead of the ordinary ones when using a stack
>>> allocated request. Would you mind using some macro foo here involving
>>> __builtin_types_compatible_p() ?
>>
>> Something like a completely new type which in reality is just a
>> wrapper around skcipher:
>>
>> struct crypto_sync_skcipher {
>> struct crypto_skcipher base;
>> } tfm;
>>
>> tfm = crypto_alloc_sync_skcipher(...);
>>
>> crypto_sync_skcipher_encrypt(...)
>> crypto_sync_skcipher_decrypt(...)
>>
>> These functions would just be trivial inline functions around their
>> crypto_skcipher counterparts.
>
> This means new wrappers for the other helpers too, yes? For example:
>
> SKCIPHER_REQUEST_ON_STACK(nreq, ctx->null);
>
> skcipher_request_set_tfm(nreq, ctx->null);
> skcipher_request_set_callback(nreq, req->base.flags, NULL, NULL);
> skcipher_request_set_crypt(nreq, req->src, req->dst, nbytes, NULL);
>
> return crypto_skcipher_encrypt(nreq);
>
> For the above, we'd also need:
>
> sync_skcipher_request_set_tfm()
> sync_skcipher_request_set_callback()
> sync_skcipher_request_set_crypt()
Wait, I think I misunderstood you. Did you mean a new top-level thing
(tfm?) not a new request type?
That would mean at least replacing skcipher_request_set_tfm() with a
wrapper (since the tfm argument is different), but _not_
encrypt/decrypt like you mention. I could perform a type test in
SKCIPHER_REQUEST_ON_STACK().
Globally:
- add struct crypto_sync_skcipher wrapper
- add crypto_alloc_sync_skcipher() to check non-ASYNC and request size
of actual tfm
- add skcipher_request_set_sync_tfm() to attach the wrapped tfm to the request
- SKCIPHER_REQUEST_ON_STACK() would verify the tfm was a struct
crypto_sync_skcipher.
Two changes per user:
- change allocation to use new crypto_alloc_sync_skcipher() which does
the runtime checking
- change skcipher_request_set_tfm() to skcipher_request_set_sync_tfm()
This means struct skcipher_request is unchanged, along with
_set_callback, _set_crypt, _zero, and en/decrypt.
API misuse would be caught at build-time (via
SKCIPHER_REQUEST_ON_STACK type checking) and any request size problems
would be caught at allocation time.
Does this sound like what you had in mind?
-Kees
--
Kees Cook
Pixel Security
Powered by blists - more mailing lists