Skip to contentSkip to conversation

qemu-nbd: regression with arguments passing into nbd_client_thread()

PATCH In review Denis V. Lunev 2 participants 2 messages Jul 27, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qemu-nbd: regression with arguments passing into nbd_client_thread()

Unfortunately
commit 03b67621445d601c9cdc7dfe25812e9f19b81488
Author: Denis V. Lunev <[email protected]>
Date: Mon Jul 17 16:55:40 2023 +0200
qemu-nbd: pass structure into nbd_client_thread instead of plain char*
has introduced a regression. struct NbdClientOpts resides on stack inside 'if' block. This specifically means that this stack space could be reused once the execution will leave that block of the code.

This means that parameters passed into nbd_client_thread could be overwritten at any moment.

The patch moves the data to the namespace of main() function effectively preserving it for the whole process lifetime.

CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>

---
Changes from v1:
- fixed compilation without HAVE_NBD_DEVICE (i.e. for Win/BSD)

 qemu-nbd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
qemu-nbd.c +4 -1
index 5b2757920c..aaccaa3318 100644
@@ -589,6 +589,9 @@ int main(int argc, char **argv)
     const char *pid_file_name = NULL;
     const char *selinux_label = NULL;
     BlockExportOptions *export_opts;
+#if HAVE_NBD_DEVICE
+    struct NbdClientOpts opts;
+#endif
 
 #ifdef CONFIG_POSIX
     os_setup_early_signal_handling();
@@ -1145,7 +1148,7 @@ int main(int argc, char **argv)
     if (device) {
 #if HAVE_NBD_DEVICE
         int ret;
-        struct NbdClientOpts opts = {
+        opts = (struct NbdClientOpts) {
             .device = device,
             .fork_process = fork_process,
             .verbose = verbose,
Signature · 1 line
2.34.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines · Denis V. Lunev

Unfortunately
commit 03b67621445d601c9cdc7dfe25812e9f19b81488
Author: Denis V. Lunev <[email protected]>
Date: Mon Jul 17 16:55:40 2023 +0200
qemu-nbd: pass structure into nbd_client_thread instead of plain char*
has introduced a regression. struct NbdClientOpts resides on stack inside 'if' block. This specifically means that this stack space could be reused once the execution will leave that block of the code.

This means that parameters passed into nbd_client_thread could be overwritten at any moment.

The patch moves the data to the namespace of main() function effectively preserving it for the whole process lifetime.

Quoted 7 lines
CC Eric Blake <[email protected]>
CC Vladimir Sementsov-Ogievskiy <[email protected]>

---
Changes from v1:
- fixed compilation without HAVE_NBD_DEVICE (i.e. for Win/BSD)

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org