Skip to contentSkip to conversation

workqueue: Fix double kfree for rescuer

PATCH Superseded [email protected] 2 participants 7 messages May 25, 2020 – May 26, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 workqueue: Fix double kfree for rescuer

From: Zhang Qiang <[email protected]>

The duplicate memory release should be deleted from the implementation of the callback function "rcu_free_wq".

Fixes 6ba94429c8e7 ("workqueue: Reorder sysfs code")
---
 kernel/workqueue.c | 1 -
 1 file changed, 1 deletion(-)
kernel/workqueue.c +0 -1
index 891ccad5f271..a2451cdcd503 100644
@@ -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);
 }
 
Signature · 1 line
2.24.1
#1 lore raw

Re: [PATCH v2] workqueue: Delete duplicate kfree() call for “rescuer” from rcu_free_wq()

Quoted 2 lines

The duplicate memory release should be deleted from the implementation of the callback function "rcu_free_wq".

I would find it nicer if you would have extended my simple wording suggestion.

1. Mention conditions:
The callback function “rcu_free_wq” could be called after memory was released for “rescuer” already.

2. Specify the desired action:
Thus delete a misplaced call of the function “kfree”.

3. Please keep the patch versioning consistent.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?id=9cb1fd0efd195590b828b9b865421ad345a4a145#n709

Regards,
Markus

#2 lore raw
In reply to [email protected]
Quoted 2 lines

The duplicate memory release should be deleted from the implementation of the callback function "rcu_free_wq".

I tried to help with the selection of a better commit message.
I have taken another look also at the implementation of the function “destroy_workqueue”.

* The function call “destroy_workqueue” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.

* This data processing is independent from a possible call of the function “call_rcu(&wq->rcu, rcu_free_wq)” in another if branch. Thus it seems that a null pointer is intentionally passed by a data structure member to this callback function on demand.
The corresponding call of the function “kfree” can tolerate this special case.

Now I find that the proposed change can be inappropriate.

Regards,
Markus

#3 lore raw
Quoted 2 lines

* The function call “destroy_workqueue” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.

Another correction:
* The function call “kfree(rescuer)” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.

Regards,
Markus

author
#4 lore raw
In reply to Markus Elfring

I see, kfree does nothing with null pointers and direct return. but again kfree is not a good suggestion.

Quoted 21 lines · Markus Elfring
Quoted 2 lines

The duplicate memory release should be deleted from the implementation of the callback function "rcu_free_wq".

I tried to help with the selection of a better commit message.
I have taken another look also at the implementation of the function “destroy_workqueue”.

* The function call “destroy_workqueue” can be performed there in an if branch after the statement “wq->rescuer = NULL” was executed.

* This data processing is independent from a possible call of the function “call_rcu(&wq->rcu, rcu_free_wq)” in another if branch. Thus it seems that a null pointer is intentionally passed by a data structure member to this callback function on demand.
The corresponding call of the function “kfree” can tolerate this special case.

Now I find that the proposed change can be inappropriate.

Regards,
Markus

#5 lore raw
Quoted 2 lines

I see, kfree does nothing with null pointers and direct return. but again kfree is not a good suggestion.

I have got the impression that the implementation detail is important here if non-null pointers (according to valid rescuer objects) are occasionally passed by the corresponding data structure member for the callback function “rcu_free_wq”.
Can another clarification attempt reduce unwanted confusion for this patch review?

Regards,
Markus

author
#6 lore raw

Thanks for your advice.
The rescuer null pointer is intentionally passed by a data structure? and also I read the code of workqueue again, when destroy_workqueue is called, after "wq->rescuer = NULL" was executed, The scenario described below does not happen

"if non-null pointers (according to valid rescuer objects) are occasionally passed by the corresponding data structure member for the callback function "rcu_free_wq"."

Quoted 12 lines · Markus Elfring
Quoted 2 lines

I see, kfree does nothing with null pointers and direct return. but again kfree is not a good suggestion.

I have got the impression that the implementation detail is important here if non-null pointers (according to valid rescuer objects) are occasionally passed by the corresponding data structure member for the callback function “rcu_free_wq”.
Can another clarification attempt reduce unwanted confusion for this patch review?

Regards,
Markus