All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH] crypto: pcrypt: Fix possible deadlock in padata_sysfs_release
  2019-05-31  9:29 [PATCH] crypto: pcrypt: Fix possible deadlock in padata_sysfs_release Kefeng Wang
@ 2019-05-31  9:23 ` Kefeng Wang
  2019-06-01  9:23   ` [PATCH v2] " Kefeng Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Kefeng Wang @ 2019-05-31  9:23 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: linux-crypto, linux-kernel, Hulk Robot


On 2019/5/31 17:29, Kefeng Wang wrote:
> 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 | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
> index 0e9ce329fd47..662228b48b70 100644
> --- a/crypto/pcrypt.c
> +++ b/crypto/pcrypt.c
> @@ -407,13 +407,14 @@ 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) 

Oh, forget to add put_online_cpus in this error path, will resend v2 if there is no comment.


>  		goto err_destroy_workqueue;
> @@ -448,12 +449,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;
>  }
>  


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] crypto: pcrypt: Fix possible deadlock in padata_sysfs_release
@ 2019-05-31  9:29 Kefeng Wang
  2019-05-31  9:23 ` Kefeng Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Kefeng Wang @ 2019-05-31  9:29 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: linux-crypto, linux-kernel, Kefeng Wang, Hulk Robot

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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
index 0e9ce329fd47..662228b48b70 100644
--- a/crypto/pcrypt.c
+++ b/crypto/pcrypt.c
@@ -407,13 +407,14 @@ 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)
 		goto err_destroy_workqueue;
@@ -448,12 +449,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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2] crypto: pcrypt: Fix possible deadlock in padata_sysfs_release
  2019-05-31  9:23 ` Kefeng Wang
@ 2019-06-01  9:23   ` Kefeng Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Kefeng Wang @ 2019-06-01  9:23 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S. Miller
  Cc: linuxcrypto, linux-kernel, Kefeng Wang, Hulk Robot

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-06-01  9:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-31  9:29 [PATCH] crypto: pcrypt: Fix possible deadlock in padata_sysfs_release Kefeng Wang
2019-05-31  9:23 ` Kefeng Wang
2019-06-01  9:23   ` [PATCH v2] " Kefeng Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.