All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
	qemu-devel@nongnu.org, "Gerd Hoffmann" <kraxel@redhat.com>
Subject: Re: [Qemu-devel] [RFC v2 01/12] chardev: avoid crash if no associated address
Date: Mon, 11 Jun 2018 09:59:22 +0100	[thread overview]
Message-ID: <20180611085922.GA11636@redhat.com> (raw)
In-Reply-To: <496cef6a-35a1-5ad7-fa43-771f877c5c13@amsat.org>

On Fri, Jun 08, 2018 at 11:52:11AM -0300, Philippe Mathieu-Daudé wrote:
> On 06/01/2018 01:27 PM, Marc-André Lureau wrote:
> > A socket chardev may not have associated address (when adding client
> > fd manually for example). But on disconnect, updating socket filename
> > expects an address and may lead to this crash:
> > 
> >   Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
> >   0x0000555555d8c70c in SocketAddress_to_str (prefix=0x555556043062 "disconnected:", addr=0x0, is_listen=false, is_telnet=false) at /home/elmarco/src/qq/chardev/char-socket.c:388
> >   388	    switch (addr->type) {
> >   (gdb) bt
> >   #0  0x0000555555d8c70c in SocketAddress_to_str (prefix=0x555556043062 "disconnected:", addr=0x0, is_listen=false, is_telnet=false) at /home/elmarco/src/qq/chardev/char-socket.c:388
> >   #1  0x0000555555d8c8aa in update_disconnected_filename (s=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:419
> >   #2  0x0000555555d8c959 in tcp_chr_disconnect (chr=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:438
> >   #3  0x0000555555d8cba1 in tcp_chr_hup (channel=0x555556b75690, cond=G_IO_HUP, opaque=0x555556b1ed00) at /home/elmarco/src/qq/chardev/char-socket.c:482
> >   #4  0x0000555555da596e in qio_channel_fd_source_dispatch (source=0x555556bb68b0, callback=0x555555d8cb58 <tcp_chr_hup>, user_data=0x555556b1ed00) at /home/elmarco/src/qq/io/channel-watch.c:84
> > 
> > Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> > ---
> >  chardev/char-socket.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> > index 159e69c3b1..f1b7907798 100644
> > --- a/chardev/char-socket.c
> > +++ b/chardev/char-socket.c
> > @@ -416,8 +416,11 @@ static void update_disconnected_filename(SocketChardev *s)
> >      Chardev *chr = CHARDEV(s);
> >  
> >      g_free(chr->filename);
> > -    chr->filename = SocketAddress_to_str("disconnected:", s->addr,
> > -                                         s->is_listen, s->is_telnet);
> > +    chr->filename = NULL;
> > +    if (s->addr) {
> 
> Isn't it more robust to add this check in SocketAddress_to_str()?

IMHO that just shifts the problem elsewhere - currently SocketAddress_to_str
is assumed to return non-NULL, or to abort(). Shifting the check means it
can now return NULL, so there's every chance the caller will now reference
the NULL pointer that's returned.

> 
>     static char *SocketAddress_to_str(const char *prefix, SocketAddress
> *addr,
>                                       bool is_listen, bool is_telnet)
>     {
>         if (!addr) {
>             return NULL;
>         }
>         switch (addr->type) {
>             ...
> 
> > +        chr->filename = SocketAddress_to_str("disconnected:", s->addr,
> > +                                             s->is_listen, s->is_telnet);
> > +    }
> >  }
> >  
> >  /* NB may be called even if tcp_chr_connect has not been
> > 
> 

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2018-06-11  8:59 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01 16:27 [Qemu-devel] [RFC v2 00/12] vhost-user for input & GPU Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 01/12] chardev: avoid crash if no associated address Marc-André Lureau
2018-06-08 14:52   ` Philippe Mathieu-Daudé
2018-06-11  8:59     ` Daniel P. Berrangé [this message]
2018-06-11  9:04   ` Daniel P. Berrangé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 02/12] libvhost-user: exit by default on VHOST_USER_NONE Marc-André Lureau
2018-06-08 14:48   ` Philippe Mathieu-Daudé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 03/12] vhost-user: wrap some read/write with retry handling Marc-André Lureau
2018-06-08 14:53   ` Philippe Mathieu-Daudé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 04/12] Add vhost-user-backend Marc-André Lureau
2018-06-04  9:36   ` Daniel P. Berrangé
2018-06-07 22:34     ` Marc-André Lureau
2018-06-08  8:43       ` Daniel P. Berrangé
2018-06-12 14:53         ` Marc-André Lureau
2018-06-12 15:08           ` Daniel P. Berrangé
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 05/12] vhost-user: split vhost_user_read() Marc-André Lureau
2018-06-08 14:57   ` Philippe Mathieu-Daudé
2018-06-12 14:58     ` Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 06/12] vhost-user: add vhost_user_input_get_config() Marc-André Lureau
2018-06-04  9:07   ` Dr. David Alan Gilbert
2018-06-04  9:18     ` Marc-André Lureau
2018-06-04  9:59       ` Dr. David Alan Gilbert
2018-06-12 12:46         ` Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 07/12] libvhost-user: export vug_source_new Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 08/12] contrib: add vhost-user-input Marc-André Lureau
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 09/12] Add vhost-input-pci Marc-André Lureau
2018-06-04  8:58   ` Gerd Hoffmann
2018-06-07 22:22     ` Marc-André Lureau
2018-06-08  5:41       ` Gerd Hoffmann
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 10/12] vhost-user: add vhost_user_gpu_set_socket() Marc-André Lureau
2018-06-04  9:28   ` Gerd Hoffmann
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 11/12] Add virtio-gpu vhost-user backend Marc-André Lureau
2018-06-04  9:37   ` Gerd Hoffmann
2018-06-08 17:25     ` Marc-André Lureau
2018-06-09  1:02       ` Marc-André Lureau
2018-06-11  6:49       ` Gerd Hoffmann
2018-06-01 16:27 ` [Qemu-devel] [RFC v2 12/12] contrib: add vhost-user-gpu Marc-André Lureau
2018-06-01 17:28 ` [Qemu-devel] [RFC v2 00/12] vhost-user for input & GPU no-reply

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=20180611085922.GA11636@redhat.com \
    --to=berrange@redhat.com \
    --cc=f4bug@amsat.org \
    --cc=kraxel@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=qemu-devel@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.