[GIT] Crypto Fixes for 5.3

2019-07-18 Thread Herbert Xu
Hi Linus: This push fixes the following issues: - Fix missed wake-up race in padata. - Use crypto_memneq in ccp. - Fix version check in ccp. - Fix fuzz test failure in ccp. - Fix potential double free in crypto4xx. - Fix compile warning in stm32. The following changes since commit f3880a23564e

[PATCH v2 09/14] crypto: caam - keep both virtual and dma key addresses

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă Update alginfo struct to keep both virtual and dma key addresses, so that descriptors have them at hand. One example where this is needed is in the xcbc(aes) shared descriptors, which are updated in current patch. Another example is the upcoming fix for DKP. Signed-off-by: Hor

[PATCH v2 03/14] crypto: caam - update IV only when crypto operation succeeds

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă skcipher encryption might fail and in some cases, like (invalid) input length smaller then block size, updating the IV would lead to a useless IV copy in case hardware issued an error. Signed-off-by: Horia Geantă Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg

[PATCH v2 12/14] crypto: caam - execute module exit point only if necessary

2019-07-18 Thread Iuliana Prodan
Commit 1b46c90c8e00 ("crypto: caam - convert top level drivers to libraries") changed entry and exit points behavior for caamalg, caamalg_qi, caamalg_qi2, caamhash, caampkc, caamrng. For example, previously caam_pkc_init() and caam_pkc_exit() were module entry/exit points. This means that if an er

[PATCH v2 08/14] crypto: caam - update rfc4106 sh desc to support zero length input

2019-07-18 Thread Iuliana Prodan
Update share descriptor for rfc4106 to skip instructions in case cryptlen is zero. If no instructions are jumped the DECO hangs and a timeout error is thrown. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg_desc.c | 46 +- drivers/crypto/caam/caa

[PATCH v2 06/14] crypto: caam - check assoclen

2019-07-18 Thread Iuliana Prodan
Check assoclen to solve the extra tests that expect -EINVAL to be returned when the associated data size is not valid. Validated assoclen for RFC4106 and RFC4543 which expects an assoclen of 16 or 20. Based on seqiv, IPsec ESP and RFC4543/RFC4106 the assoclen is sizeof IP Header (spi, seq_no, exte

[PATCH v2 00/14] crypto: caam - fixes for kernel v5.3

2019-07-18 Thread Iuliana Prodan
The series solves: - the failures found with fuzz testing; - resources clean-up on caampkc/caamrng exit path. The first 10 patches solve the issues found with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS enabled. They modify the drivers to provide a valid error (and not the hardware error ID) to the user, vi

[PATCH v2 02/14] crypto: caam - fix return code in completion callbacks

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă Modify drive to provide a valid errno (and not the HW error ID) to the user, via completion callbacks. A "valid errno" is currently not explicitly mentioned in the docs, however the error code is expected to match the one returned by the generic SW implementation. Note: in mo

[PATCH v2 14/14] crypto: caam - change return value in case CAAM has no MDHA

2019-07-18 Thread Iuliana Prodan
To be consistent with other CAAM modules, caamhash should return 0 instead of -ENODEV in case CAAM has no MDHA. Based on commit 1b46c90c8e00 ("crypto: caam - convert top level drivers to libraries") the value returned by entry point is never checked and the exit point is always executed. Signed-

[PATCH v2 01/14] crypto: caam/qi - fix error handling in ERN handler

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă ERN handler calls the caam/qi frontend "done" callback with a status of -EIO. This is incorrect, since the callback expects a status value meaningful for the crypto engine - hence the cryptic messages like the one below: platform caam_qi: 15: unknown error source Fix this by p

[PATCH v2 05/14] crypto: caam - check authsize

2019-07-18 Thread Iuliana Prodan
Check authsize to solve the extra tests that expect -EINVAL to be returned when the authentication tag size is not valid. Validated authsize for GCM, RFC4106 and RFC4543. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 13 + drivers/crypto/caam/caamalg_qi.c |

[PATCH v2 11/14] crypto: caam - free resources in case caam_rng registration failed

2019-07-18 Thread Iuliana Prodan
Check the return value of the hardware registration for caam_rng and free resources in case of failure. Fixes: 6e4e603a9 ("crypto: caam - Dynamic memory allocation for caam_rng_ctx object") Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamrng.c | 5 - 1 file changed, 4 insertions(+

[PATCH v2 07/14] crypto: caam - check zero-length input

2019-07-18 Thread Iuliana Prodan
Check zero-length input, for skcipher algorithm, to solve the extra tests. This is a valid operation, therefore the API will return no error. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 6 ++ drivers/crypto/caam/caamalg_qi.c | 3 +++ drivers/crypto/caam/caamalg_qi2

[PATCH v2 13/14] crypto: caam - unregister algorithm only if the registration succeeded

2019-07-18 Thread Iuliana Prodan
To know if a registration succeeded added a new struct, caam_akcipher_alg, that keeps, also, the registration status. This status is updated in caam_pkc_init and verified in caam_pkc_exit to unregister an algorithm. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caampkc.c | 49 +++

[PATCH v2 10/14] crypto: caam - fix DKP for certain key lengths

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă DKP cannot be used with immediate input key if |user key| > |derived key|, since the resulting descriptor (after DKP execution) would be invalid - having a few bytes from user key left in descriptor buffer as incorrect opcodes. Fix DKP usage both in standalone hmac and in auth

[PATCH v2 04/14] crypto: caam - check key length

2019-07-18 Thread Iuliana Prodan
Check key length to solve the extra tests that expect -EINVAL to be returned when the key size is not valid. Validated AES keylen for skcipher and ahash. The check_aes_keylen function is added in a common file, to be used also for caam/qi and caam/qi2. Signed-off-by: Iuliana Prodan --- drivers

Re: [PATCH] crypto: ccp - Replace dma_pool_alloc + memset with dma_pool_zalloc

2019-07-18 Thread Gary R Hook
On 7/18/19 8:16 AM, Chuhong Yuan wrote: > Use dma_pool_zalloc instead of using dma_pool_alloc to allocate > memory and then zeroing it with memset 0. > This simplifies the code. > > Signed-off-by: Chuhong Yuan Acked-by: Gary R Hook > --- > drivers/crypto/ccp/ccp-ops.c | 3 +-- > 1 file chan

Re: [PATCH] crypto: aegis: fix badly optimized clang output

2019-07-18 Thread Arnd Bergmann
On Thu, Jul 18, 2019 at 11:17 PM 'Nick Desaulniers' via Clang Built Linux wrote: > On Thu, Jul 18, 2019 at 6:50 AM Arnd Bergmann wrote: > > diff --git a/crypto/aegis.h b/crypto/aegis.h > > index 41a3090cda8e..efed7251c49d 100644 > > --- a/crypto/aegis.h > > +++ b/crypto/aegis.h > > @@ -34,21 +34,

Re: [PATCH] crypto: aegis: fix badly optimized clang output

2019-07-18 Thread Nick Desaulniers
On Thu, Jul 18, 2019 at 6:50 AM Arnd Bergmann wrote: > > Clang sometimes makes very different inlining decisions from gcc. > In case of the aegis crypto algorithms, it decides to turn the innermost > primitives (and, xor, ...) into separate functions but inline most of > the rest. > > This results

Re: [PATCH] crypto: aegis: fix badly optimized clang output

2019-07-18 Thread Joe Perches
On Thu, 2019-07-18 at 15:50 +0200, Arnd Bergmann wrote: > Clang sometimes makes very different inlining decisions from gcc. > In case of the aegis crypto algorithms, it decides to turn the innermost > primitives (and, xor, ...) into separate functions but inline most of > the rest. > This results

Re: [PATCH] crypto: gcm - restrict assoclen for rfc4543

2019-07-18 Thread Herbert Xu
On Thu, Jul 18, 2019 at 10:59:07PM +0800, Herbert Xu wrote: > > So I presume the driver does enforce the limit. Please actually > state that in the commit description for future reference. Also have you looked at whether other drivers would be affected by this? It wouldn't be so nice if this cha

[v2 PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder

2019-07-18 Thread Herbert Xu
The function padata_reorder will use a timer when it cannot progress while completed jobs are outstanding (pd->reorder_objects > 0). This is suboptimal as if we do end up using the timer then it would have introduced a gratuitous delay of one second. In fact we can easily distinguish between whet

Re: [PATCH 03/14] crypto: caam - update IV only when crypto operation succeeds

2019-07-18 Thread Horia Geanta
On 7/18/2019 5:45 PM, Iuliana Prodan wrote: > From: Horia Geantă > > skcipher encryption might fail and in some cases, like (invalid) input > length smaller then block size, updating the IV would lead to panic > due to copying from a negative offset (req->cryptlen - ivsize). > The commit message

Re: [PATCH] crypto: gcm - restrict assoclen for rfc4543

2019-07-18 Thread Herbert Xu
On Thu, Jul 18, 2019 at 02:56:35PM +, Iuliana Prodan wrote: > > Yes, this is for fuzz testing. > The generic implementation for rfc4543 considers any assoclen valid, > which is not correct. So I presume the driver does enforce the limit. Please actually state that in the commit description f

Re: [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder

2019-07-18 Thread Herbert Xu
On Thu, Jul 18, 2019 at 10:27:30AM -0400, Daniel Jordan wrote: > > That's what I expected when I first saw it too, but nr_cpumask_bits is > returned > to signal the end of the iteration. The patch always passes 0 for the 'start' > argument, so when cpumask_next_wrap is called with the last cpu in

Re: [PATCH] crypto: gcm - restrict assoclen for rfc4543

2019-07-18 Thread Iuliana Prodan
On 7/18/2019 5:46 PM, Herbert Xu wrote: > On Thu, Jul 18, 2019 at 05:43:04PM +0300, Iuliana Prodan wrote: >> Based on seqiv, IPsec ESP and rfc4543/rfc4106 the assoclen can be 16 or >> 20 bytes. >> >> >From esp4/esp6, assoclen is sizeof IP Header. This includes spi, seq_no >> and extended seq_no, th

Re: [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder

2019-07-18 Thread Herbert Xu
On Thu, Jul 18, 2019 at 10:25:15AM -0400, Daniel Jordan wrote: > > Which memory barrier do you mean? I think you're referring to the one that > atomic_inc might provide? If so, the memory model maintainers can correct me > here, but my understanding is that RMW atomic ops that don't return values

[PATCH] crypto: caam - move shared symbols in a common location

2019-07-18 Thread Iuliana Prodan
Moved to a common location the symbols shared by all CAAM drivers (jr, qi, qi2). Signed-off-by: Iuliana Prodan --- This patch depends on series: https://patchwork.kernel.org/project/linux-crypto/list/?series=147479 drivers/crypto/caam/common_if.c | 7 +++ drivers/crypto/caam/common_if.h | 7

Re: [PATCH] crypto: gcm - restrict assoclen for rfc4543

2019-07-18 Thread Herbert Xu
On Thu, Jul 18, 2019 at 05:43:04PM +0300, Iuliana Prodan wrote: > Based on seqiv, IPsec ESP and rfc4543/rfc4106 the assoclen can be 16 or > 20 bytes. > > >From esp4/esp6, assoclen is sizeof IP Header. This includes spi, seq_no > and extended seq_no, that is 8 or 12 bytes. > In seqiv, to asscolen i

[PATCH 05/14] crypto: caam - check authsize

2019-07-18 Thread Iuliana Prodan
Check authsize to solve the extra tests that expect -EINVAL to be returned when the authentication tag size is not valid. Validated authsize for GCM, RFC4106 and RFC4543. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 13 + drivers/crypto/caam/caamalg_qi.c |

[PATCH 13/14] crypto: caam - unregister algorithm only if the registration succeeded

2019-07-18 Thread Iuliana Prodan
To know if a registration succeeded added a new struct, caam_akcipher_alg, that keeps, also, the registration status. This status is updated in caam_pkc_init and verified in caam_pkc_exit to unregister an algorithm. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caampkc.c | 49 +++

[PATCH 12/14] crypto: caam - execute module exit point only if necessary

2019-07-18 Thread Iuliana Prodan
Commit 1b46c90c8e00 ("crypto: caam - convert top level drivers to libraries") changed entry and exit points behavior for caamalg, caamalg_qi, caamalg_qi2, caamhash, caampkc, caamrng. For example, previously caam_pkc_init() and caam_pkc_exit() were module entry/exit points. This means that if an er

[PATCH 01/14] crypto: caam/qi - fix error handling in ERN handler

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă ERN handler calls the caam/qi frontend "done" callback with a status of -EIO. This is incorrect, since the callback expects a status value meaningful for the crypto engine - hence the cryptic messages like the one below: platform caam_qi: 15: unknown error source Fix this by p

[PATCH 06/14] crypto: caam - check assoclen

2019-07-18 Thread Iuliana Prodan
Check assoclen to solve the extra tests that expect -EINVAL to be returned when the associated data size is not valid. Validated assoclen for RFC4106 and RFC4543 which expects an assoclen of 16 or 20. Based on seqiv, IPsec ESP and RFC4543/RFC4106 the assoclen is sizeof IP Header (spi, seq_no, exte

[PATCH 02/14] crypto: caam - fix return code in completion callbacks

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă Modify drive to provide a valid errno (and not the HW error ID) to the user, via completion callbacks. A "valid errno" is currently not explicitly mentioned in the docs, however the error code is expected to match the one returned by the generic SW implementation. Note: in mo

[PATCH 07/14] crypto: caam - check zero-length input

2019-07-18 Thread Iuliana Prodan
Check zero-length input, for skcipher algorithm, to solve the extra tests. This is a valid operation, therefore the API will return no error. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg.c | 6 ++ drivers/crypto/caam/caamalg_qi.c | 3 +++ drivers/crypto/caam/caamalg_qi2

[PATCH 10/14] crypto: caam - fix DKP for certain key lengths

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă DKP cannot be used with immediate input key if |user key| > |derived key|, since the resulting descriptor (after DKP execution) would be invalid - having a few bytes from user key left in descriptor buffer as incorrect opcodes. Fix DKP usage both in standalone hmac and in auth

[PATCH 09/14] crypto: caam - keep both virtual and dma key addresses

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă Update alginfo struct to keep both virtual and dma key addresses, so that descriptors have them at hand. One example where this is needed is in the xcbc(aes) shared descriptors, which are updated in current patch. Another example is the upcoming fix for DKP. Signed-off-by: Hor

[PATCH 14/14] crypto: caam - change return value in case CAAM has no MDHA

2019-07-18 Thread Iuliana Prodan
To be consistent with other CAAM modules, caamhash should return 0 instead of -ENODEV in case CAAM has no MDHA. Based on commit 1b46c90c8e00 ("crypto: caam - convert top level drivers to libraries") the value returned by entry point is never checked and the exit point is always executed. Signed-

[PATCH 08/14] crypto: caam - update rfc4106 sh desc to support zero length input

2019-07-18 Thread Iuliana Prodan
Update share descriptor for rfc4106 to skip instructions in case cryptlen is zero. If no instructions are jumped the DECO hangs and a timeout error is thrown. Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamalg_desc.c | 46 +- drivers/crypto/caam/caa

[PATCH 11/14] crypto: caam - free resources in case caam_rng registration failed

2019-07-18 Thread Iuliana Prodan
Check the return value of the hardware registration for caam_rng and free resources in case of failure. Fixes: 6e4e603a9 ("crypto: caam - Dynamic memory allocation for caam_rng_ctx object") Signed-off-by: Iuliana Prodan --- drivers/crypto/caam/caamrng.c | 5 - 1 file changed, 4 insertions(+

[PATCH 03/14] crypto: caam - update IV only when crypto operation succeeds

2019-07-18 Thread Iuliana Prodan
From: Horia Geantă skcipher encryption might fail and in some cases, like (invalid) input length smaller then block size, updating the IV would lead to panic due to copying from a negative offset (req->cryptlen - ivsize). Signed-off-by: Horia Geantă Signed-off-by: Iuliana Prodan --- drivers/c

[PATCH 04/14] crypto: caam - check key length

2019-07-18 Thread Iuliana Prodan
Check key length to solve the extra tests that expect -EINVAL to be returned when the key size is not valid. Validated AES keylen for skcipher and ahash. The check_aes_keylen function is added in a common file, to be used also for caam/qi and caam/qi2. Signed-off-by: Iuliana Prodan --- drivers

[PATCH 00/14] crypto: caam - fixes for kernel v5.3

2019-07-18 Thread Iuliana Prodan
The series solves: - the failures found with fuzz testing; - resources clean-up on caampkc/caamrng exit path. The first 10 patches solve the issues found with CONFIG_CRYPTO_MANAGER_EXTRA_TESTS enabled. They modify the drivers to provide a valid error (and not the hardware error ID) to the user, vi

[PATCH] crypto: gcm - restrict assoclen for rfc4543

2019-07-18 Thread Iuliana Prodan
Based on seqiv, IPsec ESP and rfc4543/rfc4106 the assoclen can be 16 or 20 bytes. >From esp4/esp6, assoclen is sizeof IP Header. This includes spi, seq_no and extended seq_no, that is 8 or 12 bytes. In seqiv, to asscolen is added the IV size (8 bytes). Therefore, the assoclen, for rfc4543, should

Re: [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder

2019-07-18 Thread Daniel Jordan
On Thu, Jul 18, 2019 at 11:31:31AM +0800, Herbert Xu wrote: > On Wed, Jul 17, 2019 at 02:32:27PM -0400, Daniel Jordan wrote: > > > > We'll crash when cpumask_next_wrap returns nr_cpumask_bits and later try to > > get > > the corresponding per-cpu queue. > > The whole point of cpumask_next_wrap is

Re: [PATCH] padata: Replace delayed timer with immediate workqueue in padata_reorder

2019-07-18 Thread Daniel Jordan
On Thu, Jul 18, 2019 at 11:30:08AM +0800, Herbert Xu wrote: > On Wed, Jul 17, 2019 at 07:21:36PM -0400, Daniel Jordan wrote: > > > > > @@ -388,12 +336,12 @@ void padata_do_serial(struct padata_priv *padata) > > > pqueue = per_cpu_ptr(pd->pqueue, cpu); > > > > > > spin_lock(&pqueue->reorder.lo

[PATCH] crypto: aegis: fix badly optimized clang output

2019-07-18 Thread Arnd Bergmann
Clang sometimes makes very different inlining decisions from gcc. In case of the aegis crypto algorithms, it decides to turn the innermost primitives (and, xor, ...) into separate functions but inline most of the rest. This results in a huge amount of variables spilled on the stack, leading to rat

[PATCH] crypto: ccp - Replace dma_pool_alloc + memset with dma_pool_zalloc

2019-07-18 Thread Chuhong Yuan
Use dma_pool_zalloc instead of using dma_pool_alloc to allocate memory and then zeroing it with memset 0. This simplifies the code. Signed-off-by: Chuhong Yuan --- drivers/crypto/ccp/ccp-ops.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/crypto/ccp/ccp-ops.c b/dr

[PATCH] crypto: caam/qi2 - Increase napi budget to process more caam responses

2019-07-18 Thread Vakul Garg
While running ipsec processing for traffic through multiple network interfaces, it is observed that caam driver gets less time to poll responses from caam block compared to ethernet driver. This is because ethernet driver has as many napi instances per cpu as the number of ethernet interfaces in sy

[RFC/RFT v2 1/2] KEYS: trusted: create trusted keys subsystem

2019-07-18 Thread Sumit Garg
Move existing code to trusted keys subsystem. Also, rename files with "tpm" as suffix which provides the underlying implementation. Suggested-by: Jarkko Sakkinen Signed-off-by: Sumit Garg --- crypto/asymmetric_keys/asym_tpm.c | 2 +- include/keys/{trusted.h => trusted_tpm.

[RFC/RFT v2 2/2] KEYS: trusted: Add generic trusted keys framework

2019-07-18 Thread Sumit Garg
Current trusted keys framework is tightly coupled to use TPM device as an underlying implementation which makes it difficult for implementations like Trusted Execution Environment (TEE) etc. to provide trusked keys support in case platform doesn't posses a TPM device. So this patch tries to add ge

[RFC/RFT v2 0/2] KEYS: trusted: Add generic trusted keys framework

2019-07-18 Thread Sumit Garg
This patch-set is an outcome of discussion here [1]. I have tested this framework with trusted keys support provided via TEE but I wasn't able to test it with a TPM device as I don't possess one. It would be really helpful if others could test this patch-set using a TPM device. [1] https://www.ma