socket: don't attempt to reconnect a TCP socket in server mode
PATCH 1/1 socket: don't attempt to reconnect a TCP socket in server mode
Commit c3767ed0eb5d0bb25fe409ae5dec06e3411ff1b6 introduced a possible SEGV when using a socket chardev with server=on because it assumes that all TCP sockets are in client mode.
This patch adds a check to only reconnect when in client mode.
--- qemu-char.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
qemu-char.c +3 -1
@@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)TCPCharDriver *s = chr->opaque;if (s->connected) {return send_all (s->fd, buf, len); - }else { + }else if (s->listen_fd ==-1 ) {/* (Re-)connect for unconnected writing */ tcp_chr_connect (chr);return 0 ; + }else { +return len; } }
Signature · 1 line
1.7.5.4
Quoted 20 lines · Anthony Liguori
Commit
c3767ed0eb5d0bb25fe409ae5dec06e3411ff1b6introduced a possible SEGV when using a socket chardev with server=on because it assumes that all TCP sockets are in client mode.This patch adds a check to only reconnect when in client mode.
Cc Lei Li <[email protected]>Reported-by Michael Roth <[email protected]>Signed-off-by Anthony Liguori <[email protected]>--- qemu-char.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)qemu-char.c +0
-0@@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)TCPCharDriver *s = chr->opaque;if (s->connected) {
qemu-char.c static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len) · line 2158
Quoted 10 lines
qemu-char.c +3
-1return send_all (s->fd, buf, len); - }else { + }else if (s->listen_fd ==-1 ) {/* (Re-)connect for unconnected writing */ tcp_chr_connect (chr);return 0 ; + }else { +return len; } }
Hi Anthony,
I just came around this patch when I was trying to fix this
qemu segfaults when trying to write to a serial socket which is *not* a server socket and has been closed by the other end.
Unfortunately your patch above does not fix it. Only a complete revert of c3767ed0eb5d0 fixes it.
I don't understand the purpose of c3767ed0eb5d0 at all. It seems to set the s->connected flag and carries on regardless, happily calling write (-1, ...), which is completely broken.
The other end closed the socket. There's no one listening on the other end, and setting the s->connected flag will not help that.
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
Quoted 42 lines · Richard W.M. Jones
Quoted 20 lines · Anthony Liguori
Commit
c3767ed0eb5d0bb25fe409ae5dec06e3411ff1b6introduced a possible SEGV when using a socket chardev with server=on because it assumes that all TCP sockets are in client mode.This patch adds a check to only reconnect when in client mode.
Cc Lei Li <[email protected]>Reported-by Michael Roth <[email protected]>Signed-off-by Anthony Liguori <[email protected]>--- qemu-char.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)qemu-char.c +0
-0@@ -2148,10 +2148,12 @@ static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len)TCPCharDriver *s = chr->opaque;if (s->connected) {qemu-char.c static int tcp_chr_write(CharDriverState *chr, const uint8_t *buf, int len) · line 2158
Quoted 10 lines
qemu-char.c +3
-1return send_all (s->fd, buf, len); - }else { + }else if (s->listen_fd ==-1 ) {/* (Re-)connect for unconnected writing */ tcp_chr_connect (chr);return 0 ; + }else { +return len; } }Hi Anthony,
I just came around this patch when I was trying to fix this
qemu segfaults when trying to write to a serial socket which is *not* a server socket and has been closed by the other end.
Unfortunately your patch above does not fix it. Only a complete revert of
c3767ed0eb5d0fixes it.
Quoted 6 lines
I don't understand the purpose of
c3767ed0eb5d0at all. It seems to set thes->connectedflag and carries on regardless, happily calling write (-1, ...), which is completely broken.The other end closed the socket. There's no one listening on the other end, and setting the
s->connectedflag will not help that.
You're 100% correct. I was only attempting to fix the server SEGV, I didn't notice that client was hopelessly broken too. Will send a patch reverting both commits.
Regards,
Anthony Liguori
Quoted 8 lines
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora