* [PATCH] crypto: authenc - cryptlen must be at least AAD len
@ 2017-09-06 19:22 Stephan Müller
2017-09-06 20:10 ` Stephan Müller
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Müller @ 2017-09-06 19:22 UTC (permalink / raw)
To: herbert; +Cc: stable, linux-crypto
With AF_ALG, AAD len and cryptlen can be set freely by unprivileged
user space. The cipher implementation must therefore validate the input
data for sanity. For AEAD ciphers, this implies that cryptlen must be
at least as large as AAD size.
This fixes a kernel crash that can be triggered via AF_ALG detected by
the fuzzing test implemented with libkcapi.
CC: <stable@vger.kernel.org>
CC: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Stephan Mueller <smueller@chronox.de>
---
crypto/authenc.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/crypto/authenc.c b/crypto/authenc.c
index 875470b0e026..21e202fc32c1 100644
--- a/crypto/authenc.c
+++ b/crypto/authenc.c
@@ -209,6 +209,9 @@ static int crypto_authenc_encrypt(struct aead_request *req)
struct scatterlist *src, *dst;
int err;
+ if (req->assoclen > cryptlen)
+ return -EINVAL;
+
src = scatterwalk_ffwd(areq_ctx->src, req->src, req->assoclen);
dst = src;
--
2.13.5
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: authenc - cryptlen must be at least AAD len
2017-09-06 19:22 [PATCH] crypto: authenc - cryptlen must be at least AAD len Stephan Müller
@ 2017-09-06 20:10 ` Stephan Müller
2017-09-07 3:54 ` Herbert Xu
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Müller @ 2017-09-06 20:10 UTC (permalink / raw)
To: herbert; +Cc: stable, linux-crypto
Am Mittwoch, 6. September 2017, 21:22:44 CEST schrieb Stephan M�ller:
Hi Herbert,
> With AF_ALG, AAD len and cryptlen can be set freely by unprivileged
> user space. The cipher implementation must therefore validate the input
> data for sanity. For AEAD ciphers, this implies that cryptlen must be
> at least as large as AAD size.
>
> This fixes a kernel crash that can be triggered via AF_ALG detected by
> the fuzzing test implemented with libkcapi.
What is your opinion: should this check be rather added to crypto_aead_encrypt
(similar to a sanity check found in crypto_aead_decrypt)?
Ciao
Stephan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: authenc - cryptlen must be at least AAD len
2017-09-06 20:10 ` Stephan Müller
@ 2017-09-07 3:54 ` Herbert Xu
2017-09-07 5:48 ` Stephan Müller
0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2017-09-07 3:54 UTC (permalink / raw)
To: Stephan Müller; +Cc: stable, linux-crypto
On Wed, Sep 06, 2017 at 10:10:08PM +0200, Stephan M�ller wrote:
> Am Mittwoch, 6. September 2017, 21:22:44 CEST schrieb Stephan M�ller:
>
> Hi Herbert,
>
> > With AF_ALG, AAD len and cryptlen can be set freely by unprivileged
> > user space. The cipher implementation must therefore validate the input
> > data for sanity. For AEAD ciphers, this implies that cryptlen must be
> > at least as large as AAD size.
> >
> > This fixes a kernel crash that can be triggered via AF_ALG detected by
> > the fuzzing test implemented with libkcapi.
>
> What is your opinion: should this check be rather added to crypto_aead_encrypt
> (similar to a sanity check found in crypto_aead_decrypt)?
Doesn't this apply to decryption as well? Perhaps we can simply
truncate assoclen in aead_request_set_ad.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: authenc - cryptlen must be at least AAD len
2017-09-07 3:54 ` Herbert Xu
@ 2017-09-07 5:48 ` Stephan Müller
2017-09-07 6:01 ` Herbert Xu
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Müller @ 2017-09-07 5:48 UTC (permalink / raw)
To: Herbert Xu; +Cc: stable, linux-crypto
Am Donnerstag, 7. September 2017, 05:54:05 CEST schrieb Herbert Xu:
Hi Herbert,
> >
> > What is your opinion: should this check be rather added to
> > crypto_aead_encrypt (similar to a sanity check found in
> > crypto_aead_decrypt)?
>
> Doesn't this apply to decryption as well?
There is already such check:
static inline int crypto_aead_decrypt(struct aead_request *req)
{
struct crypto_aead *aead = crypto_aead_reqtfm(req);
if (req->cryptlen < crypto_aead_authsize(aead))
return -EINVAL;
...
> Perhaps we can simply
> truncate assoclen in aead_request_set_ad.
I am not sure that would work because at the time we set the AAD len, we may
not yet have cryptlen. I.e. aead_request_set_ad may be called before
aead_request_set_crypt.
Ciao
Stephan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: authenc - cryptlen must be at least AAD len
2017-09-07 5:48 ` Stephan Müller
@ 2017-09-07 6:01 ` Herbert Xu
2017-09-07 6:04 ` Stephan Mueller
0 siblings, 1 reply; 7+ messages in thread
From: Herbert Xu @ 2017-09-07 6:01 UTC (permalink / raw)
To: Stephan Müller; +Cc: stable, linux-crypto
On Thu, Sep 07, 2017 at 07:48:53AM +0200, Stephan M�ller wrote:
>
> There is already such check:
>
> static inline int crypto_aead_decrypt(struct aead_request *req)
> {
> struct crypto_aead *aead = crypto_aead_reqtfm(req);
>
> if (req->cryptlen < crypto_aead_authsize(aead))
> return -EINVAL;
> ...
That doesn't check assoclen, does it?
> > Perhaps we can simply
> > truncate assoclen in aead_request_set_ad.
>
> I am not sure that would work because at the time we set the AAD len, we may
> not yet have cryptlen. I.e. aead_request_set_ad may be called before
> aead_request_set_crypt.
We can add the truncation in both places.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: authenc - cryptlen must be at least AAD len
2017-09-07 6:01 ` Herbert Xu
@ 2017-09-07 6:04 ` Stephan Mueller
2017-09-07 6:09 ` Herbert Xu
0 siblings, 1 reply; 7+ messages in thread
From: Stephan Mueller @ 2017-09-07 6:04 UTC (permalink / raw)
To: Herbert Xu; +Cc: stable, linux-crypto
Am Donnerstag, 7. September 2017, 08:01:08 CEST schrieb Herbert Xu:
Hi Herbert,
> On Thu, Sep 07, 2017 at 07:48:53AM +0200, Stephan M�ller wrote:
> > There is already such check:
> >
> > static inline int crypto_aead_decrypt(struct aead_request *req)
> > {
> >
> > struct crypto_aead *aead = crypto_aead_reqtfm(req);
> >
> > if (req->cryptlen < crypto_aead_authsize(aead))
> >
> > return -EINVAL;
> >
> > ...
>
> That doesn't check assoclen, does it?
Right, I mixed up the tag and the AAD, sorry for that.
>
> > > Perhaps we can simply
> > > truncate assoclen in aead_request_set_ad.
> >
> > I am not sure that would work because at the time we set the AAD len, we
> > may not yet have cryptlen. I.e. aead_request_set_ad may be called before
> > aead_request_set_crypt.
>
> We can add the truncation in both places.
I sill send a new patch -- shall I first send it excluding stable so that we
can review it before bothering the stable folks?
>
> Cheers,
Ciao
Stephan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] crypto: authenc - cryptlen must be at least AAD len
2017-09-07 6:04 ` Stephan Mueller
@ 2017-09-07 6:09 ` Herbert Xu
0 siblings, 0 replies; 7+ messages in thread
From: Herbert Xu @ 2017-09-07 6:09 UTC (permalink / raw)
To: Stephan Mueller; +Cc: stable, linux-crypto
On Thu, Sep 07, 2017 at 08:04:25AM +0200, Stephan Mueller wrote:
>
> I sill send a new patch -- shall I first send it excluding stable so that we
> can review it before bothering the stable folks?
You don't need to cc the email to stable@vger.kernel.org, just add
a Cc: tag in the patch description and it'll automatically go to
stable when it hits mainline.
Cheers,
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-09-07 6:09 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-06 19:22 [PATCH] crypto: authenc - cryptlen must be at least AAD len Stephan Müller
2017-09-06 20:10 ` Stephan Müller
2017-09-07 3:54 ` Herbert Xu
2017-09-07 5:48 ` Stephan Müller
2017-09-07 6:01 ` Herbert Xu
2017-09-07 6:04 ` Stephan Mueller
2017-09-07 6:09 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox