workqueue: Fix double kfree for rescuer
Subsystems (2)
PATCH v3 1/1 workqueue: Fix double kfree for rescuer
From: Zhang Qiang <[email protected]>
The callback function "rcu_free_wq" could be called after memory was released for "rescuer" already, Thus delete a misplaced call of the function "kfree".
---
v1->v2->v3:
Only commit information modification.
kernel/workqueue.c | 1 - 1 file changed, 1 deletion(-)
kernel/workqueue.c +0 -1
@@ -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
Quoted 3 lines
The callback function "
rcu_free_wq" could be called after memory was released for "rescuer" already, Thus delete a misplaced call of the function "kfree".
I got into the mood to follow your interpretation of the software situation for a moment.
I have taken another look also at the implementation of the function “destroy_workqueue”.
* The function call “kfree(rescuer)” 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. I'm sorry for undesirable confusion because of this patch review.
Regards,
Markus
Quoted 3 lines
The callback function "
rcu_free_wq" could be called after memory was released for "rescuer" already, Thus delete a misplaced call of the function "kfree".
I got into the mood to follow your interpretation of the software situation for a moment.
I have taken another look also at the implementation of the function “destroy_workqueue”.
* The function call “kfree(rescuer)” 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. I'm sorry for undesirable confusion because of this patch review.
Regards,
Markus
Lai Jiangshan
reviewerQuoted 6 lines · On Mon, May 25, 2020 at 5:22 PM <[email protected]> wrote:
From: Zhang Qiang <[email protected]>
The callback function "
rcu_free_wq" could be called after memory was released for "rescuer" already, Thus delete a misplaced call of the function "kfree".
Hello
wq->rescuer is guaranteed to be NULL in rcu_free_wq()
since def98c84b6cd
("workqueue: Fix spurious sanity check failures in destroy_workqueue()")
And the resucer is already free in destroy_workqueue() since 8efe1223d73c
("workqueue: Fix missing kfree(rescuer) in destroy_workqueue()")
The patch is a cleanup to remove a "kfree(NULL);". But the changelog is misleading.
Quoted 2 lines
Fixes 6ba94429c8e7 ("workqueue: Reorder sysfs code")
It is totally unrelated.
Quoted 22 lines
Signed-off-by Zhang Qiang <[email protected]>---
v1->v2->v3:
Only commit information modification.kernel/workqueue.c | 1 - 1 file changed, 1 deletion(-)kernel/workqueue.c +0
-2@@ -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.24.1
Quoted 1 line
wq->rescueris guaranteed to be NULL inrcu_free_wq()
I was unsure about this data processing detail.
Quoted 1 line
The patch is a cleanup to remove a "kfree(NULL);".
I would prefer also an improved commit message according to the understanding of the software situation in this direction.
Regards,
Markus
Thank you reply
There is something wrong with my description. is it feasible to describe as follows:
The resucer is already free in "destroy_workqueue" and
"wq->rescuer = NULL" was executed, but in "rcu_free_wq" it's release again (equivalent to kfree(NULL)), this is unnecessary, so should remove.
Quoted 48 lines · Lai Jiangshan
Quoted 6 lines · On Mon, May 25, 2020 at 5:22 PM <[email protected]> wrote:
From: Zhang Qiang <[email protected]>
The callback function "
rcu_free_wq" could be called after memory was released for "rescuer" already, Thus delete a misplaced call of the function "kfree".Hello
wq->rescueris guaranteed to be NULL inrcu_free_wq()
sincedef98c84b6cd
("workqueue: Fix spurious sanity check failures indestroy_workqueue()")And the resucer is already free in
destroy_workqueue()since8efe1223d73c
("workqueue: Fix missing kfree(rescuer) indestroy_workqueue()")The patch is a cleanup to remove a "kfree(NULL);". But the changelog is misleading.
Quoted 2 lines
Fixes 6ba94429c8e7 ("workqueue: Reorder sysfs code")It is totally unrelated.
Quoted 22 lines
Signed-off-by Zhang Qiang <[email protected]>---
v1->v2->v3:
Only commit information modification.kernel/workqueue.c | 1 - 1 file changed, 1 deletion(-)kernel/workqueue.c +0
-2@@ -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.24.1
Quoted 6 lines
There is something wrong with my description. is it feasible to describe as follows:
The resucer is already free in "
destroy_workqueue" and
"wq->rescuer= NULL" was executed, but in "rcu_free_wq" it's release again (equivalent to kfree(NULL)), this is unnecessary, so should remove.
I find that this suggestion indicates further wording challenges. Please try another variant.
Regards,
Markus