In the Linux kernel, the following vulnerability has been resolved:
dmaengine: idxd: Let probe fail when workqueue cannot be enabled
The workqueue is enabled when the appropriate driver is loaded and disabled when the driver is removed. When the driver is removed it assumes that the workqueue was enabled successfully and proceeds to free allocations made during workqueue enabling.
Failure during workqueue enabling does not prevent the driver from being loaded. This is because the error path within drvenablewq() returns success unless a second failure is encountered during the error path. By returning success it is possible to load the driver even if the workqueue cannot be enabled and allocations that do not exist are attempted to be freed during driver remove.
Some examples of problematic flows: (a)
idxddmaenginedrvprobe() -> drvenablewq() -> idxdwqrequestirq(): In above flow, if idxdwqrequestirq() fails then idxdwqunmapportal() is called on error exit path, but drvenablewq() returns 0 because idxdwqdisable() succeeds. The driver is thus loaded successfully.
idxddmaenginedrvremove()->drvdisablewq()->idxdwqunmapportal() Above flow on driver unload triggers the WARN in devmiounmap() because the device resource has already been removed during error path of drvenable_wq().
(b)
idxddmaenginedrvprobe() -> drvenablewq() -> idxdwqrequestirq(): In above flow, if idxdwqrequestirq() fails then idxdwqinitpercpuref() is never called to initialize the percpu counter, yet the driver loads successfully because drvenable_wq() returns 0.
idxddmaenginedrvremove()->idxdwqquiesce()->percpuref_kill(): Above flow on driver unload triggers a BUG when attempting to drop the initial ref of the uninitialized percpu ref: BUG: kernel NULL pointer dereference, address: 0000000000000010
Fix the drvenablewq() error path by returning the original error that indicates failure of workqueue enabling. This ensures that the probe fails when an error is encountered and the driver remove paths are only attempted when the workqueue was enabled successfully.