Re: [RFC v1 1/3] workqueue: Add resource-managed version of INIT_[DELAYED_]WORK()

From: Tejun Heo
Date: Fri Feb 08 2019 - 12:07:02 EST


On Mon, Feb 04, 2019 at 05:09:50PM -0500, Sven Van Asbroeck wrote:
> In modules which extensively use devm_ resource management, it is often
> easy to overlook (delayed) work that is left pending or running after the
> module is unloaded. This could introduce user-after-free issues.
>
> Nudge kernel developers into 'doing the right thing' by introducing a
> resource-managed version of INIT_[DELAYED_]WORK(). This can be used as
> an elegant way to ensure that work is not left pending or running after
> its dependencies are released.
>
> Functions introduced in workqueue.h :
> - devm_init_work()
> - devm_init_delayed_work()

I don't object to the basic idea but cancel_[delayed_]work_sync()
works iff queueing is disabled already, so there can be situations
where this can lead to surprising / subtle failures. Given that, it
*might* not be a bad idea to keep this explicit unless there is a way
to reliably block future queueing.

Thanks.

--
tejun