workqueue: Fix an use after free in init_rescuer()
Subsystems (2)
PATCH 1/1 workqueue: Fix an use after free in init_rescuer()
We need to preserve error code before freeing "rescuer".
Fixes f187b6974f6df ("workqueue: Use IS_ERR and PTR_ERR instead of PTR_ERR_OR_ZERO.")
Signed-off-by Dan Carpenter <[email protected]>
---
Another option would be to just revert the original commit.
kernel/workqueue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/workqueue.c +3 -1
@@ -4197,6 +4197,7 @@ static int wq_clamp_max_active(int max_active, unsigned int flags,static int init_rescuer (struct workqueue_struct *wq) {struct worker *rescuer; +int ret;if (!(wq->flags &WQ_MEM_RECLAIM ))return 0 ;
@@ -4208,8 +4209,9 @@ static int init_rescuer(struct workqueue_struct *wq) rescuer->rescue_wq = wq; rescuer->task =kthread_create (rescuer_thread, rescuer,"%s" , wq->name);if (IS_ERR (rescuer->task)) { + ret =PTR_ERR (rescuer->task);kfree (rescuer); -return PTR_ERR (rescuer->task); +return ret; } wq->rescuer = rescuer;
Signature · 1 line
2.26.2
Reviewed-by Lai Jiangshan <[email protected]>
Quoted 37 lines · Dan Carpenter
We need to preserve error code before freeing "rescuer".
Fixes f187b6974f6df ("workqueue: Use IS_ERR and PTR_ERR instead of PTR_ERR_OR_ZERO.")Signed-off-by Dan Carpenter <[email protected]>---
Another option would be to just revert the original commit.kernel/workqueue.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)kernel/workqueue.c +3
-2@@ -4197,6 +4197,7 @@ static int wq_clamp_max_active(int max_active, unsigned int flags,static int init_rescuer (struct workqueue_struct *wq) {struct worker *rescuer; +int ret;if (!(wq->flags &WQ_MEM_RECLAIM ))return 0 ;@@ -4208,8 +4209,9 @@ static int init_rescuer(struct workqueue_struct *wq) rescuer->rescue_wq = wq; rescuer->task =kthread_create (rescuer_thread, rescuer,"%s" , wq->name);if (IS_ERR (rescuer->task)) { + ret =PTR_ERR (rescuer->task);kfree (rescuer); -return PTR_ERR (rescuer->task); +return ret; } wq->rescuer = rescuer; --2.26.2
Quoted 4 lines · Dan Carpenter
We need to preserve error code before freeing "rescuer".
Fixes f187b6974f6df ("workqueue: Use IS_ERR and PTR_ERR instead of PTR_ERR_OR_ZERO.")Signed-off-by Dan Carpenter <[email protected]>
Applied to wq/for-5.8. Thank you.
Signature · 1 line
tejun