qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] chardev/char-socket: fix double free of err after socket is disconnected
@ 2020-06-24 10:00 Derek Su
  2020-06-24 10:12 ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 3+ messages in thread
From: Derek Su @ 2020-06-24 10:00 UTC (permalink / raw)
  To: qemu-devel; +Cc: Derek Su, marcandre.lureau, jwsu1986, pbonzini

The err is freed in check_report_connect_error() conditionally,
calling error_free() directly may lead to a double-free bug.

Signed-off-by: Derek Su <dereksu@qnap.com>
---
 chardev/char-socket.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index afebeec5c3..a009bed5ee 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -1086,7 +1086,11 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
     if (qio_task_propagate_error(task, &err)) {
         tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
         check_report_connect_error(chr, err);
-        error_free(err);
+
+        if (!s->connect_err_reported) {
+            error_free(err);
+        }
+
         goto cleanup;
     }
 
-- 
2.17.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] chardev/char-socket: fix double free of err after socket is disconnected
  2020-06-24 10:00 [PATCH v1] chardev/char-socket: fix double free of err after socket is disconnected Derek Su
@ 2020-06-24 10:12 ` Philippe Mathieu-Daudé
  2020-06-24 10:18   ` Derek Su
  0 siblings, 1 reply; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-06-24 10:12 UTC (permalink / raw)
  To: Derek Su, qemu-devel; +Cc: marcandre.lureau, lichun, jwsu1986, pbonzini

On 6/24/20 12:00 PM, Derek Su wrote:
> The err is freed in check_report_connect_error() conditionally,
> calling error_free() directly may lead to a double-free bug.

This seems the same issue Lichun is working on, right?
https://www.mail-archive.com/qemu-devel@nongnu.org/msg714709.html

> 
> Signed-off-by: Derek Su <dereksu@qnap.com>
> ---
>  chardev/char-socket.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> index afebeec5c3..a009bed5ee 100644
> --- a/chardev/char-socket.c
> +++ b/chardev/char-socket.c
> @@ -1086,7 +1086,11 @@ static void qemu_chr_socket_connected(QIOTask *task, void *opaque)
>      if (qio_task_propagate_error(task, &err)) {
>          tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
>          check_report_connect_error(chr, err);
> -        error_free(err);
> +
> +        if (!s->connect_err_reported) {
> +            error_free(err);
> +        }
> +
>          goto cleanup;
>      }
>  
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] chardev/char-socket: fix double free of err after socket is disconnected
  2020-06-24 10:12 ` Philippe Mathieu-Daudé
@ 2020-06-24 10:18   ` Derek Su
  0 siblings, 0 replies; 3+ messages in thread
From: Derek Su @ 2020-06-24 10:18 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: marcandre.lureau, lichun, jwsu1986, qemu-devel, pbonzini

[-- Attachment #1: Type: text/plain, Size: 1480 bytes --]

Oops! Sorry, I dont’t notice this patch before.

Thanks.

Derek

Philippe Mathieu-Daudé <philmd@redhat.com>於 2020年6月24日 週三,下午6:12寫道:

> On 6/24/20 12:00 PM, Derek Su wrote:
> > The err is freed in check_report_connect_error() conditionally,
> > calling error_free() directly may lead to a double-free bug.
>
> This seems the same issue Lichun is working on, right?
> https://www.mail-archive.com/qemu-devel@nongnu.org/msg714709.html
>
> >
> > Signed-off-by: Derek Su <dereksu@qnap.com>
> > ---
> >  chardev/char-socket.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/chardev/char-socket.c b/chardev/char-socket.c
> > index afebeec5c3..a009bed5ee 100644
> > --- a/chardev/char-socket.c
> > +++ b/chardev/char-socket.c
> > @@ -1086,7 +1086,11 @@ static void qemu_chr_socket_connected(QIOTask
> *task, void *opaque)
> >      if (qio_task_propagate_error(task, &err)) {
> >          tcp_chr_change_state(s, TCP_CHARDEV_STATE_DISCONNECTED);
> >          check_report_connect_error(chr, err);
> > -        error_free(err);
> > +
> > +        if (!s->connect_err_reported) {
> > +            error_free(err);
> > +        }
> > +
> >          goto cleanup;
> >      }
> >
> >
>
> --

Best regards,

Derek Su
QNAP Systems, Inc.
Email: dereksu@qnap.com
Tel: (+886)-2-2393-5152 ext. 15017
Address: 13F., No.56, Sec. 1, Xinsheng S. Rd., Zhongzheng Dist., Taipei
City, Taiwan

[-- Attachment #2: Type: text/html, Size: 3063 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-24 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-24 10:00 [PATCH v1] chardev/char-socket: fix double free of err after socket is disconnected Derek Su
2020-06-24 10:12 ` Philippe Mathieu-Daudé
2020-06-24 10:18   ` Derek Su

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).