Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key
@ 2020-03-13 11:02 Torsten Duwe
  2020-03-17 22:17 ` Will Deacon
  2020-03-20  3:51 ` Herbert Xu
  0 siblings, 2 replies; 5+ messages in thread
From: Torsten Duwe @ 2020-03-13 11:02 UTC (permalink / raw)
  To: Catalin Marinas, Will Deacon
  Cc: Herbert Xu, David S. Miller, Russell King, linux-crypto,
	linux-arm-kernel, linux-kernel

From: Torsten Duwe <duwe@suse.de>

At function exit, do not leave the expanded key in the rk struct
which got allocated on the stack.

Signed-off-by: Torsten Duwe <duwe@suse.de>
---
Another small fix from our FIPS evaluation. I hope you don't mind I merged
arm32 and arm64 into one patch -- this is really simple.
--- a/arch/arm/crypto/aes-neonbs-glue.c
+++ b/arch/arm/crypto/aes-neonbs-glue.c
@@ -138,6 +138,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
 	kernel_neon_begin();
 	aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
 	kernel_neon_end();
+	memzero_explicit(&rk, sizeof(rk));
 
 	return crypto_cipher_setkey(ctx->enc_tfm, in_key, key_len);
 }
diff --git a/arch/arm64/crypto/aes-neonbs-glue.c b/arch/arm64/crypto/aes-neonbs-glue.c
index e3e27349a9fe..c0b980503643 100644
--- a/arch/arm64/crypto/aes-neonbs-glue.c
+++ b/arch/arm64/crypto/aes-neonbs-glue.c
@@ -151,6 +151,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
 	kernel_neon_begin();
 	aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
 	kernel_neon_end();
+	memzero_explicit(&rk, sizeof(rk));
 
 	return 0;
 }

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key
  2020-03-13 11:02 [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key Torsten Duwe
@ 2020-03-17 22:17 ` Will Deacon
  2020-03-18 20:13   ` Ard Biesheuvel
  2020-03-20  3:51 ` Herbert Xu
  1 sibling, 1 reply; 5+ messages in thread
From: Will Deacon @ 2020-03-17 22:17 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Catalin Marinas, Herbert Xu, David S. Miller, Russell King,
	linux-crypto, linux-arm-kernel, linux-kernel, ardb

[+Ard]

On Fri, Mar 13, 2020 at 12:02:58PM +0100, Torsten Duwe wrote:
> From: Torsten Duwe <duwe@suse.de>
> 
> At function exit, do not leave the expanded key in the rk struct
> which got allocated on the stack.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>
> ---
> Another small fix from our FIPS evaluation. I hope you don't mind I merged
> arm32 and arm64 into one patch -- this is really simple.
> --- a/arch/arm/crypto/aes-neonbs-glue.c
> +++ b/arch/arm/crypto/aes-neonbs-glue.c
> @@ -138,6 +138,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
>  	kernel_neon_begin();
>  	aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
>  	kernel_neon_end();
> +	memzero_explicit(&rk, sizeof(rk));
>  
>  	return crypto_cipher_setkey(ctx->enc_tfm, in_key, key_len);
>  }
> diff --git a/arch/arm64/crypto/aes-neonbs-glue.c b/arch/arm64/crypto/aes-neonbs-glue.c
> index e3e27349a9fe..c0b980503643 100644
> --- a/arch/arm64/crypto/aes-neonbs-glue.c
> +++ b/arch/arm64/crypto/aes-neonbs-glue.c
> @@ -151,6 +151,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
>  	kernel_neon_begin();
>  	aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
>  	kernel_neon_end();
> +	memzero_explicit(&rk, sizeof(rk));
>  
>  	return 0;
>  }

I'm certainly not a crypto person, but this looks sensible to me and I
couldn't find any other similar stack variable usage under
arch/arm64/crypto/ at a quick glance.

Acked-by: Will Deacon <will@kernel.org>

Will

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key
  2020-03-17 22:17 ` Will Deacon
@ 2020-03-18 20:13   ` Ard Biesheuvel
  2020-03-19  8:15     ` Will Deacon
  0 siblings, 1 reply; 5+ messages in thread
From: Ard Biesheuvel @ 2020-03-18 20:13 UTC (permalink / raw)
  To: Will Deacon
  Cc: Torsten Duwe, Catalin Marinas, Herbert Xu, David S. Miller,
	Russell King, open list:HARDWARE RANDOM NUMBER GENERATOR CORE,
	linux-arm-kernel, Linux Kernel Mailing List

On Tue, 17 Mar 2020 at 18:17, Will Deacon <will@kernel.org> wrote:
>
> [+Ard]
>
> On Fri, Mar 13, 2020 at 12:02:58PM +0100, Torsten Duwe wrote:
> > From: Torsten Duwe <duwe@suse.de>
> >
> > At function exit, do not leave the expanded key in the rk struct
> > which got allocated on the stack.
> >
> > Signed-off-by: Torsten Duwe <duwe@suse.de>
> > ---
> > Another small fix from our FIPS evaluation. I hope you don't mind I merged
> > arm32 and arm64 into one patch -- this is really simple.
> > --- a/arch/arm/crypto/aes-neonbs-glue.c
> > +++ b/arch/arm/crypto/aes-neonbs-glue.c
> > @@ -138,6 +138,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
> >       kernel_neon_begin();
> >       aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
> >       kernel_neon_end();
> > +     memzero_explicit(&rk, sizeof(rk));
> >
> >       return crypto_cipher_setkey(ctx->enc_tfm, in_key, key_len);
> >  }
> > diff --git a/arch/arm64/crypto/aes-neonbs-glue.c b/arch/arm64/crypto/aes-neonbs-glue.c
> > index e3e27349a9fe..c0b980503643 100644
> > --- a/arch/arm64/crypto/aes-neonbs-glue.c
> > +++ b/arch/arm64/crypto/aes-neonbs-glue.c
> > @@ -151,6 +151,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
> >       kernel_neon_begin();
> >       aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
> >       kernel_neon_end();
> > +     memzero_explicit(&rk, sizeof(rk));
> >
> >       return 0;
> >  }
>
> I'm certainly not a crypto person, but this looks sensible to me and I
> couldn't find any other similar stack variable usage under
> arch/arm64/crypto/ at a quick glance.
>
> Acked-by: Will Deacon <will@kernel.org>
>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key
  2020-03-18 20:13   ` Ard Biesheuvel
@ 2020-03-19  8:15     ` Will Deacon
  0 siblings, 0 replies; 5+ messages in thread
From: Will Deacon @ 2020-03-19  8:15 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Torsten Duwe, Catalin Marinas, Herbert Xu, David S. Miller,
	Russell King, open list:HARDWARE RANDOM NUMBER GENERATOR CORE,
	linux-arm-kernel, Linux Kernel Mailing List

On Wed, Mar 18, 2020 at 04:13:33PM -0400, Ard Biesheuvel wrote:
> On Tue, 17 Mar 2020 at 18:17, Will Deacon <will@kernel.org> wrote:
> >
> > [+Ard]
> >
> > On Fri, Mar 13, 2020 at 12:02:58PM +0100, Torsten Duwe wrote:
> > > From: Torsten Duwe <duwe@suse.de>
> > >
> > > At function exit, do not leave the expanded key in the rk struct
> > > which got allocated on the stack.
> > >
> > > Signed-off-by: Torsten Duwe <duwe@suse.de>
> > > ---
> > > Another small fix from our FIPS evaluation. I hope you don't mind I merged
> > > arm32 and arm64 into one patch -- this is really simple.
> > > --- a/arch/arm/crypto/aes-neonbs-glue.c
> > > +++ b/arch/arm/crypto/aes-neonbs-glue.c
> > > @@ -138,6 +138,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
> > >       kernel_neon_begin();
> > >       aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
> > >       kernel_neon_end();
> > > +     memzero_explicit(&rk, sizeof(rk));
> > >
> > >       return crypto_cipher_setkey(ctx->enc_tfm, in_key, key_len);
> > >  }
> > > diff --git a/arch/arm64/crypto/aes-neonbs-glue.c b/arch/arm64/crypto/aes-neonbs-glue.c
> > > index e3e27349a9fe..c0b980503643 100644
> > > --- a/arch/arm64/crypto/aes-neonbs-glue.c
> > > +++ b/arch/arm64/crypto/aes-neonbs-glue.c
> > > @@ -151,6 +151,7 @@ static int aesbs_cbc_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
> > >       kernel_neon_begin();
> > >       aesbs_convert_key(ctx->key.rk, rk.key_enc, ctx->key.rounds);
> > >       kernel_neon_end();
> > > +     memzero_explicit(&rk, sizeof(rk));
> > >
> > >       return 0;
> > >  }
> >
> > I'm certainly not a crypto person, but this looks sensible to me and I
> > couldn't find any other similar stack variable usage under
> > arch/arm64/crypto/ at a quick glance.
> >
> > Acked-by: Will Deacon <will@kernel.org>
> >
> 
> Acked-by: Ard Biesheuvel <ardb@kernel.org>

Cheers, Ard. I'm assuming that Herbert will pick this up via the crypto
tree.

Will

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key
  2020-03-13 11:02 [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key Torsten Duwe
  2020-03-17 22:17 ` Will Deacon
@ 2020-03-20  3:51 ` Herbert Xu
  1 sibling, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2020-03-20  3:51 UTC (permalink / raw)
  To: Torsten Duwe
  Cc: Catalin Marinas, Will Deacon, David S. Miller, Russell King,
	linux-crypto, linux-arm-kernel, linux-kernel

On Fri, Mar 13, 2020 at 12:02:58PM +0100, Torsten Duwe wrote:
> From: Torsten Duwe <duwe@suse.de>
> 
> At function exit, do not leave the expanded key in the rk struct
> which got allocated on the stack.
> 
> Signed-off-by: Torsten Duwe <duwe@suse.de>

Patch applied.  Thanks.
-- 
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] 5+ messages in thread

end of thread, back to index

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 11:02 [Patch][Fix] crypto: arm{,64} neon: memzero_explicit aes-cbc key Torsten Duwe
2020-03-17 22:17 ` Will Deacon
2020-03-18 20:13   ` Ard Biesheuvel
2020-03-19  8:15     ` Will Deacon
2020-03-20  3:51 ` Herbert Xu

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git