Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ublk: prevent invalid access with DEBUG

ublk_ch_uring_cmd_local() may jump to the out label before
initialising the io pointer. This will cause trouble if DEBUG is
defined, because the pr_devel() call dereferences io. Clang reports:

drivers/block/ublk_drv.c:2403:6: error: variable 'io' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
2403 | if (tag >= ub->dev_info.queue_depth)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/block/ublk_drv.c:2492:32: note: uninitialized use occurs here
2492 | __func__, cmd_op, tag, ret, io->flags);
|

Fix this by initialising io to NULL and checking it before
dereferencing it.

Signed-off-by: Kevin Brodsky <kevin.brodsky@arm.com>
Fixes: 71f28f3136af ("ublk_drv: add io_uring based userspace block driver")
Reviewed-by: Caleb Sander Mateos <csander@purestorage.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Kevin Brodsky and committed by
Jens Axboe
c6a45ee7 a857d992

+2 -2
+2 -2
drivers/block/ublk_drv.c
··· 2301 2301 u16 buf_idx = UBLK_INVALID_BUF_IDX; 2302 2302 struct ublk_device *ub = cmd->file->private_data; 2303 2303 struct ublk_queue *ubq; 2304 - struct ublk_io *io; 2304 + struct ublk_io *io = NULL; 2305 2305 u32 cmd_op = cmd->cmd_op; 2306 2306 u16 q_id = READ_ONCE(ub_src->q_id); 2307 2307 u16 tag = READ_ONCE(ub_src->tag); ··· 2422 2422 2423 2423 out: 2424 2424 pr_devel("%s: complete: cmd op %d, tag %d ret %x io_flags %x\n", 2425 - __func__, cmd_op, tag, ret, io->flags); 2425 + __func__, cmd_op, tag, ret, io ? io->flags : 0); 2426 2426 return ret; 2427 2427 } 2428 2428