]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
ublk: fix use-after-free in ublk_cancel_cmd()
authorMing Lei <tom.leiming@gmail.com>
Fri, 8 May 2026 12:37:46 +0000 (20:37 +0800)
committerJens Axboe <axboe@kernel.dk>
Fri, 8 May 2026 12:44:42 +0000 (06:44 -0600)
commitf7700a4415afb3ac1767a556094e4ef8bd440e41
tree4ced987546c335d15f5e9949eb826357d60da84e
parent86f33ca9bea30cf011f2b1edad4593faea9c6e98
ublk: fix use-after-free in ublk_cancel_cmd()

When ublk_reset_ch_dev() clears io->cmd via ublk_queue_reinit()
concurrently with ublk_cancel_cmd(), ublk_cancel_cmd() can read a
stale pointer and pass it to io_uring_cmd_done(), causing a
use-after-free.

Fix by synchronizing the two paths with ubq->cancel_lock:

- ublk_cancel_cmd(): read and clear io->cmd under cancel_lock,
  then call io_uring_cmd_done() on the saved local copy outside
  the lock.

- ublk_reset_ch_dev(): hold cancel_lock across ublk_queue_reinit()
  so that io->cmd and io->flags are cleared atomically with respect
  to ublk_cancel_cmd().

Fixes: 216c8f5ef0f2 ("ublk: replace monitor with cancelable uring_cmd")
Signed-off-by: Ming Lei <tom.leiming@gmail.com>
Link: https://patch.msgid.link/20260508123746.242018-1-tom.leiming@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/block/ublk_drv.c