Skip to contentSkip to conversation

blktests: src/miniublk.c: fix segment fault when io_uring is disabled

PATCH In review Ming Lei 2 participants 4 messages Dec 13, 2024 – Dec 18, 2024 Block layer

lore
Share & tools
lore

Ming Lei

author
#0 lore raw

PATCH 1/1 blktests: src/miniublk.c: fix segment fault when io_uring is disabled

When io_uring is disabled, ublk_ctrl_init() will return NULL, so we have to check the result.

Fixes segment fault reported from Yi.

---
 src/miniublk.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
src/miniublk.c +15 -4
index 73791fd..f98f850 100644
@@ -1136,9 +1136,14 @@ static int ublk_stop_io_daemon(const struct ublk_dev *dev)
 static int __cmd_dev_del(int number, bool log)
 {
 	struct ublk_dev *dev;
-	int ret;
+	int ret = -ENODEV;
 
 	dev = ublk_ctrl_init();
+	if (!dev) {
+		ublk_err("del dev %d failed\n", number);
+		goto fail;
+	}
+
 	dev->dev_info.dev_id = number;
 
 	ret = ublk_ctrl_get_info(dev);
@@ -1208,8 +1213,14 @@ static int cmd_dev_del(int argc, char *argv[])
 
 static int __cmd_dev_list(int number, bool log)
 {
-	struct ublk_dev *dev = ublk_ctrl_init();
-	int ret;
+	struct ublk_dev *dev;
+	int ret = -ENODEV;
+
+	dev = ublk_ctrl_init();
+	if (!dev) {
+		ublk_err("list dev %d failed\n", number);
+		goto exit;
+	}
 
 	dev->dev_info.dev_id = number;
 
@@ -1223,7 +1234,7 @@ static int __cmd_dev_list(int number, bool log)
 	}
 
 	ublk_ctrl_deinit(dev);
-
+exit:
 	return ret;
 }
 
Signature · 1 line
2.47.0
#1 lore raw
Quoted 4 lines · Ming Lei

When io_uring is disabled, ublk_ctrl_init() will return NULL, so we have to check the result.

Fixes segment fault reported from Yi.

Ming, let me confirm, the segmentation fault was reported in the blktests GitHub PR 153 [1]. AFAIU, the segmentation fault cause is in liburing, not in blktests src/miniublk.c. So I guess that this patch is not needed. Do you have same view?

[1] https://github.com/osandov/blktests/pull/153

author
#2 lore raw
Quoted 10 lines · Shinichiro Kawasaki
Quoted 4 lines · Ming Lei

When io_uring is disabled, ublk_ctrl_init() will return NULL, so we have to check the result.

Fixes segment fault reported from Yi.

Ming, let me confirm, the segmentation fault was reported in the blktests GitHub PR 153 [1]. AFAIU, the segmentation fault cause is in liburing, not in blktests src/miniublk.c. So I guess that this patch is not needed. Do you have same view?

Hi Shinichiro,

This patch fixes another segment fault which is miniublk specific.

Thanks,

#3 lore raw
Quoted 9 lines · Ming Lei
Quoted 7 lines · Shinichiro Kawasaki
Quoted 4 lines · Ming Lei

When io_uring is disabled, ublk_ctrl_init() will return NULL, so we have to check the result.

Fixes segment fault reported from Yi.

Quoted 7 lines
Quoted 3 lines

Ming, let me confirm, the segmentation fault was reported in the blktests GitHub PR 153 [1]. AFAIU, the segmentation fault cause is in liburing, not in blktests src/miniublk.c. So I guess that this patch is not needed. Do you have same view?

Hi Shinichiro,

This patch fixes another segment fault which is miniublk specific.

Got it, I have applied this patch. Thanks!