From: Sebastian Andrzej Siewior <linux-crypto@ml.breakpoint.cc>
To: Neil Horman <nhorman@tuxdriver.com>
Cc: Sebastian Andrzej Siewior <linux-crypto@ml.breakpoint.cc>,
herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org,
davem@davemloft.net,
Eric Sesterhenn <eric.sesterhenn@lsexperts.de>
Subject: [PATCH 1/2] crypto/ansi prng: use just a BH lock
Date: Mon, 29 Jun 2009 23:44:30 +0200 [thread overview]
Message-ID: <20090629214430.GA29616@Chamillionaire.breakpoint.cc> (raw)
In-Reply-To: <20090629152027.GA5022@hmsreliant.think-freely.org>
From: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
the current code uses a mix of sping_lock() & spin_lock_irqsave(). This can
lead to deadlock with the correct timming & cprng_get_random() + cprng_reset()
sequence.
I've converted them to bottom half locks since all three user grab just a BH
lock so this runs probably in softirq :)
Signed-off-by: Sebastian Andrzej Siewior <sebastian@breakpoint.cc>
---
crypto/ansi_cprng.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index d80ed4c..ff00b58 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -187,7 +187,6 @@ static int _get_more_prng_bytes(struct prng_context *ctx)
/* Our exported functions */
static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx)
{
- unsigned long flags;
unsigned char *ptr = buf;
unsigned int byte_count = (unsigned int)nbytes;
int err;
@@ -196,7 +195,7 @@ static int get_prng_bytes(char *buf, size_t nbytes, struct prng_context *ctx)
if (nbytes < 0)
return -EINVAL;
- spin_lock_irqsave(&ctx->prng_lock, flags);
+ spin_lock_bh(&ctx->prng_lock);
err = -EINVAL;
if (ctx->flags & PRNG_NEED_RESET)
@@ -268,7 +267,7 @@ empty_rbuf:
goto remainder;
done:
- spin_unlock_irqrestore(&ctx->prng_lock, flags);
+ spin_unlock_bh(&ctx->prng_lock);
dbgprint(KERN_CRIT "returning %d from get_prng_bytes in context %p\n",
err, ctx);
return err;
@@ -287,7 +286,7 @@ static int reset_prng_context(struct prng_context *ctx,
int rc = -EINVAL;
unsigned char *prng_key;
- spin_lock(&ctx->prng_lock);
+ spin_lock_bh(&ctx->prng_lock);
ctx->flags |= PRNG_NEED_RESET;
prng_key = (key != NULL) ? key : (unsigned char *)DEFAULT_PRNG_KEY;
@@ -332,7 +331,7 @@ static int reset_prng_context(struct prng_context *ctx,
rc = 0;
ctx->flags &= ~PRNG_NEED_RESET;
out:
- spin_unlock(&ctx->prng_lock);
+ spin_unlock_bh(&ctx->prng_lock);
return rc;
--
1.6.3.3
next prev parent reply other threads:[~2009-06-29 21:44 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-29 13:17 Bug when modprobing tcrypt Eric Sesterhenn
2009-06-29 14:07 ` Sebastian Andrzej Siewior
2009-06-29 15:20 ` Neil Horman
2009-06-29 21:44 ` Sebastian Andrzej Siewior [this message]
2009-06-30 14:14 ` [PATCH 1/2] crypto/ansi prng: use just a BH lock Neil Horman
2009-06-29 21:45 ` [PATCH 2/2] crypto/ansi prng: alloc cipher just in in init() Sebastian Andrzej Siewior
2009-06-29 21:48 ` Sebastian Andrzej Siewior
2009-06-29 21:54 ` Neil Horman
2009-06-30 14:51 ` Neil Horman
2009-06-30 19:55 ` [PATCH v2] " Sebastian Andrzej Siewior
2009-07-01 0:06 ` Neil Horman
[not found] ` <20090701072517.GA9583@Chamillionaire.breakpoint.cc>
2009-07-01 10:36 ` Neil Horman
2009-07-03 4:11 ` Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090629214430.GA29616@Chamillionaire.breakpoint.cc \
--to=linux-crypto@ml.breakpoint.cc \
--cc=davem@davemloft.net \
--cc=eric.sesterhenn@lsexperts.de \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox