Skip to content

Commit 82d712f

Browse files
committed
Merge branch 'for-5.14-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq
Pull workqueue fix from Tejun Heo: "Fix a use-after-free in allocation failure handling path" * 'for-5.14-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq: workqueue: fix UAF in pwq_unbound_release_workfn()
2 parents ff11764 + b42b0bd commit 82d712f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

kernel/workqueue.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3676,15 +3676,21 @@ static void pwq_unbound_release_workfn(struct work_struct *work)
36763676
unbound_release_work);
36773677
struct workqueue_struct *wq = pwq->wq;
36783678
struct worker_pool *pool = pwq->pool;
3679-
bool is_last;
3679+
bool is_last = false;
36803680

3681-
if (WARN_ON_ONCE(!(wq->flags & WQ_UNBOUND)))
3682-
return;
3681+
/*
3682+
* when @pwq is not linked, it doesn't hold any reference to the
3683+
* @wq, and @wq is invalid to access.
3684+
*/
3685+
if (!list_empty(&pwq->pwqs_node)) {
3686+
if (WARN_ON_ONCE(!(wq->flags & WQ_UNBOUND)))
3687+
return;
36833688

3684-
mutex_lock(&wq->mutex);
3685-
list_del_rcu(&pwq->pwqs_node);
3686-
is_last = list_empty(&wq->pwqs);
3687-
mutex_unlock(&wq->mutex);
3689+
mutex_lock(&wq->mutex);
3690+
list_del_rcu(&pwq->pwqs_node);
3691+
is_last = list_empty(&wq->pwqs);
3692+
mutex_unlock(&wq->mutex);
3693+
}
36883694

36893695
mutex_lock(&wq_pool_mutex);
36903696
put_unbound_pool(pool);

0 commit comments

Comments
 (0)