Received: by 2002:a19:c345:0:0:0:0:0 with SMTP id t66csp5492435lff; Tue, 14 Jan 2020 05:15:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzfac1+nqTlTGJd/e+r+oBy5LTKc0EAdv9K4th2+CifEbvH1bnWAIWINi1PqXQ5f7r1CvB4 X-Received: by 2002:a17:906:b212:: with SMTP id p18mr22557906ejz.208.1579007718478; Tue, 14 Jan 2020 05:15:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579007718; cv=none; d=google.com; s=arc-20160816; b=a8MuhcgWLG1at8tR2leLpQJVpUdBlSFd3OktZWpuDIhXVnN6RMY2XdQ0dOCESQ0Wkc laN+WmyzecS1oMWfDymBZhTQsGjJwYy9gcppK3BV0OalGQFfExHMo7IgeoyXtBK23haS GY0bcsKXzFLMm9HLMiXr57aVNTKjn3seicbw1GSTa5c7Le+b+sD1OPz9N9hgum7YLI01 W+sQyd0Jw6kq1iI/NW1tRkX9u3HPZXpaWfOhxfRxihAHtk4IwtwwiDKQBFwHtxXsL1Ea II/Qs4fxyg275Z3fWnKtOtKs1qGU3Sv3fZJBkY3A8Y2qyZyp/davmsvA67I3uvWGqNnK YWaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=UCvNgXqg3YNciEEz4bwYVicJE+TkN+xTZTIh75LexRo=; b=j7gE8U94HCxSpmX+uo8D3/bK9NW07/ceKAuMvr6HVzlYY/GXBA3TB5ZMOmDUZGQviN +fUPf1lDK7KM4Mo038zI1u71+7HGf8Txh9nbq0LBlSAJw93Y7XM+JNVr7rMrE+0+0LNj D7Kai7WGwMVFkXme9uEjKUN5G3i+Ttm7ulBwBqjgbE02zHW7p80yXsDEMwUPHSu5en0F bwsJG+RgURh/Qeak4ztI111TD5oN6VjfbpnhbBKtkOK4wxKr8y7K5ZHMybH9v2j3RvCy uLOBKf/spV+nMEnZsuMOJixYSTHCDWkqzBevA/z81FhVTT5QwlFoC3tJ1MQnUAJxXjvC Hc9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b="NhDBw/9F"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id dc17si10480382ejb.243.2020.01.14.05.15.18 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 14 Jan 2020 05:15:18 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b="NhDBw/9F"; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:39204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irM2O-0003Ze-Qm for alex.bennee@linaro.org; Tue, 14 Jan 2020 08:15:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:41682) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1irLk9-00040M-2p for qemu-arm@nongnu.org; Tue, 14 Jan 2020 07:56:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1irLk5-0002FO-J1 for qemu-arm@nongnu.org; Tue, 14 Jan 2020 07:56:22 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:36095 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1irLk5-0002FC-DN for qemu-arm@nongnu.org; Tue, 14 Jan 2020 07:56:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579006581; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UCvNgXqg3YNciEEz4bwYVicJE+TkN+xTZTIh75LexRo=; b=NhDBw/9FkzHVHOZllh9jPOAHOVXP2XLTBEglvmYYar+JJwBbnIYVNOUuGMcHcQdUiWlD7a 1iV1CZo8iyGKBw4wGoTor/A8nWWKfLDJFM7dYOn6Vr/xt/HuxFFOC24MF89UnRnDhXmZc0 QD4ZSqWO/5ZAiAW46crrZL1gY6cWUKY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-234-LgSCKFThNZqpzVtJSuMUPA-1; Tue, 14 Jan 2020 07:56:19 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68A85801E72; Tue, 14 Jan 2020 12:56:17 +0000 (UTC) Received: from secure.mitica (ovpn-116-207.ams2.redhat.com [10.36.116.207]) by smtp.corp.redhat.com (Postfix) with ESMTP id BFA415D9E5; Tue, 14 Jan 2020 12:56:12 +0000 (UTC) From: Juan Quintela To: qemu-devel@nongnu.org Subject: [PULL 24/30] migration/multifd: fix nullptr access in terminating multifd threads Date: Tue, 14 Jan 2020 13:52:48 +0100 Message-Id: <20200114125254.4515-25-quintela@redhat.com> In-Reply-To: <20200114125254.4515-1-quintela@redhat.com> References: <20200114125254.4515-1-quintela@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: LgSCKFThNZqpzVtJSuMUPA-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.120 X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Corey Minyard , Jason Wang , Jiahui Cen , Juan Quintela , "Michael S. Tsirkin" , Marcel Apfelbaum , Ying Fang , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , David Gibson , Andrzej Zaborowski , Laurent Vivier , Thomas Huth , Eduardo Habkost , Stefan Weil , "Dr. David Alan Gilbert" , qemu-arm@nongnu.org, Richard Henderson , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , qemu-ppc@nongnu.org, Paolo Bonzini , Stefan Berger Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: uZ5cC7V5MMlF From: Jiahui Cen One multifd channel will shutdown all the other multifd's IOChannel when it fails to receive an IOChannel. In this senario, if some multifds had not received its IOChannel yet, it would try to shutdown its IOChannel which co= uld cause nullptr access at qio_channel_shutdown. Here is the coredump stack: #0 object_get_class (obj=3Dobj@entry=3D0x0) at qom/object.c:908 #1 0x00005563fdbb8f4a in qio_channel_shutdown (ioc=3D0x0, how=3DQIO_CH= ANNEL_SHUTDOWN_BOTH, errp=3D0x0) at io/channel.c:355 #2 0x00005563fd7b4c5f in multifd_recv_terminate_threads (err=3D) at migration/ram.c:1280 #3 0x00005563fd7bc019 in multifd_recv_new_channel (ioc=3Dioc@entry=3D0= x556400255610, errp=3Derrp@entry=3D0x7ffec07dce00) at migration/ram.c:1478 #4 0x00005563fda82177 in migration_ioc_process_incoming (ioc=3Dioc@ent= ry=3D0x556400255610, errp=3Derrp@entry=3D0x7ffec07dce30) at migration/migra= tion.c:605 #5 0x00005563fda8567d in migration_channel_process_incoming (ioc=3D0x5= 56400255610) at migration/channel.c:44 #6 0x00005563fda83ee0 in socket_accept_incoming_migration (listener=3D= 0x5563fff6b920, cioc=3D0x556400255610, opaque=3D) at migrati= on/socket.c:166 #7 0x00005563fdbc25cd in qio_net_listener_channel_func (ioc=3D, condition=3D, opaque=3D) at io/net-l= istener.c:54 #8 0x00007f895b6fe9a9 in g_main_context_dispatch () from /usr/lib64/li= bglib-2.0.so.0 #9 0x00005563fdc18136 in glib_pollfds_poll () at util/main-loop.c:218 #10 0x00005563fdc181b5 in os_host_main_loop_wait (timeout=3D1000000000)= at util/main-loop.c:241 #11 0x00005563fdc183a2 in main_loop_wait (nonblocking=3Dnonblocking@ent= ry=3D0) at util/main-loop.c:517 #12 0x00005563fd8edb37 in main_loop () at vl.c:1791 #13 0x00005563fd74fd45 in main (argc=3D, argv=3D, envp=3D) at vl.c:4473 To fix it up, let's check p->c before calling qio_channel_shutdown. Signed-off-by: Jiahui Cen Signed-off-by: Ying Fang Reviewed-by: Juan Quintela Signed-off-by: Juan Quintela --- migration/ram.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/migration/ram.c b/migration/ram.c index aee057f7da..e7cd522173 100644 --- a/migration/ram.c +++ b/migration/ram.c @@ -1308,7 +1308,9 @@ static void multifd_recv_terminate_threads(Error *err= ) - normal quit, i.e. everything went fine, just finished - error quit: We close the channels so the channel threads finish the qio_channel_read_all_eof() */ - qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + if (p->c) { + qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL); + } qemu_mutex_unlock(&p->mutex); } } --=20 2.24.1