Skip to content

Commit 58dfbc2

Browse files
ming1kernel-patches-daemon
authored andcommitted
ublk: reject FETCH from non-userspace context
__ublk_fetch() sets io->task to current, which is later checked against io_uring_cmd_get_task() in ublk_uring_cmd_cancel_fn(). With REQ_F_FORCE_ASYNC, the FETCH uring_cmd can be issued from task work, which can be run from io_uring's fallback workqueue, causing a task mismatch and triggering the WARN in cancel_fn. Reject FETCH if current is not a real userspace task, and it is reasonable for failing it in case of io_uring fallback. Fixes: 3421c7f ("ublk: make sure io cmd handled in submitter task context") Signed-off-by: Ming Lei <[email protected]>
1 parent 5a9f7c7 commit 58dfbc2

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3251,12 +3251,19 @@ static int __ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
32513251

32523252
WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV);
32533253

3254-
ublk_fill_io_cmd(io, cmd);
3255-
3256-
if (ublk_dev_support_batch_io(ub))
3254+
if (ublk_dev_support_batch_io(ub)) {
32573255
WRITE_ONCE(io->task, NULL);
3258-
else
3256+
} else {
3257+
/*
3258+
* FETCH must come from a real userspace task, not a
3259+
* kworker is actually io_uring fallback workqueue.
3260+
*/
3261+
if (current->flags & (PF_KTHREAD | PF_WQ_WORKER))
3262+
return -EINVAL;
32593263
WRITE_ONCE(io->task, get_task_struct(current));
3264+
}
3265+
3266+
ublk_fill_io_cmd(io, cmd);
32603267

32613268
return 0;
32623269
}

0 commit comments

Comments
 (0)