Skip to content

Commit

Permalink
ublksrv_tgt: handle ublksrv_ctrl_init() failure
Browse files Browse the repository at this point in the history
io_uring can be disabled by:

	echo 2 > /proc/sys/kernel/io_uring_disabled

then ublksrv_ctrl_init() will return NULL, handle the failure and
avoid to trigger segment fault.

Reported-by: Changhui Zhong <[email protected]>
Signed-off-by: Ming Lei <[email protected]>
  • Loading branch information
ming1 committed Nov 28, 2024
1 parent c76ed26 commit 46c08b0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ublksrv_tgt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,10 @@ static int __cmd_dev_del(int number, bool log, bool async)
};

dev = ublksrv_ctrl_init(&data);
if (!dev) {
fprintf(stderr, "ublksrv_ctrl_init failed id %d\n", number);
return -errno;
}

ret = ublksrv_ctrl_get_info(dev);
if (ret < 0) {
Expand Down Expand Up @@ -978,6 +982,10 @@ static int list_one_dev(int number, bool log, bool verbose)
struct ublksrv_ctrl_dev *dev = ublksrv_ctrl_init(&data);
int ret;

if (!dev) {
fprintf(stderr, "ublksrv_ctrl_init failed id %d\n", number);
return -errno;
}
ret = ublksrv_ctrl_get_info(dev);
if (ret < 0) {
if (log)
Expand Down Expand Up @@ -1057,6 +1065,11 @@ static int cmd_dev_get_features(int argc, char *argv[])
[const_ilog2(UBLK_F_USER_RECOVERY_FAIL_IO)] = "RECOVERY_FAIL_IO",
};

if (!dev) {
fprintf(stderr, "ublksrv_ctrl_init failed id\n");
return -errno;
}

ret = ublksrv_ctrl_get_features(dev, &features);
if (!ret) {
int i;
Expand Down Expand Up @@ -1102,7 +1115,7 @@ static int __cmd_dev_user_recover(int number, bool verbose)
dev = ublksrv_ctrl_init(&data);
if (!dev) {
fprintf(stderr, "ublksrv_ctrl_init failure dev %d\n", number);
return -ENOMEM;
return -errno;
}

ret = ublksrv_ctrl_get_info(dev);
Expand Down

0 comments on commit 46c08b0

Please sign in to comment.