2012-10-21 17:42:31

by Jussi Kivilinna

[permalink] [raw]
Subject: [PATCH] [v2] crypto: cryptd - disable softirqs in cryptd_queue_worker to prevent data corruption

cryptd_queue_worker attempts to prevent simultaneous accesses to crypto
workqueue by cryptd_enqueue_request using preempt_disable/preempt_enable.
However cryptd_enqueue_request might be called from softirq context,
so add local_bh_disable/local_bh_enable to prevent data corruption and
panics.

Bug report at http://marc.info/?l=linux-crypto-vger&m=134858649616319&w=2

v2:
- Disable software interrupts instead of hardware interrupts

Cc: [email protected]
Reported-by: Gurucharan Shetty <[email protected]>
Signed-off-by: Jussi Kivilinna <[email protected]>
---
crypto/cryptd.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index 671d4d6..7bdd61b 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -137,13 +137,18 @@ static void cryptd_queue_worker(struct work_struct *work)
struct crypto_async_request *req, *backlog;

cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
- /* Only handle one request at a time to avoid hogging crypto
- * workqueue. preempt_disable/enable is used to prevent
- * being preempted by cryptd_enqueue_request() */
+ /*
+ * Only handle one request at a time to avoid hogging crypto workqueue.
+ * preempt_disable/enable is used to prevent being preempted by
+ * cryptd_enqueue_request(). local_bh_disable/enable is used to prevent
+ * cryptd_enqueue_request() being accessed from software interrupts.
+ */
+ local_bh_disable();
preempt_disable();
backlog = crypto_get_backlog(&cpu_queue->queue);
req = crypto_dequeue_request(&cpu_queue->queue);
preempt_enable();
+ local_bh_enable();

if (!req)
return;


2012-10-24 13:14:26

by Herbert Xu

[permalink] [raw]
Subject: Re: [PATCH] [v2] crypto: cryptd - disable softirqs in cryptd_queue_worker to prevent data corruption

On Sun, Oct 21, 2012 at 08:42:28PM +0300, Jussi Kivilinna wrote:
> cryptd_queue_worker attempts to prevent simultaneous accesses to crypto
> workqueue by cryptd_enqueue_request using preempt_disable/preempt_enable.
> However cryptd_enqueue_request might be called from softirq context,
> so add local_bh_disable/local_bh_enable to prevent data corruption and
> panics.
>
> Bug report at http://marc.info/?l=linux-crypto-vger&m=134858649616319&w=2
>
> v2:
> - Disable software interrupts instead of hardware interrupts
>
> Cc: [email protected]
> Reported-by: Gurucharan Shetty <[email protected]>
> Signed-off-by: Jussi Kivilinna <[email protected]>

Patch applied to crypto.

Thanks!
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt