From nobody Sat May 11 14:27:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1710365338; cv=none; d=zohomail.com; s=zohoarc; b=gmLH3GBTJP9RGImZguqzHWRW9PLmK2rMsxQFeoMnqUjkl2FloQFEeDqP8eu+hLq0M49ey0PX9bo6dCRmZXI5PpDSWPehlCTOKTwmcYoOp/NyeDSsq+SkFi+NBkaF6zBwEGqAHdYXTgqCxTQbTHdmNnOhZfYl4rR45HzarsfUzw8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710365338; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7cX6bB0KFmqQRRvMEhyeCMzPVc0iaic9MJrea1Qqjbo=; b=aOfHnjTS7fBKA9bidfabJHbUg989VtWxe4rC6c8W/dN54jN9r58WbE4sLkMRxEt10CbQSn6NZ+y+wWtCPFLVLnY2itvZ5UlKLunhIPje+0Mx3uxvXCbxgXqgWrxBuSi2bK+0eY3wd+PDuKYvyQQ6Od1SvXApk1vsPGF7QJllUEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 171036533873120.674262416675447; Wed, 13 Mar 2024 14:28:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkW9P-0007Qs-AA; Wed, 13 Mar 2024 17:28:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkW9O-0007Qh-G1 for qemu-devel@nongnu.org; Wed, 13 Mar 2024 17:28:38 -0400 Received: from smtp-out2.suse.de ([195.135.223.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkW9J-0006p6-AG for qemu-devel@nongnu.org; Wed, 13 Mar 2024 17:28:34 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C28D61F7F1; Wed, 13 Mar 2024 21:28:30 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 9A12D13977; Wed, 13 Mar 2024 21:28:29 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id 2MZDGH0a8mX/ZQAAD6G6ig (envelope-from ); Wed, 13 Mar 2024 21:28:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710365311; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cX6bB0KFmqQRRvMEhyeCMzPVc0iaic9MJrea1Qqjbo=; b=BFUz0umQwmYX6W9v515VFQvpxL6YOPdqOL/0i+xzusfRfcJcXeQoeLyg7AV61sKhcCA90X 96GpTn95l7Dfv/Kj9d9l1Mvp5YEph2MPKPoDrBs6NHt1lG1TohVyAn5n8WMIFL/f072EWG HRgKwxOrZTIR5sQJA2obJxY+TD31x6g= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710365311; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cX6bB0KFmqQRRvMEhyeCMzPVc0iaic9MJrea1Qqjbo=; b=hCprlf2+6GX0mjSYwhzSz7+Tm//844Q4ZXPKfxI3Nt+v4/fL8NNYflUY3XUc9RbveT6q0M MbvJDqkXkoGbg5DA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710365310; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cX6bB0KFmqQRRvMEhyeCMzPVc0iaic9MJrea1Qqjbo=; b=arLz/xxJZybcqviND+40rXYir7hmbwOl+SPNP55UR7N3W7KGOpDUyi46vVzn0euXtA95QV DLc/TJyse7aXnHkKM1UFk9GoArXX6rYAzjf89k6a7BdjWKnjKAU8SLmJnVMXxZqWqWJXYK 9ou5iUrjxDZO3ocMTDGBvOAFWmd5Kj0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710365310; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7cX6bB0KFmqQRRvMEhyeCMzPVc0iaic9MJrea1Qqjbo=; b=j+zqssmpsk/hmpLE4JeUKXRji9EKlMycg1mVTaZMMGHRRMRtVitY3FjlfFl1FSvDjVMmNy x17CgWo6xh2bUaAg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Peter Xu Subject: [PATCH v2 1/2] migration: Fix iocs leaks during file and fd migration Date: Wed, 13 Mar 2024 18:28:23 -0300 Message-Id: <20240313212824.16974-2-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240313212824.16974-1-farosas@suse.de> References: <20240313212824.16974-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: / Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="arLz/xxJ"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=j+zqssmp X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [0.49 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; TO_DN_SOME(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+]; MX_GOOD(-0.01)[]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; NEURAL_HAM_SHORT(-0.20)[-1.000]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 0.49 X-Rspamd-Queue-Id: C28D61F7F1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=195.135.223.131; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1710365340333100001 Content-Type: text/plain; charset="utf-8" The memory for the io channels is being leaked in three different ways during file migration: 1) if the offset check fails we never drop the ioc reference; 2) we allocate an extra channel for no reason; 3) if multifd is enabled but channel creation fails when calling dup(), we leave the previous channels around along with the glib polling; Fix all issues by restructuring the code to first allocate the channels and only register the watches when all channels have been created. For multifd, the file and fd migrations can share code because both are backed by a QIOChannelFile. For the non-multifd case, the fd needs to be separate because it is backed by a QIOChannelSocket. Fixes: 2dd7ee7a51 ("migration/multifd: Add incoming QIOChannelFile support") Fixes: decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") Reported-by: Peter Xu Signed-off-by: Fabiano Rosas Reviewed-by: Peter Xu based-on: https://gitlab.com/peterx/qemu/-/commits/migration-stable --- migration/fd.c | 29 +++++++----------------- migration/file.c | 58 ++++++++++++++++++++++++++++++------------------ migration/file.h | 1 + 3 files changed, 46 insertions(+), 42 deletions(-) diff --git a/migration/fd.c b/migration/fd.c index 4e2a63a73d..39a52e5c90 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -18,6 +18,7 @@ #include "qapi/error.h" #include "channel.h" #include "fd.h" +#include "file.h" #include "migration.h" #include "monitor/monitor.h" #include "io/channel-file.h" @@ -80,7 +81,6 @@ static gboolean fd_accept_incoming_migration(QIOChannel *= ioc, void fd_start_incoming_migration(const char *fdname, Error **errp) { QIOChannel *ioc; - QIOChannelFile *fioc; int fd =3D monitor_fd_param(monitor_cur(), fdname, errp); if (fd =3D=3D -1) { return; @@ -94,26 +94,13 @@ void fd_start_incoming_migration(const char *fdname, Er= ror **errp) return; } =20 - qio_channel_set_name(ioc, "migration-fd-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, - fd_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()); - if (migrate_multifd()) { - int channels =3D migrate_multifd_channels(); - - while (channels--) { - fioc =3D qio_channel_file_new_dupfd(fd, errp); - if (!fioc) { - return; - } - - qio_channel_set_name(ioc, "migration-fd-incoming"); - qio_channel_add_watch_full(QIO_CHANNEL(fioc), G_IO_IN, - fd_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()= ); - } + file_create_incoming_channels(ioc, errp); + } else { + qio_channel_set_name(ioc, "migration-fd-incoming"); + qio_channel_add_watch_full(ioc, G_IO_IN, + fd_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); } } diff --git a/migration/file.c b/migration/file.c index e56c5eb0a5..ddde0ca818 100644 --- a/migration/file.c +++ b/migration/file.c @@ -115,13 +115,46 @@ static gboolean file_accept_incoming_migration(QIOCha= nnel *ioc, return G_SOURCE_REMOVE; } =20 +void file_create_incoming_channels(QIOChannel *ioc, Error **errp) +{ + int i, fd, channels =3D 1; + g_autofree QIOChannel **iocs =3D NULL; + + if (migrate_multifd()) { + channels +=3D migrate_multifd_channels(); + } + + iocs =3D g_new0(QIOChannel *, channels); + fd =3D QIO_CHANNEL_FILE(ioc)->fd; + iocs[0] =3D ioc; + + for (i =3D 1; i < channels; i++) { + QIOChannelFile *fioc =3D qio_channel_file_new_dupfd(fd, errp); + + if (!fioc) { + while (i) { + object_unref(iocs[--i]); + } + return; + } + + iocs[i] =3D QIO_CHANNEL(fioc); + } + + for (i =3D 0; i < channels; i++) { + qio_channel_set_name(iocs[i], "migration-file-incoming"); + qio_channel_add_watch_full(iocs[i], G_IO_IN, + file_accept_incoming_migration, + NULL, NULL, + g_main_context_get_thread_default()); + } +} + void file_start_incoming_migration(FileMigrationArgs *file_args, Error **e= rrp) { g_autofree char *filename =3D g_strdup(file_args->filename); QIOChannelFile *fioc =3D NULL; uint64_t offset =3D file_args->offset; - int channels =3D 1; - int i =3D 0; =20 trace_migration_file_incoming(filename); =20 @@ -132,28 +165,11 @@ void file_start_incoming_migration(FileMigrationArgs = *file_args, Error **errp) =20 if (offset && qio_channel_io_seek(QIO_CHANNEL(fioc), offset, SEEK_SET, errp) < 0= ) { + object_unref(OBJECT(fioc)); return; } =20 - if (migrate_multifd()) { - channels +=3D migrate_multifd_channels(); - } - - do { - QIOChannel *ioc =3D QIO_CHANNEL(fioc); - - qio_channel_set_name(ioc, "migration-file-incoming"); - qio_channel_add_watch_full(ioc, G_IO_IN, - file_accept_incoming_migration, - NULL, NULL, - g_main_context_get_thread_default()); - - fioc =3D qio_channel_file_new_dupfd(fioc->fd, errp); - - if (!fioc) { - break; - } - } while (++i < channels); + file_create_incoming_channels(QIO_CHANNEL(fioc), errp); } =20 int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, diff --git a/migration/file.h b/migration/file.h index 9f71e87f74..7699c04677 100644 --- a/migration/file.h +++ b/migration/file.h @@ -20,6 +20,7 @@ void file_start_outgoing_migration(MigrationState *s, int file_parse_offset(char *filespec, uint64_t *offsetp, Error **errp); void file_cleanup_outgoing_migration(void); bool file_send_channel_create(gpointer opaque, Error **errp); +void file_create_incoming_channels(QIOChannel *ioc, Error **errp); int file_write_ramblock_iov(QIOChannel *ioc, const struct iovec *iov, int niov, RAMBlock *block, Error **errp); int multifd_file_recv_data(MultiFDRecvParams *p, Error **errp); --=20 2.35.3 From nobody Sat May 11 14:27:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1710365346; cv=none; d=zohomail.com; s=zohoarc; b=klk+QuUvPbjQ4KOC6xJ/vEjU9wbyVPFOWkGfdBgiR2YTBEjoXD3dOAkFszb33Bz+jqpvwN/Y66GnlsDmvmDR3kne7NQSrPrY9J4espGowFNAYDSub4HNNF866CmjOyVZ3THL9AKlbF+sU1iDWYi0N9TO+UCEcT1pc7la/IAg8fM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710365346; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1krFGZjeXVQYSZrWORLsRFUd1Ebi+C3zBAT6pb9nTBU=; b=LSy89Zb1NYSzWdgCJmIIVAFAUkJnzxE+kpZWv9YN8wicweEzmyLnoLOOPavYTJd4PVQBzhQ/b9lDSDaIfMjarKu9Mv0nNHoI3DyroK+mwv6HLL3uK9h/WWwimMtBrXzLRnkA03Cqmq1BreC05mjv86Y56bBiX5w2ldpyV2ngEiI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710365346087870.8997601473034; Wed, 13 Mar 2024 14:29:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rkW9S-0007Rv-GZ; Wed, 13 Mar 2024 17:28:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkW9P-0007RK-OX for qemu-devel@nongnu.org; Wed, 13 Mar 2024 17:28:39 -0400 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rkW9O-0006pW-1b for qemu-devel@nongnu.org; Wed, 13 Mar 2024 17:28:39 -0400 Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 678EF1F7F4; Wed, 13 Mar 2024 21:28:32 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 432EB13977; Wed, 13 Mar 2024 21:28:31 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap1.dmz-prg2.suse.org with ESMTPSA id cEB/An8a8mX/ZQAAD6G6ig (envelope-from ); Wed, 13 Mar 2024 21:28:31 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710365313; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1krFGZjeXVQYSZrWORLsRFUd1Ebi+C3zBAT6pb9nTBU=; b=E0DRAjTeEUrCXmR8jCHuIKUgIQYe7JelzlZW3b6ZNloC7y+i8Nn51/W60an/ylXD4mpws9 ULYov8GxP0ioicSLp20kgwcr/pKmkjRGCYUSM2BvqYfdJOukZvgmX8ZS0YLmInzkR9JsnD bOmBP43kZH7JU7QnO6yvn9kjnz7FjxQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710365313; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1krFGZjeXVQYSZrWORLsRFUd1Ebi+C3zBAT6pb9nTBU=; b=zh+sE9QIOspCSmifbZiAKkPcfekRDLjDglUxMo/7vEJzCk98Ku2jha30AbtdNb86cBYc/z Px7/S3sCPHMkPqBg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1710365312; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1krFGZjeXVQYSZrWORLsRFUd1Ebi+C3zBAT6pb9nTBU=; b=qijwhVai4tbiNO3Xjem+HWT0VuAxaY+vcxY/4r8qgnWFpxrBCl4N7pBb6t3aKA/dIMq9i8 +3FveIYFy/vNw1hbNPeK+WyV5DQBG4C+HOxLndmDzngiwtn9YParn9tBcY04as0ea5V8Je lLMuw7tmVmFQ6+h6LOkj4cVeRi61MZU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1710365312; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1krFGZjeXVQYSZrWORLsRFUd1Ebi+C3zBAT6pb9nTBU=; b=c1sXS9s2njKhDSZwzG939OE5/duv+rTCCisEjZglQpPLuO/eZ6YTVkwBBT5PMVcncoyGXi mjGmW/OcIdCr7/Ag== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Peter Xu Subject: [PATCH v2 2/2] migration/multifd: Ensure we're not given a socket for file migration Date: Wed, 13 Mar 2024 18:28:24 -0300 Message-Id: <20240313212824.16974-3-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240313212824.16974-1-farosas@suse.de> References: <20240313212824.16974-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [1.90 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 1.90 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a07:de40:b251:101:10:150:64:2; envelope-from=farosas@suse.de; helo=smtp-out2.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) (identity @suse.de) X-ZM-MESSAGEID: 1710365348076100003 Content-Type: text/plain; charset="utf-8" When doing migration using the fd: URI, the incoming migration starts before the user has passed the file descriptor to QEMU. This means that the checks at migration_channels_and_transport_compatible() happen too soon and we need to allow a migration channel of type SOCKET_ADDRESS_TYPE_FD even though socket migration is not supported with multifd. The commit decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") was supposed to add a second check prior to starting migration to make sure a socket fd is not passed instead of a file fd, but failed to do so. Add the missing verification. Fixes: decdc76772 ("migration/multifd: Add mapped-ram support to fd: URI") Signed-off-by: Fabiano Rosas based-on: https://gitlab.com/peterx/qemu/-/commits/migration-stable --- migration/fd.c | 8 ++++++++ migration/file.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/migration/fd.c b/migration/fd.c index 39a52e5c90..c07030f715 100644 --- a/migration/fd.c +++ b/migration/fd.c @@ -22,6 +22,7 @@ #include "migration.h" #include "monitor/monitor.h" #include "io/channel-file.h" +#include "io/channel-socket.h" #include "io/channel-util.h" #include "options.h" #include "trace.h" @@ -95,6 +96,13 @@ void fd_start_incoming_migration(const char *fdname, Err= or **errp) } =20 if (migrate_multifd()) { + if (fd_is_socket(fd)) { + error_setg(errp, + "Multifd migration to a socket FD is not supported"= ); + object_unref(ioc); + return; + } + file_create_incoming_channels(ioc, errp); } else { qio_channel_set_name(ioc, "migration-fd-incoming"); diff --git a/migration/file.c b/migration/file.c index ddde0ca818..b6e8ba13f2 100644 --- a/migration/file.c +++ b/migration/file.c @@ -15,6 +15,7 @@ #include "file.h" #include "migration.h" #include "io/channel-file.h" +#include "io/channel-socket.h" #include "io/channel-util.h" #include "options.h" #include "trace.h" @@ -58,6 +59,12 @@ bool file_send_channel_create(gpointer opaque, Error **e= rrp) int fd =3D fd_args_get_fd(); =20 if (fd && fd !=3D -1) { + if (fd_is_socket(fd)) { + error_setg(errp, + "Multifd migration to a socket FD is not supported"= ); + goto out; + } + ioc =3D qio_channel_file_new_dupfd(fd, errp); } else { ioc =3D qio_channel_file_new_path(outgoing_args.fname, flags, 0, e= rrp); --=20 2.35.3