mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: <linuxcrypto@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	Kefeng Wang <wangkefeng.wang@huawei.com>,
	Hulk Robot <hulkci@huawei.com>
Subject: [PATCH v2] crypto: pcrypt: Fix possible deadlock in padata_sysfs_release
Date: Sat, 1 Jun 2019 17:23:32 +0800	[thread overview]
Message-ID: <20190601092332.136481-1-wangkefeng.wang@huawei.com> (raw)
In-Reply-To: <1b71b136-3501-db1c-834b-ba7ed1431f4d@huawei.com>

There is a deadlock issue in pcrypt_init_padata(),

pcrypt_init_padata()
    cpus_read_lock()
      padata_free()
        padata_sysfs_release()
          cpus_read_lock()

Narrow rcu_read_lock/unlock() and move put_online_cpus()
before padata_free() to fix it.

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Kefeng Wang <wangkefeng.wang@huawei.com>
---
 crypto/pcrypt.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index 0e9ce329fd47..f3dacb714cd4 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -407,16 +407,19 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
 	int ret = -ENOMEM;
 	struct pcrypt_cpumask *mask;
 
-	get_online_cpus();
 
 	pcrypt->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE,
 				     1, name);
 	if (!pcrypt->wq)
 		goto err;
 
+	get_online_cpus();
+
 	pcrypt->pinst = padata_alloc_possible(pcrypt->wq);
-	if (!pcrypt->pinst)
+	if (!pcrypt->pinst) {
+		put_online_cpus();
 		goto err_destroy_workqueue;
+	}
 
 	mask = kmalloc(sizeof(*mask), GFP_KERNEL);
 	if (!mask)
@@ -448,12 +451,11 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
 	free_cpumask_var(mask->mask);
 	kfree(mask);
 err_free_padata:
+	put_online_cpus();
 	padata_free(pcrypt->pinst);
 err_destroy_workqueue:
 	destroy_workqueue(pcrypt->wq);
 err:
-	put_online_cpus();
-
 	return ret;
 }
 
-- 
2.20.1


      reply	other threads:[~2019-06-01  9:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31  9:29 [PATCH] " Kefeng Wang
2019-05-31  9:23 ` Kefeng Wang
2019-06-01  9:23   ` Kefeng Wang [this message]

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=20190601092332.136481-1-wangkefeng.wang@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=hulkci@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxcrypto@vger.kernel.org \
    --cc=steffen.klassert@secunet.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

all inboxes | Powered by JetHome®