Skip to contentSkip to conversation

chardev/char-socket: fix double free of err after socket is disconnected

PATCH In review Derek Su 2 participants 3 messages Jun 24, 2020

lore
Share & tools
lore

Derek Su

author
#0 lore raw

PATCH 1/1 chardev/char-socket: fix double free of err after socket is disconnected

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

---
 chardev/char-socket.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
chardev/char-socket.c +5 -1
index afebeec5c3..a009bed5ee 100644
@@ -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;
     }
 
Signature · 1 line
2.17.1
#1 lore raw
Quoted 2 lines · Derek Su

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/[email protected]/msg714709.html

Quoted 24 lines
---
 chardev/char-socket.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
chardev/char-socket.c +5 -1
index afebeec5c3..a009bed5ee 100644
@@ -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;
     }
 
author
#2 lore raw

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

Thanks.

Derek

Philippe Mathieu-Daudé <[email protected]>於 2020年6月24日 週三,下午6:12寫道:

Quoted 19 lines · Derek Su
Quoted 2 lines

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/[email protected]/msg714709.html

chardev/char-socket.c static void qemu_chr_socket_connected(QIOTask

Quoted 11 lines
---
 chardev/char-socket.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
chardev/char-socket.c +0 -0
index afebeec5c3..a009bed5ee 100644
@@ -1086,7 +1086,11 @@ static void qemu_chr_socket_connected(QIOTask

*task, void *opaque)

Quoted 15 lines

chardev/char-socket.c static void qemu_chr_socket_connected(QIOTask *task, void *opaque) · line 1096

Quoted 13 lines
chardev/char-socket.c +5 -1
     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: [email protected]
Tel: (+886)-2-2393-5152 ext. 15017
Address: 13F., No.56, Sec. 1, Xinsheng S. Rd., Zhongzheng Dist., Taipei City, Taiwan