Skip to content

Commit 9101065

Browse files
committed
ublk: make sure ubq->canceling is set when queue is frozen
jira LE-4297 cve CVE-2025-22068 Rebuild_History Non-Buildable kernel-6.12.0-55.34.1.el10_0 commit-author Ming Lei <[email protected]> commit 8741d07 Now ublk driver depends on `ubq->canceling` for deciding if the request can be dispatched via uring_cmd & io_uring_cmd_complete_in_task(). Once ubq->canceling is set, the uring_cmd can be done via ublk_cancel_cmd() and io_uring_cmd_done(). So set ubq->canceling when queue is frozen, this way makes sure that the flag can be observed from ublk_queue_rq() reliably, and avoids use-after-free on uring_cmd. Fixes: 216c8f5 ("ublk: replace monitor with cancelable uring_cmd") Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]> (cherry picked from commit 8741d07) Signed-off-by: Jonathan Maple <[email protected]>
1 parent 40d2037 commit 9101065

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

drivers/block/ublk_drv.c

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,17 +1407,27 @@ static void ublk_abort_queue(struct ublk_device *ub, struct ublk_queue *ubq)
14071407
}
14081408
}
14091409

1410+
/* Must be called when queue is frozen */
1411+
static bool ublk_mark_queue_canceling(struct ublk_queue *ubq)
1412+
{
1413+
bool canceled;
1414+
1415+
spin_lock(&ubq->cancel_lock);
1416+
canceled = ubq->canceling;
1417+
if (!canceled)
1418+
ubq->canceling = true;
1419+
spin_unlock(&ubq->cancel_lock);
1420+
1421+
return canceled;
1422+
}
1423+
14101424
static bool ublk_abort_requests(struct ublk_device *ub, struct ublk_queue *ubq)
14111425
{
1426+
bool was_canceled = ubq->canceling;
14121427
struct gendisk *disk;
14131428

1414-
spin_lock(&ubq->cancel_lock);
1415-
if (ubq->canceling) {
1416-
spin_unlock(&ubq->cancel_lock);
1429+
if (was_canceled)
14171430
return false;
1418-
}
1419-
ubq->canceling = true;
1420-
spin_unlock(&ubq->cancel_lock);
14211431

14221432
spin_lock(&ub->lock);
14231433
disk = ub->ub_disk;
@@ -1429,14 +1439,23 @@ static bool ublk_abort_requests(struct ublk_device *ub, struct ublk_queue *ubq)
14291439
if (!disk)
14301440
return false;
14311441

1432-
/* Now we are serialized with ublk_queue_rq() */
1442+
/*
1443+
* Now we are serialized with ublk_queue_rq()
1444+
*
1445+
* Make sure that ubq->canceling is set when queue is frozen,
1446+
* because ublk_queue_rq() has to rely on this flag for avoiding to
1447+
* touch completed uring_cmd
1448+
*/
14331449
blk_mq_quiesce_queue(disk->queue);
1434-
/* abort queue is for making forward progress */
1435-
ublk_abort_queue(ub, ubq);
1450+
was_canceled = ublk_mark_queue_canceling(ubq);
1451+
if (!was_canceled) {
1452+
/* abort queue is for making forward progress */
1453+
ublk_abort_queue(ub, ubq);
1454+
}
14361455
blk_mq_unquiesce_queue(disk->queue);
14371456
put_device(disk_to_dev(disk));
14381457

1439-
return true;
1458+
return !was_canceled;
14401459
}
14411460

14421461
static void ublk_cancel_cmd(struct ublk_queue *ubq, struct ublk_io *io,

0 commit comments

Comments
 (0)