diff options
author | Marcelo Cerri <mhcerri@linux.vnet.ibm.com> | 2013-08-12 17:49:37 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-08-14 06:42:04 -0400 |
commit | c849163b80c05f4567b1adef5db7f377460f88cd (patch) | |
tree | b7e3e40e463ed921040c1049212e40132103c536 /drivers/crypto/nx/nx-aes-cbc.c | |
parent | f22d08111a1d23f7432ee8d9c2dd637deb6963bd (diff) |
crypto: nx - fix concurrency issue
The NX driver uses the transformation context to store several fields
containing data related to the state of the operations in progress.
Since a single tfm can be used by different kernel threads at the same
time, we need to protect the data stored into the context.
This patch makes use of spin locks to protect the data where a race
condition can happen.
Reviewed-by: Fionnuala Gunter <fin@linux.vnet.ibm.com>
Reviewed-by: Joy Latten <jmlatten@linux.vnet.ibm.com>
Signed-off-by: Marcelo Cerri <mhcerri@linux.vnet.ibm.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'drivers/crypto/nx/nx-aes-cbc.c')
-rw-r--r-- | drivers/crypto/nx/nx-aes-cbc.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/crypto/nx/nx-aes-cbc.c b/drivers/crypto/nx/nx-aes-cbc.c index a2f99a910e4a..7c0237dae02d 100644 --- a/drivers/crypto/nx/nx-aes-cbc.c +++ b/drivers/crypto/nx/nx-aes-cbc.c | |||
@@ -70,10 +70,15 @@ static int cbc_aes_nx_crypt(struct blkcipher_desc *desc, | |||
70 | { | 70 | { |
71 | struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); | 71 | struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); |
72 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; | 72 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
73 | unsigned long irq_flags; | ||
73 | int rc; | 74 | int rc; |
74 | 75 | ||
75 | if (nbytes > nx_ctx->ap->databytelen) | 76 | spin_lock_irqsave(&nx_ctx->lock, irq_flags); |
76 | return -EINVAL; | 77 | |
78 | if (nbytes > nx_ctx->ap->databytelen) { | ||
79 | rc = -EINVAL; | ||
80 | goto out; | ||
81 | } | ||
77 | 82 | ||
78 | if (enc) | 83 | if (enc) |
79 | NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT; | 84 | NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT; |
@@ -100,6 +105,7 @@ static int cbc_aes_nx_crypt(struct blkcipher_desc *desc, | |||
100 | atomic64_add(csbcpb->csb.processed_byte_count, | 105 | atomic64_add(csbcpb->csb.processed_byte_count, |
101 | &(nx_ctx->stats->aes_bytes)); | 106 | &(nx_ctx->stats->aes_bytes)); |
102 | out: | 107 | out: |
108 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); | ||
103 | return rc; | 109 | return rc; |
104 | } | 110 | } |
105 | 111 | ||