diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2006-12-10 10:45:28 +1100 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2007-02-07 09:20:58 +1100 |
commit | 39d18f6d8174abb5dc23bfb0342e472f2c8ef8ca (patch) | |
tree | b4bfa8ef802e807f6cbdcf80b6faa3d1cc194850 /crypto/xcbc.c | |
parent | cd5b1e3a795536ffb7e6450fbce75a363a9841a0 (diff) | |
download | linux-crypto-39d18f6d8174abb5dc23bfb0342e472f2c8ef8ca.tar.gz linux-crypto-39d18f6d8174abb5dc23bfb0342e472f2c8ef8ca.zip |
[CRYPTO] all: Check for usage in hard IRQ context
Using blkcipher/hash crypto operations in hard IRQ context can lead
to random memory corruption due to the reuse of kmap_atomic slots.
Since crypto operations were never meant to be used in hard IRQ
contexts, this patch checks for such usage and returns an error
before kmap_atomic is performed.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to '')
-rw-r--r-- | crypto/xcbc.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/crypto/xcbc.c b/crypto/xcbc.c index 9347eb6b..317e9f08 100644 --- a/crypto/xcbc.c +++ b/crypto/xcbc.c @@ -21,6 +21,7 @@ #include <linux/crypto.h> #include <linux/err.h> +#include <linux/hardirq.h> #include <linux/kernel.h> #include <linux/mm.h> #include <linux/rtnetlink.h> @@ -108,9 +109,9 @@ static int crypto_xcbc_digest_init(struct hash_desc *pdesc) return 0; } -static int crypto_xcbc_digest_update(struct hash_desc *pdesc, - struct scatterlist *sg, - unsigned int nbytes) +static int crypto_xcbc_digest_update2(struct hash_desc *pdesc, + struct scatterlist *sg, + unsigned int nbytes) { struct crypto_hash *parent = pdesc->tfm; struct crypto_xcbc_ctx *ctx = crypto_hash_ctx_aligned(parent); @@ -183,6 +184,15 @@ static int crypto_xcbc_digest_update(struct hash_desc *pdesc, return 0; } +static int crypto_xcbc_digest_update(struct hash_desc *pdesc, + struct scatterlist *sg, + unsigned int nbytes) +{ + if (WARN_ON_ONCE(in_irq())) + return -EDEADLK; + return crypto_xcbc_digest_update2(pdesc, sg, nbytes); +} + static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out) { struct crypto_hash *parent = pdesc->tfm; @@ -234,8 +244,11 @@ static int crypto_xcbc_digest_final(struct hash_desc *pdesc, u8 *out) static int crypto_xcbc_digest(struct hash_desc *pdesc, struct scatterlist *sg, unsigned int nbytes, u8 *out) { + if (WARN_ON_ONCE(in_irq())) + return -EDEADLK; + crypto_xcbc_digest_init(pdesc); - crypto_xcbc_digest_update(pdesc, sg, nbytes); + crypto_xcbc_digest_update2(pdesc, sg, nbytes); return crypto_xcbc_digest_final(pdesc, out); } |