From nobody Fri Apr 19 01:43:45 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1575256626; cv=none; d=zohomail.com; s=zohoarc; b=OXn3gwClqHqHMB5EzcP/lTn01LtmHacXBYhZ0e1zNBTVUZ2qIg5Or4jWDnHnetgnofJjlxLblOJhkCQoaMG7RdAlZZ/RxaF5zhbEA9EuD1g4LpgAFVZON1TXEnXxmRh7n17JOUAsV02DJS4veeoslvuOnyrPF5TTqLuiWQWaX6E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575256626; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=FJ2pI2cZIk5Nzh1ua31g2uZ45r69CocTHcfhR2xK/0c=; b=lXhhRkL+ztbYrEjJpepvwjTAEx8Y7/SngK+xNyvjsvWNYuW3hspz9QPBbDmYCbTwwoTI8GNK5PkYXrD8k9yyJvCZgVn8EpFdbCcerMtlU45gBdeR01xobw1+0YjCD2aI4CRN4/GYfJIFIHpnHwfqUtK0iTfYV25+r69QS0sVyuc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1575256626453741.1730896294545; Sun, 1 Dec 2019 19:17:06 -0800 (PST) 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-333-7w05RBweMjmo4z28v0FBnA-1; Sun, 01 Dec 2019 22:17:03 -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 EC20DDB62; Mon, 2 Dec 2019 03:16:55 +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 9B8735D9CA; Mon, 2 Dec 2019 03:16:53 +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 758714EA4C; Mon, 2 Dec 2019 03:16:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xB23GgqL031486 for ; Sun, 1 Dec 2019 22:16:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0C4872166B29; Mon, 2 Dec 2019 03:16:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 07E0F2166B27 for ; Mon, 2 Dec 2019 03:16:39 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 839A58E1FFA for ; Mon, 2 Dec 2019 03:16:39 +0000 (UTC) Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-184-hb0YazKYNEGFUZqXbLJvUw-1; Sun, 01 Dec 2019 22:16:35 -0500 Received: by mail-pj1-f51.google.com with SMTP id o11so1668314pjp.9; Sun, 01 Dec 2019 19:16:35 -0800 (PST) Received: from localhost.localdomain.localdomain (li85-137.members.linode.com. [74.207.243.137]) by smtp.gmail.com with ESMTPSA id q6sm20855331pfl.140.2019.12.01.19.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Dec 2019 19:16:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575256625; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FJ2pI2cZIk5Nzh1ua31g2uZ45r69CocTHcfhR2xK/0c=; b=LPtL27d7ehZ0cufGJYFgPUEJXP5CKzgdf7Sc8Vi36xiKyV7CQt48pEHZWoqMdJcNJcTian 8qbhCKgYLezOgM2M4rNGjLT3BDFaDUHslmMrKWDphYoOZMcpyauyVIkCy8WshhJF9PpjNn KWq95nxDJHzOTmXDIO7QsunFGB1Tn2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=v+ZX+750OVM1FtiAHVSHTFBUPKgGah/rph6RvitxM5Q=; b=TlkIUzw9V6rGO1ndsOfWzDTIv3a8uwaQKVoaycnUt0n9vwZSEvWGrSo9HAxAjM9MFd w/Om3AtcptMqr+M8tI/3lzA5X/ttwq6ibv7iVNVxyFhLWiAlyFjfdYZFsaPXRKKmaS6P BwDUb/T2C50ABymzOm4aLKagd8j11/Acm+YzK2iVja5SscFkeom70n9MyylSPgZbV/14 yhzr1SNsIMkTt3tgnw+NY39himiQd/AqYe8vXiDJma0Jzi7t+DHULQ+bOeBHDvPIhf6I idBfJff89GOokjh3QIxkLJZgeT9eo4FJmwfL3ajZ5bgDZO674P04GZ3ZLTjNEO/0h8bl sorQ== X-Gm-Message-State: APjAAAXh/8dXI0+4dX6ZX4mlv1F59M5IzY18lLss7OGrnEAMdmo+24Dq efMdxfu7ikVG6ZeAf335NQLXU6MDYSE= X-Google-Smtp-Source: APXvYqzaukizODH8LYFlb3mmM5ZLsOBT2wNdEEliUi2z6OYPXwy3polwBMjawt7wnMmQ6pObfYYBNw== X-Received: by 2002:a17:90a:3663:: with SMTP id s90mr32420246pjb.1.1575256593830; Sun, 01 Dec 2019 19:16:33 -0800 (PST) From: LanceLiu To: libvir-list@redhat.com Date: Mon, 2 Dec 2019 11:16:21 +0800 Message-Id: <1575256581-21921-1-git-send-email-liu.lance.89@gmail.com> X-MC-Unique: hb0YazKYNEGFUZqXbLJvUw-1 X-MC-Unique: 7w05RBweMjmo4z28v0FBnA-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-MIME-Autoconverted: from quoted-printable to 8bit by lists01.pubmisc.prod.ext.phx2.redhat.com id xB23GgqL031486 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com, LanceLiu Subject: [libvirt] [PATCH] add lock priv->lock protection in remoteClientCloseFunc() 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 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" sometimes, virsh console session may closed by virsh console existed sessio= n(when virsh console client exit) and new virsh console --force session simutaneously. So in one threa= d(Job worker), it calls daemonStreamEvent() and referencing stream, and in another thread(main thre= ad), virNetServerClientClose() was called, and the callback remoteClientCloseFunc() was called, without pr= otect by priv->lock in remoteClientCloseFunc(), it may lead to daemonStreamEvent reference stream = released by remoteClientCloseFunc(), and also need change virNetServerClientClose() to be virNetServerClientImme= diateClose() in daemonStreamEvent(), or it lead to libvirt daemon deadlock by double lock priv->lock in daemonSt= reamEvent() --- src/remote/remote_daemon_dispatch.c | 2 ++ src/remote/remote_daemon_stream.c | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index f369ffb..b0982b7 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -1724,7 +1724,9 @@ static void remoteClientCloseFunc(virNetServerClientP= tr client) { struct daemonClientPrivate *priv =3D virNetServerClientGetPrivateData(= client); =20 + virMutexLock(&priv->lock); daemonRemoveAllClientStreams(priv->streams); + virMutexUnlock(&priv->lock); =20 remoteClientFreePrivateCallbacks(priv); } diff --git a/src/remote/remote_daemon_stream.c b/src/remote/remote_daemon_s= tream.c index 73e4d7b..6a84fdf 100644 --- a/src/remote/remote_daemon_stream.c +++ b/src/remote/remote_daemon_stream.c @@ -141,7 +141,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) (events & VIR_STREAM_EVENT_WRITABLE)) { if (daemonStreamHandleWrite(client, stream) < 0) { daemonRemoveClientStream(client, stream); - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } } @@ -151,7 +151,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) events =3D events & ~(VIR_STREAM_EVENT_READABLE); if (daemonStreamHandleRead(client, stream) < 0) { daemonRemoveClientStream(client, stream); - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } /* If we detected EOF during read processing, @@ -176,7 +176,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) if (daemonStreamHandleFinish(client, stream, msg) < 0) { virNetMessageFree(msg); daemonRemoveClientStream(client, stream); - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } break; @@ -186,7 +186,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) if (daemonStreamHandleAbort(client, stream, msg) < 0) { virNetMessageFree(msg); daemonRemoveClientStream(client, stream); - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } break; @@ -205,7 +205,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) stream->recvEOF =3D true; if (!(msg =3D virNetMessageNew(false))) { daemonRemoveClientStream(client, stream); - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } msg->cb =3D daemonStreamMessageFinished; @@ -219,7 +219,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) "", 0) < 0) { virNetMessageFree(msg); daemonRemoveClientStream(client, stream); - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } } @@ -262,7 +262,7 @@ daemonStreamEvent(virStreamPtr st, int events, void *op= aque) } daemonRemoveClientStream(client, stream); if (ret < 0) - virNetServerClientClose(client); + virNetServerClientImmediateClose(client); goto cleanup; } =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list