All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-stable@nongnu.org,
	Mauro Matteo Cascella <mcascell@redhat.com>,
	jiangyegen <jiangyegen@huawei.com>
Subject: Re: [PATCH] io: remove io watch if TLS channel is closed during handshake
Date: Fri, 7 Jul 2023 10:38:02 +0100	[thread overview]
Message-ID: <ZKfc+kL7PEEZ7h96@redhat.com> (raw)
In-Reply-To: <CAJ+F1CJt1PPSVwMAstLRog5PtPvAvA4xuccZgenTDc5SBLTGQQ@mail.gmail.com>

On Fri, Jul 07, 2023 at 01:30:16PM +0400, Marc-André Lureau wrote:
> On Wed, Jul 5, 2023 at 10:20 PM Daniel P. Berrangé <berrange@redhat.com>
> wrote:
> 
> > The TLS handshake make take some time to complete, during which time an
> > I/O watch might be registered with the main loop. If the owner of the
> > I/O channel invokes qio_channel_close() while the handshake is waiting
> > to continue the I/O watch must be removed. Failing to remove it will
> > later trigger the completion callback which the owner is not expecting
> > to receive. In the case of the VNC server, this results in a SEGV as
> > vnc_disconnect_start() tries to shutdown a client connection that is
> > already gone / NULL.
> >
> > CVE-2023-3354
> > Reported-by: jiangyegen <jiangyegen@huawei.com>
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> >
> 
> 
> 
> > ---
> >  include/io/channel-tls.h |  1 +
> >  io/channel-tls.c         | 18 ++++++++++++------
> >  2 files changed, 13 insertions(+), 6 deletions(-)
> >
> > diff --git a/include/io/channel-tls.h b/include/io/channel-tls.h
> > index 5672479e9e..26c67f17e2 100644
> > --- a/include/io/channel-tls.h
> > +++ b/include/io/channel-tls.h
> > @@ -48,6 +48,7 @@ struct QIOChannelTLS {
> >      QIOChannel *master;
> >      QCryptoTLSSession *session;
> >      QIOChannelShutdown shutdown;
> > +    guint hs_ioc_tag;
> >  };
> >
> >  /**
> > diff --git a/io/channel-tls.c b/io/channel-tls.c
> > index 9805dd0a3f..e327e6a5c2 100644
> > --- a/io/channel-tls.c
> > +++ b/io/channel-tls.c
> > @@ -198,12 +198,13 @@ static void
> > qio_channel_tls_handshake_task(QIOChannelTLS *ioc,
> >          }
> >
> >          trace_qio_channel_tls_handshake_pending(ioc, status);
> > -        qio_channel_add_watch_full(ioc->master,
> > -                                   condition,
> > -                                   qio_channel_tls_handshake_io,
> > -                                   data,
> > -                                   NULL,
> > -                                   context);
> > +        ioc->hs_ioc_tag =
> > +            qio_channel_add_watch_full(ioc->master,
> > +                                       condition,
> > +                                       qio_channel_tls_handshake_io,
> > +                                       data,
> > +                                       NULL,
> > +                                       context);
> >      }
> >  }
> >
> > @@ -218,6 +219,7 @@ static gboolean
> > qio_channel_tls_handshake_io(QIOChannel *ioc,
> >      QIOChannelTLS *tioc = QIO_CHANNEL_TLS(
> >          qio_task_get_source(task));
> >
> > +    tioc->hs_ioc_tag = 0;
> >      g_free(data);
> >      qio_channel_tls_handshake_task(tioc, task, context);
> >
> > @@ -378,6 +380,10 @@ static int qio_channel_tls_close(QIOChannel *ioc,
> >  {
> >      QIOChannelTLS *tioc = QIO_CHANNEL_TLS(ioc);
> >
> > +    if (tioc->hs_ioc_tag) {
> > +        g_source_remove(tioc->hs_ioc_tag);
> >
> 
> set it to 0 ?
> or
> g_clear_handle_id(&tios->hs_ioc_tag, g_source_remove);

Yes, close can be called mutliple times, so we must set to zero.

> > +    }
> > +
> >      return qio_channel_close(tioc->master, errp);
> >  }
> >
> > --
> > 2.41.0
> >
> >
> >
> 
> -- 
> Marc-André Lureau

With 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:[~2023-07-07  9:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-05 18:17 [PATCH] io: remove io watch if TLS channel is closed during handshake Daniel P. Berrangé
2023-07-07  9:30 ` Marc-André Lureau
2023-07-07  9:38   ` Daniel P. Berrangé [this message]
2023-07-12  9:15     ` 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=ZKfc+kL7PEEZ7h96@redhat.com \
    --to=berrange@redhat.com \
    --cc=jiangyegen@huawei.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mcascell@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-stable@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.