All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH] char: fix repeated registration of tcp chardev I/O handlers
Date: Mon, 8 Feb 2016 21:53:33 +0000	[thread overview]
Message-ID: <56B90E5D.3010105@ilande.co.uk> (raw)
In-Reply-To: <1454939707-10869-1-git-send-email-berrange@redhat.com>

On 08/02/16 13:55, Daniel P. Berrange wrote:

> In previous commit:
> 
>   commit f2001a7e0555b66d6db25a3ff1801540814045bb
>   Author: Daniel P. Berrange <berrange@redhat.com>
>   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 <berrange@redhat.com>
> ---
>  qemu-char.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/qemu-char.c b/qemu-char.c
> index 927c47e..9060f8a 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -2856,6 +2856,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,
> 

Hi Daniel,

Yes I can confirm that this patch fixes the issue for me - thanks a lot
for debugging!


ATB,

Mark.



WARNING: multiple messages have this Message-ID (diff)
From: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH] char: fix repeated registration of tcp chardev I/O handlers
Date: Mon, 8 Feb 2016 21:53:33 +0000	[thread overview]
Message-ID: <56B90E5D.3010105@ilande.co.uk> (raw)
In-Reply-To: <1454939707-10869-1-git-send-email-berrange@redhat.com>

On 08/02/16 13:55, Daniel P. Berrange wrote:

> In previous commit:
> 
>   commit f2001a7e0555b66d6db25a3ff1801540814045bb
>   Author: Daniel P. Berrange <berrange@redhat.com>
>   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 <berrange@redhat.com>
> ---
>  qemu-char.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/qemu-char.c b/qemu-char.c
> index 927c47e..9060f8a 100644
> --- a/qemu-char.c
> +++ b/qemu-char.c
> @@ -2856,6 +2856,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,
> 

Hi Daniel,

Yes I can confirm that this patch fixes the issue for me - thanks a lot
for debugging!


ATB,

Mark.

  reply	other threads:[~2016-02-08 21:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-08 13:55 [Qemu-trivial] [PATCH] char: fix repeated registration of tcp chardev I/O handlers Daniel P. Berrange
2016-02-08 13:55 ` [Qemu-devel] " Daniel P. Berrange
2016-02-08 21:53 ` Mark Cave-Ayland [this message]
2016-02-08 21:53   ` Mark Cave-Ayland
2016-02-11  5:50 ` [Qemu-trivial] " Michael Tokarev
2016-02-11  5:50   ` [Qemu-devel] " Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56B90E5D.3010105@ilande.co.uk \
    --to=mark.cave-ayland@ilande.co.uk \
    --cc=berrange@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.