From nobody Mon Feb 9 16:19:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1550239834154529.8506773133257; Fri, 15 Feb 2019 06:10:34 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6139F7AEAF; Fri, 15 Feb 2019 14:10:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DC2355F9C0; Fri, 15 Feb 2019 14:10:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 21B7E3F7D5; Fri, 15 Feb 2019 14:10:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1FEAQG8029191 for ; Fri, 15 Feb 2019 09:10:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id B0EEC1024904; Fri, 15 Feb 2019 14:10:26 +0000 (UTC) Received: from mx1.redhat.com (ext-mx10.extmail.prod.ext.phx2.redhat.com [10.5.110.39]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A6931101E843 for ; Fri, 15 Feb 2019 14:10:23 +0000 (UTC) Received: from relay.sw.ru (relay.sw.ru [185.231.240.75]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B3B3C1301D5 for ; Fri, 15 Feb 2019 14:10:21 +0000 (UTC) Received: from [10.94.3.220] (helo=dim-vz7.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gueC3-00053q-BE for libvir-list@redhat.com; Fri, 15 Feb 2019 17:10:19 +0300 From: Nikolay Shirokovskiy To: libvir-list@redhat.com Date: Fri, 15 Feb 2019 17:10:12 +0300 Message-Id: <1550239813-870626-2-git-send-email-nshirokovskiy@virtuozzo.com> In-Reply-To: <1550239813-870626-1-git-send-email-nshirokovskiy@virtuozzo.com> References: <1550239813-870626-1-git-send-email-nshirokovskiy@virtuozzo.com> X-Greylist: Sender passed SPF test, ACL 242 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 15 Feb 2019 14:10:22 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 15 Feb 2019 14:10:22 +0000 (UTC) for IP:'185.231.240.75' DOMAIN:'relay.sw.ru' HELO:'relay.sw.ru' FROM:'nshirokovskiy@virtuozzo.com' RCPT:'' X-RedHat-Spam-Score: -0.001 (SPF_PASS) 185.231.240.75 relay.sw.ru 185.231.240.75 relay.sw.ru X-Scanned-By: MIMEDefang 2.78 on 10.5.110.39 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] rpc: client: fix race on stream error and stream creation X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 15 Feb 2019 14:10:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Message of API call that creates stream and stream itself have same rpc serial. This can lead to issues. If stream got error immediately after creation then notification can be delivered before API call reply arrived. This is possible because the reply and the error message are sent from different threads (rpc worker thread and event loop thread respectively). As we don't check for message type in virNetClientCallCompleteAllWaitingReply we complete the API call which leads to API call error [1] as there is no actual reply. Later when reply arrives connection will be closed due to protocol error (see check in virNetClientCallDispatch= Reply). Let's fix virNetClientCallCompleteAllWaitingReply. Queue inspection on arriving VIR_NET_CONTINUE message in virNetClientCallDispatchStream is safe because there we check for status field also. Queue inspection on arriving VIR_NET_OK is safe too as this message can not arrive before we call virFinishAbort(Finish) which is not possible before API call that creates streams returns. But just to be sure let's add checking message type in these places too. [1] error: internal error: Unexpected message type 0 Signed-off-by: Nikolay Shirokovskiy --- src/rpc/virnetclient.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rpc/virnetclient.c b/src/rpc/virnetclient.c index 64855fb..0393587 100644 --- a/src/rpc/virnetclient.c +++ b/src/rpc/virnetclient.c @@ -1163,7 +1163,8 @@ static void virNetClientCallCompleteAllWaitingReply(v= irNetClientPtr client) virNetClientCallPtr call; =20 for (call =3D client->waitDispatch; call; call =3D call->next) { - if (call->msg->header.prog =3D=3D client->msg.header.prog && + if (call->msg->header.type =3D=3D VIR_NET_STREAM && + call->msg->header.prog =3D=3D client->msg.header.prog && call->msg->header.vers =3D=3D client->msg.header.vers && call->msg->header.serial =3D=3D client->msg.header.serial && call->expectReply) @@ -1207,7 +1208,8 @@ static int virNetClientCallDispatchStream(virNetClien= tPtr client) =20 /* Find oldest dummy message waiting for incoming data. */ for (thecall =3D client->waitDispatch; thecall; thecall =3D thecal= l->next) { - if (thecall->msg->header.prog =3D=3D client->msg.header.prog && + if (thecall->msg->header.type =3D=3D VIR_NET_STREAM && + thecall->msg->header.prog =3D=3D client->msg.header.prog && thecall->msg->header.vers =3D=3D client->msg.header.vers && thecall->msg->header.serial =3D=3D client->msg.header.seri= al && thecall->expectReply && @@ -1225,7 +1227,8 @@ static int virNetClientCallDispatchStream(virNetClien= tPtr client) case VIR_NET_OK: /* Find oldest abort/finish message. */ for (thecall =3D client->waitDispatch; thecall; thecall =3D thecal= l->next) { - if (thecall->msg->header.prog =3D=3D client->msg.header.prog && + if (thecall->msg->header.type =3D=3D VIR_NET_STREAM && + thecall->msg->header.prog =3D=3D client->msg.header.prog && thecall->msg->header.vers =3D=3D client->msg.header.vers && thecall->msg->header.serial =3D=3D client->msg.header.seri= al && thecall->expectReply && --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list