1
0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2026-01-12 01:20:14 +00:00
Ming Lei f0d385f668 ublk: fix use-after-free in ublk_partition_scan_work
A race condition exists between the async partition scan work and device
teardown that can lead to a use-after-free of ub->ub_disk:

1. ublk_ctrl_start_dev() schedules partition_scan_work after add_disk()
2. ublk_stop_dev() calls ublk_stop_dev_unlocked() which does:
   - del_gendisk(ub->ub_disk)
   - ublk_detach_disk() sets ub->ub_disk = NULL
   - put_disk() which may free the disk
3. The worker ublk_partition_scan_work() then dereferences ub->ub_disk
   leading to UAF

Fix this by using ublk_get_disk()/ublk_put_disk() in the worker to hold
a reference to the disk during the partition scan. The spinlock in
ublk_get_disk() synchronizes with ublk_detach_disk() ensuring the worker
either gets a valid reference or sees NULL and exits early.

Also change flush_work() to cancel_work_sync() to avoid running the
partition scan work unnecessarily when the disk is already detached.

Fixes: 7fc4da6a304b ("ublk: scan partition in async way")
Reported-by: Ruikai Peng <ruikai@pwno.io>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2026-01-09 06:55:30 -07:00
..
2025-12-02 17:49:12 -08:00
2025-12-03 17:24:33 -08:00
2025-10-24 21:39:27 +02:00
2025-12-03 12:42:36 -08:00
2025-11-25 17:06:04 +01:00
2025-12-03 17:24:33 -08:00
2025-11-27 18:11:43 -08:00
2025-12-03 12:42:36 -08:00
2025-12-02 17:03:55 -08:00
2025-12-01 17:32:07 -08:00
2025-12-03 14:42:21 -08:00
2025-11-22 09:58:41 -08:00
2025-12-03 17:24:33 -08:00
2025-11-17 23:16:55 -08:00
2025-11-27 17:29:15 -08:00
2025-12-01 17:32:07 -08:00
2025-12-03 12:42:36 -08:00
2025-12-03 17:24:33 -08:00
2025-11-17 19:32:32 -08:00
2025-12-04 20:58:19 -07:00
2025-12-03 17:24:33 -08:00
2025-12-02 17:03:55 -08:00
2025-11-27 08:51:36 -08:00
2025-12-03 12:42:36 -08:00
2025-12-03 17:24:33 -08:00
2025-12-03 19:26:18 -08:00
2025-12-03 17:24:33 -08:00
2025-12-03 12:42:36 -08:00
2025-12-03 17:24:33 -08:00
2025-11-21 21:27:20 +01:00
2025-12-03 12:42:36 -08:00
2025-12-02 17:31:22 -08:00
2025-12-01 17:32:07 -08:00
2025-12-03 17:24:33 -08:00