From: peterx@redhat.com
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Fabiano Rosas <farosas@suse.de>,
Prasad Pandit <ppandit@redhat.com>,
peterx@redhat.com, David Hildenbrand <david@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PULL 10/10] migration/multifd: Duplicate the fd for the outgoing_args
Date: Sun, 17 Mar 2024 16:58:03 -0400 [thread overview]
Message-ID: <20240317205803.361163-11-peterx@redhat.com> (raw)
In-Reply-To: <20240317205803.361163-1-peterx@redhat.com>
From: Fabiano Rosas <farosas@suse.de>
We currently store the file descriptor used during the main outgoing
channel creation to use it again when creating the multifd
channels.
Since this fd is used for the first iochannel, there's risk that the
QIOChannel gets freed and the fd closed while outgoing_args.fd still
has it available. This could lead to an fd-reuse bug.
Duplicate the outgoing_args fd to avoid this issue.
Suggested-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Peter Xu <peterx@redhat.com>
Link: https://lore.kernel.org/r/20240315032040.7974-3-farosas@suse.de
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/fd.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/migration/fd.c b/migration/fd.c
index c07030f715..fe0d096abd 100644
--- a/migration/fd.c
+++ b/migration/fd.c
@@ -49,8 +49,7 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
{
QIOChannel *ioc;
int fd = monitor_get_fd(monitor_cur(), fdname, errp);
-
- outgoing_args.fd = -1;
+ int newfd;
if (fd == -1) {
return;
@@ -63,7 +62,17 @@ void fd_start_outgoing_migration(MigrationState *s, const char *fdname, Error **
return;
}
- outgoing_args.fd = fd;
+ /*
+ * This is dup()ed just to avoid referencing an fd that might
+ * be already closed by the iochannel.
+ */
+ newfd = dup(fd);
+ if (newfd == -1) {
+ error_setg_errno(errp, errno, "Could not dup FD %d", fd);
+ object_unref(ioc);
+ return;
+ }
+ outgoing_args.fd = newfd;
qio_channel_set_name(ioc, "migration-fd-outgoing");
migration_channel_connect(s, ioc, NULL, NULL);
--
2.44.0
next prev parent reply other threads:[~2024-03-17 20:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-17 20:57 [PULL 00/10] Migration 20240317 patches peterx
2024-03-17 20:57 ` [PULL 01/10] io: Introduce qio_channel_file_new_dupfd peterx
2024-03-17 20:57 ` [PULL 02/10] migration: Fix error handling after dup in file migration peterx
2024-03-17 20:57 ` [PULL 03/10] physmem: Expose tlb_reset_dirty_range_all() peterx
2024-03-17 20:57 ` [PULL 04/10] physmem: Factor cpu_physical_memory_dirty_bits_cleared() out peterx
2024-03-17 20:57 ` [PULL 05/10] physmem: Fix migration dirty bitmap coherency with TCG memory access peterx
2024-03-17 20:57 ` [PULL 06/10] migration: Skip only empty block devices peterx
2024-03-17 20:58 ` [PULL 07/10] migration: cpr-reboot documentation peterx
2024-03-17 20:58 ` [PULL 08/10] migration: Fix iocs leaks during file and fd migration peterx
2024-03-17 20:58 ` [PULL 09/10] migration/multifd: Ensure we're not given a socket for file migration peterx
2024-03-17 20:58 ` peterx [this message]
2024-03-19 10:23 ` [PULL 00/10] Migration 20240317 patches Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240317205803.361163-11-peterx@redhat.com \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=farosas@suse.de \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=ppandit@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).