linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] workqueue: Fix double kfree(rescuer) in destroy_workqueue()
@ 2020-05-24  9:22 qiang.zhang
  0 siblings, 0 replies; 5+ messages in thread
From: qiang.zhang @ 2020-05-24  9:22 UTC (permalink / raw)
  To: tj; +Cc: jiangshanlai, linux-kernel

From: Zhang Qiang <qiang.zhang@windriver.com>

When destroy_workqueue if rescuer worker exist,wq->rescuer pointer be
kfree. if sanity checks passed. the func call_rcu(&wq->rcu, rcu_free_wq)
will be called if the wq->flags & WQ_UNBOUND is false,in rcu_free_wq
func wq->rescuer pointer was kfree again.

Signed-off-by: Zhang Qiang <qiang.zhang@windriver.com>
---
 kernel/workqueue.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 891ccad5f271..a2451cdcd503 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -3491,7 +3491,6 @@ static void rcu_free_wq(struct rcu_head *rcu)
 	else
 		free_workqueue_attrs(wq->unbound_attrs);
 
-	kfree(wq->rescuer);
 	kfree(wq);
 }
 
-- 
2.17.0


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

* Re: [PATCH] workqueue: Fix double kfree(rescuer) in destroy_workqueue()
  2020-05-25  6:43 ` qzhang2
@ 2020-05-25  7:04   ` Markus Elfring
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Elfring @ 2020-05-25  7:04 UTC (permalink / raw)
  To: Qiang Zhang, Lai Jiangshan, Tejun Heo; +Cc: linux-kernel, kernel-janitors

> Sorry I didn't describe clearly
>
> I describe the meaning as follows:

Can it help to adjust the change description in the way
that a duplicate memory release should be deleted from the implementation
of the callback function “rcu_free_wq”?

Which commit should be referenced for the tag “Fixes”?

Regards,
Markus

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

* Re: [PATCH] workqueue: Fix double kfree(rescuer) in destroy_workqueue()
  2020-05-24 15:33 Markus Elfring
  2020-05-25  6:28 ` qzhang2
@ 2020-05-25  6:43 ` qzhang2
  2020-05-25  7:04   ` Markus Elfring
  1 sibling, 1 reply; 5+ messages in thread
From: qzhang2 @ 2020-05-25  6:43 UTC (permalink / raw)
  To: Markus Elfring, Lai Jiangshan, Tejun Heo; +Cc: linux-kernel, kernel-janitors

Sorry I didn't describe clearly

I describe the meaning as follows:

  destroy_workqueue:
	if(wq->rescuer)
		struct worker *rescuer = wq->rescuer
		kfree(rescuer)  //first kfree
		

         if (!(wq->flags & WQ_UNBOUND))
		call_rcu(&wq->rcu, rcu_free_wq)
			
		rcu_free_wq
			kfree(wq->rescuer) //second kfree

there are double free.

On 5/24/20 11:33 PM, Markus Elfring wrote:
>> When destroy_workqueue if rescuer worker exist,wq->rescuer pointer be
>> kfree. if sanity checks passed. the func call_rcu(&wq->rcu, rcu_free_wq)
>> will be called if the wq->flags & WQ_UNBOUND is false,in rcu_free_wq
>> func wq->rescuer pointer was kfree again.
> 
> 1. I suggest to improve also this change description.
>     Do you try to explain here that a call of the function “free_workqueue_attrs”
>     (or “free_percpu”) would perform sufficient clean-up of system resources
>     in this use case?
> 
> 2. You proposed to delete the function call “kfree(wq->rescuer)” from
>     the implementation of the function “rcu_free_wq”.
>     https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/workqueue.c?id=c11d28ab4a691736e30b49813fb801847bd44e83#n3482
>     https://elixir.bootlin.com/linux/v5.7-rc6/source/kernel/workqueue.c#L3482
> 
>     This function name should be specified also in the patch subject,
>     shouldn't it?
> 
> 3. Would you like to add the tag “Fixes” to the commit message?
> 
> Regards,
> Markus
> 

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

* Re: [PATCH] workqueue: Fix double kfree(rescuer) in destroy_workqueue()
  2020-05-24 15:33 Markus Elfring
@ 2020-05-25  6:28 ` qzhang2
  2020-05-25  6:43 ` qzhang2
  1 sibling, 0 replies; 5+ messages in thread
From: qzhang2 @ 2020-05-25  6:28 UTC (permalink / raw)
  To: Markus Elfring, Lai Jiangshan, Tejun Heo; +Cc: linux-kernel, kernel-janitors

Sorry I didn't describe clearly

I describe the meaning as follows:

	destroy_workqueue
		if(wq->rescuer)
			struct worker *rescuer = wq->rescuer
			kfree(rescuer)
		..................
                 if (!(wq->flags & WQ_UNBOUND))
			call_rcu(&wq->rcu, rcu_free_wq)
			......................
			rcu_free_wq
				kfree(wq->rescuer)

there are double free.

On 5/24/20 11:33 PM, Markus Elfring wrote:
>> When destroy_workqueue if rescuer worker exist,wq->rescuer pointer be
>> kfree. if sanity checks passed. the func call_rcu(&wq->rcu, rcu_free_wq)
>> will be called if the wq->flags & WQ_UNBOUND is false,in rcu_free_wq
>> func wq->rescuer pointer was kfree again.
> 
> 1. I suggest to improve also this change description.
>     Do you try to explain here that a call of the function “free_workqueue_attrs”
>     (or “free_percpu”) would perform sufficient clean-up of system resources
>     in this use case?
> 
> 2. You proposed to delete the function call “kfree(wq->rescuer)” from
>     the implementation of the function “rcu_free_wq”.
>     https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/workqueue.c?id=c11d28ab4a691736e30b49813fb801847bd44e83#n3482
>     https://elixir.bootlin.com/linux/v5.7-rc6/source/kernel/workqueue.c#L3482
> 
>     This function name should be specified also in the patch subject,
>     shouldn't it?
> 
> 3. Would you like to add the tag “Fixes” to the commit message?
> 
> Regards,
> Markus
> 

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

* Re: [PATCH] workqueue: Fix double kfree(rescuer) in destroy_workqueue()
@ 2020-05-24 15:33 Markus Elfring
  2020-05-25  6:28 ` qzhang2
  2020-05-25  6:43 ` qzhang2
  0 siblings, 2 replies; 5+ messages in thread
From: Markus Elfring @ 2020-05-24 15:33 UTC (permalink / raw)
  To: Zhang Qiang, Lai Jiangshan, Tejun Heo; +Cc: linux-kernel, kernel-janitors

> When destroy_workqueue if rescuer worker exist,wq->rescuer pointer be
> kfree. if sanity checks passed. the func call_rcu(&wq->rcu, rcu_free_wq)
> will be called if the wq->flags & WQ_UNBOUND is false,in rcu_free_wq
> func wq->rescuer pointer was kfree again.

1. I suggest to improve also this change description.
   Do you try to explain here that a call of the function “free_workqueue_attrs”
   (or “free_percpu”) would perform sufficient clean-up of system resources
   in this use case?

2. You proposed to delete the function call “kfree(wq->rescuer)” from
   the implementation of the function “rcu_free_wq”.
   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/workqueue.c?id=c11d28ab4a691736e30b49813fb801847bd44e83#n3482
   https://elixir.bootlin.com/linux/v5.7-rc6/source/kernel/workqueue.c#L3482

   This function name should be specified also in the patch subject,
   shouldn't it?

3. Would you like to add the tag “Fixes” to the commit message?

Regards,
Markus

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

end of thread, other threads:[~2020-05-25  7:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-24  9:22 [PATCH] workqueue: Fix double kfree(rescuer) in destroy_workqueue() qiang.zhang
2020-05-24 15:33 Markus Elfring
2020-05-25  6:28 ` qzhang2
2020-05-25  6:43 ` qzhang2
2020-05-25  7:04   ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).