From patchwork Mon Feb 8 17:03:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8252661 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 94AE99F1C1 for ; Mon, 8 Feb 2016 17:11:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E08AF20145 for ; Mon, 8 Feb 2016 17:11:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3BBB820107 for ; Mon, 8 Feb 2016 17:11:56 +0000 (UTC) Received: from localhost ([::1]:46919 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpLv-0000nt-Fi for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Feb 2016 12:11:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43460) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpDy-0003QP-MU for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aSpDx-0006nk-SS for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:42 -0500 Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:35387) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aSpDx-0006nM-M4 for qemu-devel@nongnu.org; Mon, 08 Feb 2016 12:03:41 -0500 Received: by mail-wm0-x233.google.com with SMTP id c200so25247766wme.0 for ; Mon, 08 Feb 2016 09:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3U14aoJtpijZ+19wz9C9+U+DAGUj1jdEBRtFUVjr+bI=; b=lqM3y+zduiVWBDdub+Yh8TWKK8jAVmIDiPX+MhpuEjnFZoycW4PV5XzqoAFHEkipsd 1mCCJHIRgVYit/KjRMWv+1UPUAD3lRQuJUuWJrIfyNOaaAg7tinIiB9Di/lywhIe0zt0 l1QeNY/wWW0+YmgBCuZR+k8GeatAAw/ZkYhcq6hCUfPPsTtRJ+trqqrbtPX6wBDg86tW sF/q5c6hjM+QOb6nunXP7Pjmm20AVS2pi0mq9mXog5TUKFBiQokSi/xgs+0WSNtJt/Il XbXbPZRZMgjQieXuTb6vnlF9PfN8RCvQCQgv/ZxuzknyyeMC/5lsOTHrvHK3fME+jXFH P4qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=3U14aoJtpijZ+19wz9C9+U+DAGUj1jdEBRtFUVjr+bI=; b=V/+0bZl4nLpbFpj1oXQ/NidJnUIO0DENEw8qx2m4UPQWdnNKGgL7YapztoKeABDtoD VpCb6tRnrJoVDx3M7vZsVXwXJ9tB7rfdkzYw+ptUcEaVOPIudwpxqlcXybUruqh1EqSz YvvgNXQrBCukpnRqzUPvrzvYTpuAitRupTx1O+ogZt8lN3H245CWG2yuZT2mjrbiIrKz x+fPQAGMLY6A9hfTzaNDNLSpocBXO0E6noddo6Z9ZyHFp/L7azhZdY1xH5YUZI+zPMoU JPwhbfmgXctS00NuHHVXxl0a/6UamY98lLm+isCUKbp9ckH/FggdRb3h0R5libR22k0a Fgig== X-Gm-Message-State: AG10YORsUSfGznnN1wQNvD3Q8g+ib2pladIOCoDNj34vzStIoie2k7RQqh5fpGYwYeNlAA== X-Received: by 10.194.21.101 with SMTP id u5mr34163766wje.53.1454951021138; Mon, 08 Feb 2016 09:03:41 -0800 (PST) Received: from 640k.lan (94-39-141-130.adsl-ull.clienti.tiscali.it. [94.39.141.130]) by smtp.gmail.com with ESMTPSA id b1sm30651442wjy.0.2016.02.08.09.03.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Feb 2016 09:03:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 8 Feb 2016 18:03:06 +0100 Message-Id: <1454950999-64128-16-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1454950999-64128-1-git-send-email-pbonzini@redhat.com> References: <1454950999-64128-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::233 Subject: [Qemu-devel] [PULL 15/28] char: fix repeated registration of tcp chardev I/O handlers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Daniel P. Berrange" In previous commit: commit f2001a7e0555b66d6db25a3ff1801540814045bb Author: Daniel P. Berrange Date: Tue Jan 19 11:14:30 2016 +0000 char: don't assume telnet initialization will not block The code which writes the telnet initialization sequence moved to an event loop callback. If the TCP chardev is opened as a server in blocking mode (ie -serial telnet:0.0.0.0:3000,server,wait) this results in a state where the TCP chardev is connected, but not yet ready to send/recv data when virtual hardware is created. When the virtual hardware initialization registers its chardev callbacks, it triggers tcp_chr_update_read_handler, which will add I/O watches to the connection. When the telnet initialization finally runs, it will then call tcp_chr_connect to finish the connection setup. This will in turn add I/O watches to the connection too. There are now two sets of I/O watches registered on the same connection. This ultimately causes data loss on the connection, for example, when typing into the telnet console only every second byte is echoed back to the client. The same flaw can affect channels running with TLS encryption too, since they also have delayed connection setup completion. The fix is to update tcp_chr_update_read_handler so that it avoids registering watches if the connection is not fully setup yet. Signed-off-by: Daniel P. Berrange Message-Id: <1454939707-10869-1-git-send-email-berrange@redhat.com> Signed-off-by: Paolo Bonzini --- qemu-char.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qemu-char.c b/qemu-char.c index 1fbccf0..84eb8a1 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2858,6 +2858,10 @@ static void tcp_chr_update_read_handler(CharDriverState *chr) { TCPCharDriver *s = chr->opaque; + if (!s->connected) { + return; + } + remove_fd_in_watch(chr); if (s->ioc) { chr->fd_in_tag = io_add_watch_poll(s->ioc,