Re: [PATCH -stable 1/2] crypto: hash - annotate algorithms taking optional key

2018-02-22 Thread Greg Kroah-Hartman
On Thu, Feb 22, 2018 at 02:50:10PM -0800, Eric Biggers wrote:
> From: Eric Biggers 
> 
> commit a208fa8f33031b9e0aba44c7d1b7e68eb0cbd29e upstream.
> [Please apply to 4.9-stable.]

Both now applied, thanks for the backports.

greg k-h



[PATCH -stable 1/2] crypto: hash - annotate algorithms taking optional key

2018-02-22 Thread Eric Biggers
From: Eric Biggers 

commit a208fa8f33031b9e0aba44c7d1b7e68eb0cbd29e upstream.
[Please apply to 4.9-stable.]

We need to consistently enforce that keyed hashes cannot be used without
setting the key.  To do this we need a reliable way to determine whether
a given hash algorithm is keyed or not.  AF_ALG currently does this by
checking for the presence of a ->setkey() method.  However, this is
actually slightly broken because the CRC-32 algorithms implement
->setkey() but can also be used without a key.  (The CRC-32 "key" is not
actually a cryptographic key but rather represents the initial state.
If not overridden, then a default initial state is used.)

Prepare to fix this by introducing a flag CRYPTO_ALG_OPTIONAL_KEY which
indicates that the algorithm has a ->setkey() method, but it is not
required to be called.  Then set it on all the CRC-32 algorithms.

The same also applies to the Adler-32 implementation in Lustre.

Also, the cryptd and mcryptd templates have to pass through the flag
from their underlying algorithm.

Cc: sta...@vger.kernel.org
Signed-off-by: Eric Biggers 
Signed-off-by: Herbert Xu 
---
 arch/arm64/crypto/crc32-arm64.c| 2 ++
 arch/powerpc/crypto/crc32c-vpmsum_glue.c   | 1 +
 arch/s390/crypto/crc32-vx.c| 3 +++
 arch/sparc/crypto/crc32c_glue.c| 1 +
 arch/x86/crypto/crc32-pclmul_glue.c| 1 +
 arch/x86/crypto/crc32c-intel_glue.c| 1 +
 crypto/crc32_generic.c | 1 +
 crypto/crc32c_generic.c| 1 +
 crypto/cryptd.c| 7 +++
 crypto/mcryptd.c   | 7 +++
 drivers/crypto/bfin_crc.c  | 3 ++-
 .../staging/lustre/lnet/libcfs/linux/linux-crypto-adler.c  | 1 +
 include/linux/crypto.h | 6 ++
 13 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/arch/arm64/crypto/crc32-arm64.c b/arch/arm64/crypto/crc32-arm64.c
index 6a37c3c6b11d..3ec568afd1d3 100644
--- a/arch/arm64/crypto/crc32-arm64.c
+++ b/arch/arm64/crypto/crc32-arm64.c
@@ -232,6 +232,7 @@ static struct shash_alg crc32_alg = {
.cra_name   =   "crc32",
.cra_driver_name=   "crc32-arm64-hw",
.cra_priority   =   300,
+   .cra_flags  =   CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize  =   CHKSUM_BLOCK_SIZE,
.cra_alignmask  =   0,
.cra_ctxsize=   sizeof(struct chksum_ctx),
@@ -253,6 +254,7 @@ static struct shash_alg crc32c_alg = {
.cra_name   =   "crc32c",
.cra_driver_name=   "crc32c-arm64-hw",
.cra_priority   =   300,
+   .cra_flags  =   CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize  =   CHKSUM_BLOCK_SIZE,
.cra_alignmask  =   0,
.cra_ctxsize=   sizeof(struct chksum_ctx),
diff --git a/arch/powerpc/crypto/crc32c-vpmsum_glue.c 
b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
index f058e0c3e4d4..fd1d6c83f0c0 100644
--- a/arch/powerpc/crypto/crc32c-vpmsum_glue.c
+++ b/arch/powerpc/crypto/crc32c-vpmsum_glue.c
@@ -141,6 +141,7 @@ static struct shash_alg alg = {
.cra_name   = "crc32c",
.cra_driver_name= "crc32c-vpmsum",
.cra_priority   = 200,
+   .cra_flags  = CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize  = CHKSUM_BLOCK_SIZE,
.cra_ctxsize= sizeof(u32),
.cra_module = THIS_MODULE,
diff --git a/arch/s390/crypto/crc32-vx.c b/arch/s390/crypto/crc32-vx.c
index 992e630c227b..6f4985f357c6 100644
--- a/arch/s390/crypto/crc32-vx.c
+++ b/arch/s390/crypto/crc32-vx.c
@@ -238,6 +238,7 @@ static struct shash_alg crc32_vx_algs[] = {
.cra_name= "crc32",
.cra_driver_name = "crc32-vx",
.cra_priority= 200,
+   .cra_flags   = CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize   = CRC32_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crc_ctx),
.cra_module  = THIS_MODULE,
@@ -258,6 +259,7 @@ static struct shash_alg crc32_vx_algs[] = {
.cra_name= "crc32be",
.cra_driver_name = "crc32be-vx",
.cra_priority= 200,
+   .cra_flags   = CRYPTO_ALG_OPTIONAL_KEY,
.cra_blocksize   = CRC32_BLOCK_SIZE,
.cra_ctxsize = sizeof(struct crc_c