Skip to content

Commit

Permalink
workqueue: Only unregister a registered lockdep key
Browse files Browse the repository at this point in the history
The recent change to prevent use after free and a memory leak introduced an
unconditional call to wq_unregister_lockdep() in the error handling
path. If the lockdep key had not been registered yet, then the lockdep core
emits a warning.

Only call wq_unregister_lockdep() if wq_register_lockdep() has been
called first.

Fixes: 009bb42 ("workqueue, lockdep: Fix an alloc_workqueue() error path")
Reported-by: [email protected]
Signed-off-by: Bart Van Assche <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Qian Cai <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
  • Loading branch information
bvanassche authored and KAGA-KOKO committed Mar 21, 2019
1 parent 9e98c67 commit 82efcab
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions kernel/workqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -4266,7 +4266,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,
INIT_LIST_HEAD(&wq->list);

if (alloc_and_link_pwqs(wq) < 0)
goto err_free_wq;
goto err_unreg_lockdep;

if (wq_online && init_rescuer(wq) < 0)
goto err_destroy;
Expand All @@ -4292,9 +4292,10 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,

return wq;

err_free_wq:
err_unreg_lockdep:
wq_unregister_lockdep(wq);
wq_free_lockdep(wq);
err_free_wq:
free_workqueue_attrs(wq->unbound_attrs);
kfree(wq);
return NULL;
Expand Down

0 comments on commit 82efcab

Please sign in to comment.