ublk partition_scan_work race UAF on device teardown

A race between async partition scan work and device teardown can lead to a use-after-free of ub->ub_disk (struct gendisk *). KASAN reports a slab-use-after-free with an 8-byte write from the workqueue context.

Key ordering:

The worker ublk_partition_scan_work() dereferences ub->ub_disk:

This gives a

Environment:

KASAN:

KASAN

KASAN

Disclose Timeline: