workqueue: unregister wq lockdep on error path in alloc_workqueue()
PATCH 1/1 workqueue: unregister wq lockdep on error path in alloc_workqueue()
syzkaller report an issue "KASAN: use-after-free Read in alloc_workqueue",
alloc_workqueue
- kzalloc wq
- wq_init_lockdep(wq);
- lockdep_register_key(&wq->key); // add to hlist
- kfree wq
But forget to call wq_unregister_lockdep()->lockdep_unregister_key(), it will delete the entry from hlist.
--- kernel/workqueue.c | 1 + 1 file changed, 1 insertion(+)
kernel/workqueue.c +1 -0
@@ -4291,6 +4291,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,return wq; err_free_wq: +wq_unregister_lockdep (wq);free_workqueue_attrs (wq->unbound_attrs);kfree (wq);return NULL ;
Signature · 1 line
2.20.1
Quoted 23 lines · Kefeng Wang
syzkaller report an issue "KASAN: use-after-free Read in
alloc_workqueue",
alloc_workqueue
- kzalloc wq
-wq_init_lockdep(wq);
-lockdep_register_key(&wq->key); // add to hlist
- kfree wqBut forget to call wq_unregister_lockdep()->lockdep_unregister_key(), it will delete the entry from hlist.
Reported-by [email protected]Fixes 669de8bda87b ("kernel/workqueue: Use dynamic lockdep keys for workqueues")Signed-off-by Kefeng Wang <[email protected]>--- kernel/workqueue.c | 1 + 1 file changed, 1 insertion(+)kernel/workqueue.c +0
-0
kernel/workqueue.c struct workqueue_struct *alloc_workqueue(const char *fmt, · line 4297
Quoted 7 lines
kernel/workqueue.c +1
-0@@ -4291,6 +4291,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt,return wq; err_free_wq: +wq_unregister_lockdep (wq);free_workqueue_attrs (wq->unbound_attrs);kfree (wq);return NULL ;
Hi Kefeng,
Five days ago I had posted a similar but slightly different patch. Can you have a look at it? See also https://lore.kernel.org/lkml/[email protected]/
Thanks,
Bart.
Quoted 33 lines · Bart Van Assche
Quoted 24 lines · Kefeng Wang
syzkaller report an issue "KASAN: use-after-free Read in
alloc_workqueue",
alloc_workqueue
- kzalloc wq
-wq_init_lockdep(wq);
- lockdep_register_key(&wq->key); // add to hlist
- kfree wqBut forget to call wq_unregister_lockdep()->lockdep_unregister_key(), it will delete the entry from hlist.
Reported-by [email protected]Fixes 669de8bda87b ("kernel/workqueue: Use dynamic lockdep keys for workqueues")Signed-off-by Kefeng Wang <[email protected]>---
kernel/workqueue.c| 1 +1 file changed, 1 insertion(+)kernel/workqueue.c +0
-0@@ -4291,6 +4291,7 @@ struct workqueue_struct *alloc_workqueue(const char *fmt, return wq;Quoted 5 lines
err_free_wq:
+wq_unregister_lockdep(wq);
free_workqueue_attrs(wq->unbound_attrs);
kfree(wq);
return NULL;Hi Kefeng,
Quoted 1 line
Five days ago I had posted a similar but slightly different patch. Can you have a look at it? See also https://lore.kernel.org/lkml/[email protected]/
I don't notice your patch due to no subscribe lkml, that is better, wq->lock_name should be freed too; )
Quoted 9 lines
Thanks,
Bart.
.