Re: [PATCH] workqueue: Check for null pointer return from get_work_pwq()

From: Tejun Heo
Date: Mon Dec 12 2022 - 17:55:31 EST


On Wed, Dec 07, 2022 at 04:53:44PM -0800, John Moon wrote:
> We've encountered a kernel panic with the following stack trace:
>
> -> ret_from_fork
> -> kthread
> -> worker_thread
> -> process_one_work
> -> pwq_dec_nr_in_flight
> -> pwq_activate_inactive_work
>
> The issue was narrowed down to a null pointer dereference within
> pwq_activate_inactive_work() stemming from the return value of
> get_work_pwq() which may return NULL, but was not checked for
> null return prior to use.
>
> While fixing the issue, other dereferences of get_work_pwq()'s
> return value were found without a null check.
>
> Add null pointer checks to the calling functions that need them.

At that point the work item must have pwq assigned - see insert_work(), so
this can't be the root cause. It's just papering over a bug somewhere else
(e.g. the work item got freed or written over somehow).

Thanks.

--
tejun