diff options
author | Marcelo Cerri <mhcerri@linux.vnet.ibm.com> | 2013-08-12 18:49:37 -0300 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2013-08-14 20:42:04 +1000 |
commit | c849163b80c05f4567b1adef5db7f377460f88cd (patch) | |
tree | b7e3e40e463ed921040c1049212e40132103c536 /drivers/crypto/nx/nx-aes-xcbc.c | |
parent | f22d08111a1d23f7432ee8d9c2dd637deb6963bd (diff) | |
download | lwn-c849163b80c05f4567b1adef5db7f377460f88cd.tar.gz lwn-c849163b80c05f4567b1adef5db7f377460f88cd.zip |
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-xcbc.c')
-rw-r--r-- | drivers/crypto/nx/nx-aes-xcbc.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/crypto/nx/nx-aes-xcbc.c b/drivers/crypto/nx/nx-aes-xcbc.c index 93923e4628c0..658da0fd3e1f 100644 --- a/drivers/crypto/nx/nx-aes-xcbc.c +++ b/drivers/crypto/nx/nx-aes-xcbc.c @@ -89,8 +89,11 @@ static int nx_xcbc_update(struct shash_desc *desc, struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; struct nx_sg *in_sg; u32 to_process, leftover; + unsigned long irq_flags; int rc = 0; + spin_lock_irqsave(&nx_ctx->lock, irq_flags); + if (NX_CPB_FDM(csbcpb) & NX_FDM_CONTINUATION) { /* we've hit the nx chip previously and we're updating again, * so copy over the partial digest */ @@ -158,6 +161,7 @@ static int nx_xcbc_update(struct shash_desc *desc, /* everything after the first update is continuation */ NX_CPB_FDM(csbcpb) |= NX_FDM_CONTINUATION; out: + spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); return rc; } @@ -167,8 +171,11 @@ static int nx_xcbc_final(struct shash_desc *desc, u8 *out) struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(&desc->tfm->base); struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; struct nx_sg *in_sg, *out_sg; + unsigned long irq_flags; int rc = 0; + spin_lock_irqsave(&nx_ctx->lock, irq_flags); + if (NX_CPB_FDM(csbcpb) & NX_FDM_CONTINUATION) { /* we've hit the nx chip previously, now we're finalizing, * so copy over the partial digest */ @@ -211,6 +218,7 @@ static int nx_xcbc_final(struct shash_desc *desc, u8 *out) memcpy(out, csbcpb->cpb.aes_xcbc.out_cv_mac, AES_BLOCK_SIZE); out: + spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); return rc; } |