Skip to content

Commit

Permalink
qemu-nbd: regression with arguments passing into nbd_client_thread()
Browse files Browse the repository at this point in the history
Unfortunately
    commit 03b6762
    (8.0:  feb0814)
    Author: Denis V. Lunev <den@openvz.org>
    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.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Eric Blake <eblake@redhat.com>
CC: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
CC: <qemu-stable@nongnu.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-ID: <20230727105828.324314-1-den@openvz.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit e5b815b)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
(Mjt: add reference to feb0814 for 8.0 branch)
  • Loading branch information
Denis V. Lunev authored and Michael Tokarev committed Jul 31, 2023
1 parent bdfecfb commit 5a61789
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qemu-nbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,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();
Expand Down Expand Up @@ -1120,7 +1123,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,
};
Expand Down

0 comments on commit 5a61789

Please sign in to comment.