Blame SOURCES/0003-curl-7.76.1-CVE-2021-22901.patch

d889a8
From c8210a16e8b61704da7bbf4bb0992ecbb1c7746d Mon Sep 17 00:00:00 2001
d889a8
From: Daniel Stenberg <daniel@haxx.se>
d889a8
Date: Mon, 17 May 2021 08:54:00 +0200
d889a8
Subject: [PATCH 1/3] conn: add 'attach' to protocol handler, make libssh2 use
d889a8
 it
d889a8
d889a8
The libssh2 backend has SSH session associated with the connection but
d889a8
the callback context is the easy handle, so when a connection gets
d889a8
attached to a transfer, the protocol handler now allows for a custom
d889a8
function to get used to set things up correctly.
d889a8
d889a8
Reported-by: Michael O'Farrell
d889a8
Fixes #6898
d889a8
Closes #7078
d889a8
d889a8
Upstream-commit: 0c55fbab45bedb761766109d41c3da49c4bc66c6
d889a8
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d889a8
---
d889a8
 lib/curl_rtmp.c    |  6 ++++++
d889a8
 lib/dict.c         |  1 +
d889a8
 lib/file.c         |  1 +
d889a8
 lib/ftp.c          |  2 ++
d889a8
 lib/gopher.c       |  2 ++
d889a8
 lib/http.c         |  2 ++
d889a8
 lib/http2.c        |  2 ++
d889a8
 lib/imap.c         |  2 ++
d889a8
 lib/ldap.c         |  2 ++
d889a8
 lib/mqtt.c         |  1 +
d889a8
 lib/multi.c        |  2 ++
d889a8
 lib/openldap.c     |  2 ++
d889a8
 lib/pop3.c         |  2 ++
d889a8
 lib/rtsp.c         |  1 +
d889a8
 lib/smb.c          |  2 ++
d889a8
 lib/smtp.c         |  2 ++
d889a8
 lib/telnet.c       |  1 +
d889a8
 lib/tftp.c         |  1 +
d889a8
 lib/url.c          |  1 +
d889a8
 lib/urldata.h      |  4 ++++
d889a8
 lib/vssh/libssh.c  |  2 ++
d889a8
 lib/vssh/libssh2.c | 20 ++++++++++++++++++++
d889a8
 lib/vssh/ssh.h     |  3 +++
d889a8
 lib/vssh/wolfssh.c |  2 ++
d889a8
 24 files changed, 66 insertions(+)
d889a8
d889a8
diff --git a/lib/curl_rtmp.c b/lib/curl_rtmp.c
d889a8
index 1360f33..2fa0267 100644
d889a8
--- a/lib/curl_rtmp.c
d889a8
+++ b/lib/curl_rtmp.c
d889a8
@@ -79,6 +79,7 @@ const struct Curl_handler Curl_handler_rtmp = {
d889a8
   rtmp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTMP,                            /* defport */
d889a8
   CURLPROTO_RTMP,                       /* protocol */
d889a8
   CURLPROTO_RTMP,                       /* family */
d889a8
@@ -101,6 +102,7 @@ const struct Curl_handler Curl_handler_rtmpt = {
d889a8
   rtmp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTMPT,                           /* defport */
d889a8
   CURLPROTO_RTMPT,                      /* protocol */
d889a8
   CURLPROTO_RTMPT,                      /* family */
d889a8
@@ -123,6 +125,7 @@ const struct Curl_handler Curl_handler_rtmpe = {
d889a8
   rtmp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTMP,                            /* defport */
d889a8
   CURLPROTO_RTMPE,                      /* protocol */
d889a8
   CURLPROTO_RTMPE,                      /* family */
d889a8
@@ -145,6 +148,7 @@ const struct Curl_handler Curl_handler_rtmpte = {
d889a8
   rtmp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTMPT,                           /* defport */
d889a8
   CURLPROTO_RTMPTE,                     /* protocol */
d889a8
   CURLPROTO_RTMPTE,                     /* family */
d889a8
@@ -167,6 +171,7 @@ const struct Curl_handler Curl_handler_rtmps = {
d889a8
   rtmp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTMPS,                           /* defport */
d889a8
   CURLPROTO_RTMPS,                      /* protocol */
d889a8
   CURLPROTO_RTMP,                       /* family */
d889a8
@@ -189,6 +194,7 @@ const struct Curl_handler Curl_handler_rtmpts = {
d889a8
   rtmp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTMPS,                           /* defport */
d889a8
   CURLPROTO_RTMPTS,                     /* protocol */
d889a8
   CURLPROTO_RTMPT,                      /* family */
d889a8
diff --git a/lib/dict.c b/lib/dict.c
d889a8
index 4319dad..7b27f79 100644
d889a8
--- a/lib/dict.c
d889a8
+++ b/lib/dict.c
d889a8
@@ -89,6 +89,7 @@ const struct Curl_handler Curl_handler_dict = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_DICT,                            /* defport */
d889a8
   CURLPROTO_DICT,                       /* protocol */
d889a8
   CURLPROTO_DICT,                       /* family */
d889a8
diff --git a/lib/file.c b/lib/file.c
d889a8
index 1d174e5..10d8f05 100644
d889a8
--- a/lib/file.c
d889a8
+++ b/lib/file.c
d889a8
@@ -111,6 +111,7 @@ const struct Curl_handler Curl_handler_file = {
d889a8
   file_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   0,                                    /* defport */
d889a8
   CURLPROTO_FILE,                       /* protocol */
d889a8
   CURLPROTO_FILE,                       /* family */
d889a8
diff --git a/lib/ftp.c b/lib/ftp.c
d889a8
index 5bf44f1..5ef1e2e 100644
d889a8
--- a/lib/ftp.c
d889a8
+++ b/lib/ftp.c
d889a8
@@ -175,6 +175,7 @@ const struct Curl_handler Curl_handler_ftp = {
d889a8
   ftp_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                       /* readwrite */
d889a8
   ZERO_NULL,                       /* connection_check */
d889a8
+  ZERO_NULL,                       /* attach connection */
d889a8
   PORT_FTP,                        /* defport */
d889a8
   CURLPROTO_FTP,                   /* protocol */
d889a8
   CURLPROTO_FTP,                   /* family */
d889a8
@@ -205,6 +206,7 @@ const struct Curl_handler Curl_handler_ftps = {
d889a8
   ftp_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                       /* readwrite */
d889a8
   ZERO_NULL,                       /* connection_check */
d889a8
+  ZERO_NULL,                       /* attach connection */
d889a8
   PORT_FTPS,                       /* defport */
d889a8
   CURLPROTO_FTPS,                  /* protocol */
d889a8
   CURLPROTO_FTP,                   /* family */
d889a8
diff --git a/lib/gopher.c b/lib/gopher.c
d889a8
index a39cc7e..f61232f 100644
d889a8
--- a/lib/gopher.c
d889a8
+++ b/lib/gopher.c
d889a8
@@ -74,6 +74,7 @@ const struct Curl_handler Curl_handler_gopher = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_GOPHER,                          /* defport */
d889a8
   CURLPROTO_GOPHER,                     /* protocol */
d889a8
   CURLPROTO_GOPHER,                     /* family */
d889a8
@@ -97,6 +98,7 @@ const struct Curl_handler Curl_handler_gophers = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_GOPHER,                          /* defport */
d889a8
   CURLPROTO_GOPHERS,                    /* protocol */
d889a8
   CURLPROTO_GOPHER,                     /* family */
d889a8
diff --git a/lib/http.c b/lib/http.c
d889a8
index 02c81c4..91da200 100644
d889a8
--- a/lib/http.c
d889a8
+++ b/lib/http.c
d889a8
@@ -133,6 +133,7 @@ const struct Curl_handler Curl_handler_http = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_HTTP,                            /* defport */
d889a8
   CURLPROTO_HTTP,                       /* protocol */
d889a8
   CURLPROTO_HTTP,                       /* family */
d889a8
@@ -160,6 +161,7 @@ const struct Curl_handler Curl_handler_https = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_HTTPS,                           /* defport */
d889a8
   CURLPROTO_HTTPS,                      /* protocol */
d889a8
   CURLPROTO_HTTP,                       /* family */
d889a8
diff --git a/lib/http2.c b/lib/http2.c
d889a8
index d0f69ea..1eb4e89 100644
d889a8
--- a/lib/http2.c
d889a8
+++ b/lib/http2.c
d889a8
@@ -319,6 +319,7 @@ static const struct Curl_handler Curl_handler_http2 = {
d889a8
   http2_disconnect,                     /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   http2_conncheck,                      /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_HTTP,                            /* defport */
d889a8
   CURLPROTO_HTTP,                       /* protocol */
d889a8
   CURLPROTO_HTTP,                       /* family */
d889a8
@@ -341,6 +342,7 @@ static const struct Curl_handler Curl_handler_http2_ssl = {
d889a8
   http2_disconnect,                     /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   http2_conncheck,                      /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_HTTP,                            /* defport */
d889a8
   CURLPROTO_HTTPS,                      /* protocol */
d889a8
   CURLPROTO_HTTP,                       /* family */
d889a8
diff --git a/lib/imap.c b/lib/imap.c
d889a8
index e887357..e50d7fd 100644
d889a8
--- a/lib/imap.c
d889a8
+++ b/lib/imap.c
d889a8
@@ -136,6 +136,7 @@ const struct Curl_handler Curl_handler_imap = {
d889a8
   imap_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                        /* readwrite */
d889a8
   ZERO_NULL,                        /* connection_check */
d889a8
+  ZERO_NULL,                        /* attach connection */
d889a8
   PORT_IMAP,                        /* defport */
d889a8
   CURLPROTO_IMAP,                   /* protocol */
d889a8
   CURLPROTO_IMAP,                   /* family */
d889a8
@@ -164,6 +165,7 @@ const struct Curl_handler Curl_handler_imaps = {
d889a8
   imap_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                        /* readwrite */
d889a8
   ZERO_NULL,                        /* connection_check */
d889a8
+  ZERO_NULL,                        /* attach connection */
d889a8
   PORT_IMAPS,                       /* defport */
d889a8
   CURLPROTO_IMAPS,                  /* protocol */
d889a8
   CURLPROTO_IMAP,                   /* family */
d889a8
diff --git a/lib/ldap.c b/lib/ldap.c
d889a8
index 860a4a8..d632a7e 100644
d889a8
--- a/lib/ldap.c
d889a8
+++ b/lib/ldap.c
d889a8
@@ -149,6 +149,7 @@ const struct Curl_handler Curl_handler_ldap = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_LDAP,                            /* defport */
d889a8
   CURLPROTO_LDAP,                       /* protocol */
d889a8
   CURLPROTO_LDAP,                       /* family */
d889a8
@@ -176,6 +177,7 @@ const struct Curl_handler Curl_handler_ldaps = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_LDAPS,                           /* defport */
d889a8
   CURLPROTO_LDAPS,                      /* protocol */
d889a8
   CURLPROTO_LDAP,                       /* family */
d889a8
diff --git a/lib/mqtt.c b/lib/mqtt.c
d889a8
index 2134409..d88fa73 100644
d889a8
--- a/lib/mqtt.c
d889a8
+++ b/lib/mqtt.c
d889a8
@@ -86,6 +86,7 @@ const struct Curl_handler Curl_handler_mqtt = {
d889a8
   ZERO_NULL,                          /* disconnect */
d889a8
   ZERO_NULL,                          /* readwrite */
d889a8
   ZERO_NULL,                          /* connection_check */
d889a8
+  ZERO_NULL,                          /* attach connection */
d889a8
   PORT_MQTT,                          /* defport */
d889a8
   CURLPROTO_MQTT,                     /* protocol */
d889a8
   CURLPROTO_MQTT,                     /* family */
d889a8
diff --git a/lib/multi.c b/lib/multi.c
d889a8
index be3e41f..e624bc3 100644
d889a8
--- a/lib/multi.c
d889a8
+++ b/lib/multi.c
d889a8
@@ -890,6 +890,8 @@ void Curl_attach_connnection(struct Curl_easy *data,
d889a8
   data->conn = conn;
d889a8
   Curl_llist_insert_next(&conn->easyq, conn->easyq.tail, data,
d889a8
                          &data->conn_queue);
d889a8
+  if(conn->handler->attach)
d889a8
+    conn->handler->attach(data, conn);
d889a8
 }
d889a8
 
d889a8
 static int waitconnect_getsock(struct connectdata *conn,
d889a8
diff --git a/lib/openldap.c b/lib/openldap.c
d889a8
index b6980c5..b515554 100644
d889a8
--- a/lib/openldap.c
d889a8
+++ b/lib/openldap.c
d889a8
@@ -107,6 +107,7 @@ const struct Curl_handler Curl_handler_ldap = {
d889a8
   ldap_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_LDAP,                            /* defport */
d889a8
   CURLPROTO_LDAP,                       /* protocol */
d889a8
   CURLPROTO_LDAP,                       /* family */
d889a8
@@ -134,6 +135,7 @@ const struct Curl_handler Curl_handler_ldaps = {
d889a8
   ldap_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_LDAPS,                           /* defport */
d889a8
   CURLPROTO_LDAPS,                      /* protocol */
d889a8
   CURLPROTO_LDAP,                       /* family */
d889a8
diff --git a/lib/pop3.c b/lib/pop3.c
d889a8
index ccfebd0..6168b12 100644
d889a8
--- a/lib/pop3.c
d889a8
+++ b/lib/pop3.c
d889a8
@@ -131,6 +131,7 @@ const struct Curl_handler Curl_handler_pop3 = {
d889a8
   pop3_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                        /* readwrite */
d889a8
   ZERO_NULL,                        /* connection_check */
d889a8
+  ZERO_NULL,                        /* attach connection */
d889a8
   PORT_POP3,                        /* defport */
d889a8
   CURLPROTO_POP3,                   /* protocol */
d889a8
   CURLPROTO_POP3,                   /* family */
d889a8
@@ -159,6 +160,7 @@ const struct Curl_handler Curl_handler_pop3s = {
d889a8
   pop3_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                        /* readwrite */
d889a8
   ZERO_NULL,                        /* connection_check */
d889a8
+  ZERO_NULL,                        /* attach connection */
d889a8
   PORT_POP3S,                       /* defport */
d889a8
   CURLPROTO_POP3S,                  /* protocol */
d889a8
   CURLPROTO_POP3,                   /* family */
d889a8
diff --git a/lib/rtsp.c b/lib/rtsp.c
d889a8
index 3029ff5..cdd49dc 100644
d889a8
--- a/lib/rtsp.c
d889a8
+++ b/lib/rtsp.c
d889a8
@@ -109,6 +109,7 @@ const struct Curl_handler Curl_handler_rtsp = {
d889a8
   rtsp_disconnect,                      /* disconnect */
d889a8
   rtsp_rtp_readwrite,                   /* readwrite */
d889a8
   rtsp_conncheck,                       /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_RTSP,                            /* defport */
d889a8
   CURLPROTO_RTSP,                       /* protocol */
d889a8
   CURLPROTO_RTSP,                       /* family */
d889a8
diff --git a/lib/smb.c b/lib/smb.c
d889a8
index 183bc12..9f65cfd 100644
d889a8
--- a/lib/smb.c
d889a8
+++ b/lib/smb.c
d889a8
@@ -88,6 +88,7 @@ const struct Curl_handler Curl_handler_smb = {
d889a8
   smb_disconnect,                       /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_SMB,                             /* defport */
d889a8
   CURLPROTO_SMB,                        /* protocol */
d889a8
   CURLPROTO_SMB,                        /* family */
d889a8
@@ -114,6 +115,7 @@ const struct Curl_handler Curl_handler_smbs = {
d889a8
   smb_disconnect,                       /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_SMBS,                            /* defport */
d889a8
   CURLPROTO_SMBS,                       /* protocol */
d889a8
   CURLPROTO_SMB,                        /* family */
d889a8
diff --git a/lib/smtp.c b/lib/smtp.c
d889a8
index be4cd67..1defb25 100644
d889a8
--- a/lib/smtp.c
d889a8
+++ b/lib/smtp.c
d889a8
@@ -136,6 +136,7 @@ const struct Curl_handler Curl_handler_smtp = {
d889a8
   smtp_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                        /* readwrite */
d889a8
   ZERO_NULL,                        /* connection_check */
d889a8
+  ZERO_NULL,                        /* attach connection */
d889a8
   PORT_SMTP,                        /* defport */
d889a8
   CURLPROTO_SMTP,                   /* protocol */
d889a8
   CURLPROTO_SMTP,                   /* family */
d889a8
@@ -164,6 +165,7 @@ const struct Curl_handler Curl_handler_smtps = {
d889a8
   smtp_disconnect,                  /* disconnect */
d889a8
   ZERO_NULL,                        /* readwrite */
d889a8
   ZERO_NULL,                        /* connection_check */
d889a8
+  ZERO_NULL,                        /* attach connection */
d889a8
   PORT_SMTPS,                       /* defport */
d889a8
   CURLPROTO_SMTPS,                  /* protocol */
d889a8
   CURLPROTO_SMTP,                   /* family */
d889a8
diff --git a/lib/telnet.c b/lib/telnet.c
d889a8
index 4551435..fdd137f 100644
d889a8
--- a/lib/telnet.c
d889a8
+++ b/lib/telnet.c
d889a8
@@ -185,6 +185,7 @@ const struct Curl_handler Curl_handler_telnet = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_TELNET,                          /* defport */
d889a8
   CURLPROTO_TELNET,                     /* protocol */
d889a8
   CURLPROTO_TELNET,                     /* family */
d889a8
diff --git a/lib/tftp.c b/lib/tftp.c
d889a8
index 76d3ff4..bf499f3 100644
d889a8
--- a/lib/tftp.c
d889a8
+++ b/lib/tftp.c
d889a8
@@ -182,6 +182,7 @@ const struct Curl_handler Curl_handler_tftp = {
d889a8
   tftp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_TFTP,                            /* defport */
d889a8
   CURLPROTO_TFTP,                       /* protocol */
d889a8
   CURLPROTO_TFTP,                       /* family */
d889a8
diff --git a/lib/url.c b/lib/url.c
d889a8
index 19fcfb8..9f2c9f2 100644
d889a8
--- a/lib/url.c
d889a8
+++ b/lib/url.c
d889a8
@@ -292,6 +292,7 @@ static const struct Curl_handler Curl_handler_dummy = {
d889a8
   ZERO_NULL,                            /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   0,                                    /* defport */
d889a8
   0,                                    /* protocol */
d889a8
   0,                                    /* family */
d889a8
diff --git a/lib/urldata.h b/lib/urldata.h
d889a8
index fec8756..2bb7d81 100644
d889a8
--- a/lib/urldata.h
d889a8
+++ b/lib/urldata.h
d889a8
@@ -791,12 +791,16 @@ struct Curl_handler {
d889a8
                                    struct connectdata *conn,
d889a8
                                    unsigned int checks_to_perform);
d889a8
 
d889a8
+  /* attach() attaches this transfer to this connection */
d889a8
+  void (*attach)(struct Curl_easy *data, struct connectdata *conn);
d889a8
+
d889a8
   int defport;            /* Default port. */
d889a8
   unsigned int protocol;  /* See CURLPROTO_* - this needs to be the single
d889a8
                              specific protocol bit */
d889a8
   unsigned int family;    /* single bit for protocol family; basically the
d889a8
                              non-TLS name of the protocol this is */
d889a8
   unsigned int flags;     /* Extra particular characteristics, see PROTOPT_* */
d889a8
+
d889a8
 };
d889a8
 
d889a8
 #define PROTOPT_NONE 0             /* nothing extra */
d889a8
diff --git a/lib/vssh/libssh.c b/lib/vssh/libssh.c
d889a8
index 4644f4c..450ab28 100644
d889a8
--- a/lib/vssh/libssh.c
d889a8
+++ b/lib/vssh/libssh.c
d889a8
@@ -159,6 +159,7 @@ const struct Curl_handler Curl_handler_scp = {
d889a8
   scp_disconnect,               /* disconnect */
d889a8
   ZERO_NULL,                    /* readwrite */
d889a8
   ZERO_NULL,                    /* connection_check */
d889a8
+  ZERO_NULL,                    /* attach connection */
d889a8
   PORT_SSH,                     /* defport */
d889a8
   CURLPROTO_SCP,                /* protocol */
d889a8
   CURLPROTO_SCP,                /* family */
d889a8
@@ -185,6 +186,7 @@ const struct Curl_handler Curl_handler_sftp = {
d889a8
   sftp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_SSH,                             /* defport */
d889a8
   CURLPROTO_SFTP,                       /* protocol */
d889a8
   CURLPROTO_SFTP,                       /* family */
d889a8
diff --git a/lib/vssh/libssh2.c b/lib/vssh/libssh2.c
d889a8
index 9d188d0..0a468dd 100644
d889a8
--- a/lib/vssh/libssh2.c
d889a8
+++ b/lib/vssh/libssh2.c
d889a8
@@ -121,6 +121,7 @@ static int ssh_getsock(struct Curl_easy *data, struct connectdata *conn,
d889a8
                        curl_socket_t *sock);
d889a8
 static CURLcode ssh_setup_connection(struct Curl_easy *data,
d889a8
                                      struct connectdata *conn);
d889a8
+static void ssh_attach(struct Curl_easy *data, struct connectdata *conn);
d889a8
 
d889a8
 /*
d889a8
  * SCP protocol handler.
d889a8
@@ -142,6 +143,7 @@ const struct Curl_handler Curl_handler_scp = {
d889a8
   scp_disconnect,                       /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ssh_attach,
d889a8
   PORT_SSH,                             /* defport */
d889a8
   CURLPROTO_SCP,                        /* protocol */
d889a8
   CURLPROTO_SCP,                        /* family */
d889a8
@@ -170,6 +172,7 @@ const struct Curl_handler Curl_handler_sftp = {
d889a8
   sftp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ssh_attach,
d889a8
   PORT_SSH,                             /* defport */
d889a8
   CURLPROTO_SFTP,                       /* protocol */
d889a8
   CURLPROTO_SFTP,                       /* family */
d889a8
@@ -3607,4 +3610,21 @@ size_t Curl_ssh_version(char *buffer, size_t buflen)
d889a8
   return msnprintf(buffer, buflen, "libssh2/%s", LIBSSH2_VERSION);
d889a8
 }
d889a8
 
d889a8
+/* The SSH session is associated with the *CONNECTION* but the callback user
d889a8
+ * pointer is an easy handle pointer. This function allows us to reassign the
d889a8
+ * user pointer to the *CURRENT* (new) easy handle.
d889a8
+ */
d889a8
+static void ssh_attach(struct Curl_easy *data, struct connectdata *conn)
d889a8
+{
d889a8
+  DEBUGASSERT(data);
d889a8
+  DEBUGASSERT(conn);
d889a8
+  if(conn->handler->protocol & PROTO_FAMILY_SSH) {
d889a8
+    struct ssh_conn *sshc = &conn->proto.sshc;
d889a8
+    if(sshc->ssh_session) {
d889a8
+      /* only re-attach if the session already exists */
d889a8
+      void **abstract = libssh2_session_abstract(sshc->ssh_session);
d889a8
+      *abstract = data;
d889a8
+    }
d889a8
+  }
d889a8
+}
d889a8
 #endif /* USE_LIBSSH2 */
d889a8
diff --git a/lib/vssh/ssh.h b/lib/vssh/ssh.h
d889a8
index 52e1ee6..505b078 100644
d889a8
--- a/lib/vssh/ssh.h
d889a8
+++ b/lib/vssh/ssh.h
d889a8
@@ -263,9 +263,12 @@ extern const struct Curl_handler Curl_handler_sftp;
d889a8
 CURLcode Curl_ssh_init(void);
d889a8
 void Curl_ssh_cleanup(void);
d889a8
 size_t Curl_ssh_version(char *buffer, size_t buflen);
d889a8
+void Curl_ssh_attach(struct Curl_easy *data,
d889a8
+                     struct connectdata *conn);
d889a8
 #else
d889a8
 /* for non-SSH builds */
d889a8
 #define Curl_ssh_cleanup()
d889a8
+#define Curl_ssh_attach(x,y)
d889a8
 #endif
d889a8
 
d889a8
 #endif /* HEADER_CURL_SSH_H */
d889a8
diff --git a/lib/vssh/wolfssh.c b/lib/vssh/wolfssh.c
d889a8
index de0b1c7..8aa8067 100644
d889a8
--- a/lib/vssh/wolfssh.c
d889a8
+++ b/lib/vssh/wolfssh.c
d889a8
@@ -91,6 +91,7 @@ const struct Curl_handler Curl_handler_scp = {
d889a8
   wscp_disconnect,                      /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_SSH,                             /* defport */
d889a8
   CURLPROTO_SCP,                        /* protocol */
d889a8
   PROTOPT_DIRLOCK | PROTOPT_CLOSEACTION
d889a8
@@ -119,6 +120,7 @@ const struct Curl_handler Curl_handler_sftp = {
d889a8
   wsftp_disconnect,                     /* disconnect */
d889a8
   ZERO_NULL,                            /* readwrite */
d889a8
   ZERO_NULL,                            /* connection_check */
d889a8
+  ZERO_NULL,                            /* attach connection */
d889a8
   PORT_SSH,                             /* defport */
d889a8
   CURLPROTO_SFTP,                       /* protocol */
d889a8
   CURLPROTO_SFTP,                       /* family */
d889a8
-- 
d889a8
2.31.1
d889a8
d889a8
d889a8
From b5971f4854aab00fcd7810aa9a425c0a6790e050 Mon Sep 17 00:00:00 2001
d889a8
From: Harry Sintonen <sintonen@iki.fi>
d889a8
Date: Wed, 5 May 2021 13:42:26 +0200
d889a8
Subject: [PATCH 2/3] openssl: associate/detach the transfer from connection
d889a8
d889a8
CVE-2021-22901
d889a8
d889a8
Bug: https://curl.se/docs/CVE-2021-22901.html
d889a8
d889a8
Upstream-commit: 7f4a9a9b2a49547eae24d2e19bc5c346e9026479
d889a8
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d889a8
---
d889a8
 lib/multi.c          |   5 +-
d889a8
 lib/vtls/gskit.c     |   4 +-
d889a8
 lib/vtls/gtls.c      |   4 +-
d889a8
 lib/vtls/mbedtls.c   |   4 +-
d889a8
 lib/vtls/mesalink.c  |   4 +-
d889a8
 lib/vtls/nss.c       |   4 +-
d889a8
 lib/vtls/openssl.c   | 146 +++++++++++++++++++++++++++++++------------
d889a8
 lib/vtls/rustls.c    |   4 +-
d889a8
 lib/vtls/schannel.c  |   4 +-
d889a8
 lib/vtls/sectransp.c |   2 +
d889a8
 lib/vtls/vtls.c      |  23 ++++++-
d889a8
 lib/vtls/vtls.h      |  12 ++++
d889a8
 lib/vtls/wolfssl.c   |   4 +-
d889a8
 13 files changed, 171 insertions(+), 49 deletions(-)
d889a8
d889a8
diff --git a/lib/multi.c b/lib/multi.c
d889a8
index e624bc3..2228264 100644
d889a8
--- a/lib/multi.c
d889a8
+++ b/lib/multi.c
d889a8
@@ -872,8 +872,10 @@ bool Curl_multiplex_wanted(const struct Curl_multi *multi)
d889a8
 void Curl_detach_connnection(struct Curl_easy *data)
d889a8
 {
d889a8
   struct connectdata *conn = data->conn;
d889a8
-  if(conn)
d889a8
+  if(conn) {
d889a8
     Curl_llist_remove(&conn->easyq, &data->conn_queue, NULL);
d889a8
+    Curl_ssl_detach_conn(data, conn);
d889a8
+  }
d889a8
   data->conn = NULL;
d889a8
 }
d889a8
 
d889a8
@@ -892,6 +894,7 @@ void Curl_attach_connnection(struct Curl_easy *data,
d889a8
                          &data->conn_queue);
d889a8
   if(conn->handler->attach)
d889a8
     conn->handler->attach(data, conn);
d889a8
+  Curl_ssl_associate_conn(data, conn);
d889a8
 }
d889a8
 
d889a8
 static int waitconnect_getsock(struct connectdata *conn,
d889a8
diff --git a/lib/vtls/gskit.c b/lib/vtls/gskit.c
d889a8
index b0c7343..3fe54c1 100644
d889a8
--- a/lib/vtls/gskit.c
d889a8
+++ b/lib/vtls/gskit.c
d889a8
@@ -1281,7 +1281,9 @@ const struct Curl_ssl Curl_ssl_gskit = {
d889a8
   Curl_none_set_engine_default,   /* set_engine_default */
d889a8
   Curl_none_engines_list,         /* engines_list */
d889a8
   Curl_none_false_start,          /* false_start */
d889a8
-  NULL                            /* sha256sum */
d889a8
+  NULL,                           /* sha256sum */
d889a8
+  NULL,                           /* associate_connection */
d889a8
+  NULL                            /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_GSKIT */
d889a8
diff --git a/lib/vtls/gtls.c b/lib/vtls/gtls.c
d889a8
index e3fad7f..ea54fe3 100644
d889a8
--- a/lib/vtls/gtls.c
d889a8
+++ b/lib/vtls/gtls.c
d889a8
@@ -1645,7 +1645,9 @@ const struct Curl_ssl Curl_ssl_gnutls = {
d889a8
   Curl_none_set_engine_default,  /* set_engine_default */
d889a8
   Curl_none_engines_list,        /* engines_list */
d889a8
   Curl_none_false_start,         /* false_start */
d889a8
-  gtls_sha256sum                 /* sha256sum */
d889a8
+  gtls_sha256sum,                /* sha256sum */
d889a8
+  NULL,                          /* associate_connection */
d889a8
+  NULL                           /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_GNUTLS */
d889a8
diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c
d889a8
index 4b36f2d..0a9f7b4 100644
d889a8
--- a/lib/vtls/mbedtls.c
d889a8
+++ b/lib/vtls/mbedtls.c
d889a8
@@ -1113,7 +1113,9 @@ const struct Curl_ssl Curl_ssl_mbedtls = {
d889a8
   Curl_none_set_engine_default,     /* set_engine_default */
d889a8
   Curl_none_engines_list,           /* engines_list */
d889a8
   Curl_none_false_start,            /* false_start */
d889a8
-  mbedtls_sha256sum                 /* sha256sum */
d889a8
+  mbedtls_sha256sum,                /* sha256sum */
d889a8
+  NULL,                             /* associate_connection */
d889a8
+  NULL                              /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_MBEDTLS */
d889a8
diff --git a/lib/vtls/mesalink.c b/lib/vtls/mesalink.c
d889a8
index 5d6a149..0a41dd3 100644
d889a8
--- a/lib/vtls/mesalink.c
d889a8
+++ b/lib/vtls/mesalink.c
d889a8
@@ -667,7 +667,9 @@ const struct Curl_ssl Curl_ssl_mesalink = {
d889a8
   Curl_none_set_engine_default,  /* set_engine_default */
d889a8
   Curl_none_engines_list,        /* engines_list */
d889a8
   Curl_none_false_start,         /* false_start */
d889a8
-  NULL                           /* sha256sum */
d889a8
+  NULL,                          /* sha256sum */
d889a8
+  NULL,                          /* associate_connection */
d889a8
+  NULL                           /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif
d889a8
diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c
d889a8
index a9f6959..ae3945c 100644
d889a8
--- a/lib/vtls/nss.c
d889a8
+++ b/lib/vtls/nss.c
d889a8
@@ -2442,7 +2442,9 @@ const struct Curl_ssl Curl_ssl_nss = {
d889a8
   Curl_none_set_engine_default, /* set_engine_default */
d889a8
   Curl_none_engines_list,       /* engines_list */
d889a8
   nss_false_start,              /* false_start */
d889a8
-  nss_sha256sum                 /* sha256sum */
d889a8
+  nss_sha256sum,                /* sha256sum */
d889a8
+  NULL,                         /* associate_connection */
d889a8
+  NULL                          /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_NSS */
d889a8
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
d889a8
index 6583300..2404393 100644
d889a8
--- a/lib/vtls/openssl.c
d889a8
+++ b/lib/vtls/openssl.c
d889a8
@@ -246,6 +246,10 @@ struct ssl_backend_data {
d889a8
 #endif
d889a8
 };
d889a8
 
d889a8
+static void ossl_associate_connection(struct Curl_easy *data,
d889a8
+                                      struct connectdata *conn,
d889a8
+                                      int sockindex);
d889a8
+
d889a8
 /*
d889a8
  * Number of bytes to read from the random number seed file. This must be
d889a8
  * a finite value (because some entropy "files" like /dev/urandom have
d889a8
@@ -2528,6 +2532,7 @@ static CURLcode ossl_connect_step1(struct Curl_easy *data,
d889a8
   curl_socket_t sockfd = conn->sock[sockindex];
d889a8
   struct ssl_connect_data *connssl = &conn->ssl[sockindex];
d889a8
   ctx_option_t ctx_options = 0;
d889a8
+  void *ssl_sessionid = NULL;
d889a8
 
d889a8
 #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
d889a8
   bool sni;
d889a8
@@ -3209,46 +3214,23 @@ static CURLcode ossl_connect_step1(struct Curl_easy *data,
d889a8
   }
d889a8
 #endif
d889a8
 
d889a8
-  /* Check if there's a cached ID we can/should use here! */
d889a8
-  if(SSL_SET_OPTION(primary.sessionid)) {
d889a8
-    void *ssl_sessionid = NULL;
d889a8
-    int data_idx = ossl_get_ssl_data_index();
d889a8
-    int connectdata_idx = ossl_get_ssl_conn_index();
d889a8
-    int sockindex_idx = ossl_get_ssl_sockindex_index();
d889a8
-    int proxy_idx = ossl_get_proxy_index();
d889a8
-
d889a8
-    if(data_idx >= 0 && connectdata_idx >= 0 && sockindex_idx >= 0 &&
d889a8
-       proxy_idx >= 0) {
d889a8
-      /* Store the data needed for the "new session" callback.
d889a8
-       * The sockindex is stored as a pointer to an array element. */
d889a8
-      SSL_set_ex_data(backend->handle, data_idx, data);
d889a8
-      SSL_set_ex_data(backend->handle, connectdata_idx, conn);
d889a8
-      SSL_set_ex_data(backend->handle, sockindex_idx, conn->sock + sockindex);
d889a8
-#ifndef CURL_DISABLE_PROXY
d889a8
-      SSL_set_ex_data(backend->handle, proxy_idx, SSL_IS_PROXY() ? (void *) 1:
d889a8
-                      NULL);
d889a8
-#else
d889a8
-      SSL_set_ex_data(backend->handle, proxy_idx, NULL);
d889a8
-#endif
d889a8
-
d889a8
-    }
d889a8
+  ossl_associate_connection(data, conn, sockindex);
d889a8
 
d889a8
-    Curl_ssl_sessionid_lock(data);
d889a8
-    if(!Curl_ssl_getsessionid(data, conn, SSL_IS_PROXY() ? TRUE : FALSE,
d889a8
-                              &ssl_sessionid, NULL, sockindex)) {
d889a8
-      /* we got a session id, use it! */
d889a8
-      if(!SSL_set_session(backend->handle, ssl_sessionid)) {
d889a8
-        Curl_ssl_sessionid_unlock(data);
d889a8
-        failf(data, "SSL: SSL_set_session failed: %s",
d889a8
-              ossl_strerror(ERR_get_error(), error_buffer,
d889a8
-                            sizeof(error_buffer)));
d889a8
-        return CURLE_SSL_CONNECT_ERROR;
d889a8
-      }
d889a8
-      /* Informational message */
d889a8
-      infof(data, "SSL re-using session ID\n");
d889a8
+  Curl_ssl_sessionid_lock(data);
d889a8
+  if(!Curl_ssl_getsessionid(data, conn, SSL_IS_PROXY() ? TRUE : FALSE,
d889a8
+                            &ssl_sessionid, NULL, sockindex)) {
d889a8
+    /* we got a session id, use it! */
d889a8
+    if(!SSL_set_session(backend->handle, ssl_sessionid)) {
d889a8
+      Curl_ssl_sessionid_unlock(data);
d889a8
+      failf(data, "SSL: SSL_set_session failed: %s",
d889a8
+            ossl_strerror(ERR_get_error(), error_buffer,
d889a8
+                          sizeof(error_buffer)));
d889a8
+      return CURLE_SSL_CONNECT_ERROR;
d889a8
     }
d889a8
-    Curl_ssl_sessionid_unlock(data);
d889a8
+    /* Informational message */
d889a8
+    infof(data, "SSL re-using session ID\n");
d889a8
   }
d889a8
+  Curl_ssl_sessionid_unlock(data);
d889a8
 
d889a8
 #ifndef CURL_DISABLE_PROXY
d889a8
   if(conn->proxy_ssl[sockindex].use) {
d889a8
@@ -4474,6 +4456,90 @@ static void *ossl_get_internals(struct ssl_connect_data *connssl,
d889a8
          (void *)backend->ctx : (void *)backend->handle;
d889a8
 }
d889a8
 
d889a8
+static void ossl_associate_connection(struct Curl_easy *data,
d889a8
+                                      struct connectdata *conn,
d889a8
+                                      int sockindex)
d889a8
+{
d889a8
+  struct ssl_connect_data *connssl = &conn->ssl[sockindex];
d889a8
+  struct ssl_backend_data *backend = connssl->backend;
d889a8
+
d889a8
+  /* If we don't have SSL context, do nothing. */
d889a8
+  if(!backend->handle)
d889a8
+    return;
d889a8
+
d889a8
+  if(SSL_SET_OPTION(primary.sessionid)) {
d889a8
+    int data_idx = ossl_get_ssl_data_index();
d889a8
+    int connectdata_idx = ossl_get_ssl_conn_index();
d889a8
+    int sockindex_idx = ossl_get_ssl_sockindex_index();
d889a8
+    int proxy_idx = ossl_get_proxy_index();
d889a8
+
d889a8
+    if(data_idx >= 0 && connectdata_idx >= 0 && sockindex_idx >= 0 &&
d889a8
+       proxy_idx >= 0) {
d889a8
+      /* Store the data needed for the "new session" callback.
d889a8
+       * The sockindex is stored as a pointer to an array element. */
d889a8
+      SSL_set_ex_data(backend->handle, data_idx, data);
d889a8
+      SSL_set_ex_data(backend->handle, connectdata_idx, conn);
d889a8
+      SSL_set_ex_data(backend->handle, sockindex_idx, conn->sock + sockindex);
d889a8
+#ifndef CURL_DISABLE_PROXY
d889a8
+      SSL_set_ex_data(backend->handle, proxy_idx, SSL_IS_PROXY() ? (void *) 1:
d889a8
+                      NULL);
d889a8
+#else
d889a8
+      SSL_set_ex_data(backend->handle, proxy_idx, NULL);
d889a8
+#endif
d889a8
+    }
d889a8
+  }
d889a8
+}
d889a8
+
d889a8
+/*
d889a8
+ * Starting with TLS 1.3, the ossl_new_session_cb callback gets called after
d889a8
+ * the handshake. If the transfer that sets up the callback gets killed before
d889a8
+ * this callback arrives, we must make sure to properly clear the data to
d889a8
+ * avoid UAF problems. A future optimization could be to instead store another
d889a8
+ * transfer that might still be using the same connection.
d889a8
+ */
d889a8
+
d889a8
+static void ossl_disassociate_connection(struct Curl_easy *data,
d889a8
+                                         int sockindex)
d889a8
+{
d889a8
+  struct connectdata *conn = data->conn;
d889a8
+  struct ssl_connect_data *connssl = &conn->ssl[sockindex];
d889a8
+  struct ssl_backend_data *backend = connssl->backend;
d889a8
+
d889a8
+  /* If we don't have SSL context, do nothing. */
d889a8
+  if(!backend->handle)
d889a8
+    return;
d889a8
+
d889a8
+  if(SSL_SET_OPTION(primary.sessionid)) {
d889a8
+    bool isproxy = FALSE;
d889a8
+    bool incache;
d889a8
+    void *old_ssl_sessionid = NULL;
d889a8
+    int data_idx = ossl_get_ssl_data_index();
d889a8
+    int connectdata_idx = ossl_get_ssl_conn_index();
d889a8
+    int sockindex_idx = ossl_get_ssl_sockindex_index();
d889a8
+    int proxy_idx = ossl_get_proxy_index();
d889a8
+
d889a8
+    if(data_idx >= 0 && connectdata_idx >= 0 && sockindex_idx >= 0 &&
d889a8
+       proxy_idx >= 0) {
d889a8
+      /* Invalidate the session cache entry, if any */
d889a8
+      isproxy = SSL_get_ex_data(backend->handle, proxy_idx) ? TRUE : FALSE;
d889a8
+
d889a8
+      /* Disable references to data in "new session" callback to avoid
d889a8
+       * accessing a stale pointer. */
d889a8
+      SSL_set_ex_data(backend->handle, data_idx, NULL);
d889a8
+      SSL_set_ex_data(backend->handle, connectdata_idx, NULL);
d889a8
+      SSL_set_ex_data(backend->handle, sockindex_idx, NULL);
d889a8
+      SSL_set_ex_data(backend->handle, proxy_idx, NULL);
d889a8
+    }
d889a8
+
d889a8
+    Curl_ssl_sessionid_lock(data);
d889a8
+    incache = !(Curl_ssl_getsessionid(data, conn, isproxy,
d889a8
+                                      &old_ssl_sessionid, NULL, sockindex));
d889a8
+    if(incache)
d889a8
+      Curl_ssl_delsessionid(data, old_ssl_sessionid);
d889a8
+    Curl_ssl_sessionid_unlock(data);
d889a8
+  }
d889a8
+}
d889a8
+
d889a8
 const struct Curl_ssl Curl_ssl_openssl = {
d889a8
   { CURLSSLBACKEND_OPENSSL, "openssl" }, /* info */
d889a8
 
d889a8
@@ -4508,10 +4574,12 @@ const struct Curl_ssl Curl_ssl_openssl = {
d889a8
   ossl_engines_list,        /* engines_list */
d889a8
   Curl_none_false_start,    /* false_start */
d889a8
 #if (OPENSSL_VERSION_NUMBER >= 0x0090800fL) && !defined(OPENSSL_NO_SHA256)
d889a8
-  ossl_sha256sum            /* sha256sum */
d889a8
+  ossl_sha256sum,           /* sha256sum */
d889a8
 #else
d889a8
-  NULL                      /* sha256sum */
d889a8
+  NULL,                     /* sha256sum */
d889a8
 #endif
d889a8
+  ossl_associate_connection, /* associate_connection */
d889a8
+  ossl_disassociate_connection /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_OPENSSL */
d889a8
diff --git a/lib/vtls/rustls.c b/lib/vtls/rustls.c
d889a8
index e4f589d..fb8d634 100644
d889a8
--- a/lib/vtls/rustls.c
d889a8
+++ b/lib/vtls/rustls.c
d889a8
@@ -554,7 +554,9 @@ const struct Curl_ssl Curl_ssl_rustls = {
d889a8
   Curl_none_set_engine_default,    /* set_engine_default */
d889a8
   Curl_none_engines_list,          /* engines_list */
d889a8
   Curl_none_false_start,           /* false_start */
d889a8
-  NULL                             /* sha256sum */
d889a8
+  NULL,                            /* sha256sum */
d889a8
+  NULL,                            /* associate_connection */
d889a8
+  NULL                             /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_RUSTLS */
d889a8
diff --git a/lib/vtls/schannel.c b/lib/vtls/schannel.c
d889a8
index 961a71f..a80eb50 100644
d889a8
--- a/lib/vtls/schannel.c
d889a8
+++ b/lib/vtls/schannel.c
d889a8
@@ -2429,7 +2429,9 @@ const struct Curl_ssl Curl_ssl_schannel = {
d889a8
   Curl_none_set_engine_default,      /* set_engine_default */
d889a8
   Curl_none_engines_list,            /* engines_list */
d889a8
   Curl_none_false_start,             /* false_start */
d889a8
-  schannel_sha256sum                 /* sha256sum */
d889a8
+  schannel_sha256sum,                /* sha256sum */
d889a8
+  NULL,                              /* associate_connection */
d889a8
+  NULL                               /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif /* USE_SCHANNEL */
d889a8
diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c
d889a8
index 9d637da..b24b489 100644
d889a8
--- a/lib/vtls/sectransp.c
d889a8
+++ b/lib/vtls/sectransp.c
d889a8
@@ -3314,6 +3314,8 @@ const struct Curl_ssl Curl_ssl_sectransp = {
d889a8
   Curl_none_engines_list,             /* engines_list */
d889a8
   sectransp_false_start,              /* false_start */
d889a8
   sectransp_sha256sum                 /* sha256sum */
d889a8
+  NULL,                               /* associate_connection */
d889a8
+  NULL                                /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #ifdef __clang__
d889a8
diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c
d889a8
index 2e07df0..22cfb88 100644
d889a8
--- a/lib/vtls/vtls.c
d889a8
+++ b/lib/vtls/vtls.c
d889a8
@@ -579,6 +579,25 @@ CURLcode Curl_ssl_addsessionid(struct Curl_easy *data,
d889a8
   return CURLE_OK;
d889a8
 }
d889a8
 
d889a8
+void Curl_ssl_associate_conn(struct Curl_easy *data,
d889a8
+                             struct connectdata *conn)
d889a8
+{
d889a8
+  if(Curl_ssl->associate_connection) {
d889a8
+    Curl_ssl->associate_connection(data, conn, FIRSTSOCKET);
d889a8
+    if(conn->sock[SECONDARYSOCKET] && conn->bits.sock_accepted)
d889a8
+      Curl_ssl->associate_connection(data, conn, SECONDARYSOCKET);
d889a8
+  }
d889a8
+}
d889a8
+
d889a8
+void Curl_ssl_detach_conn(struct Curl_easy *data,
d889a8
+                          struct connectdata *conn)
d889a8
+{
d889a8
+  if(Curl_ssl->disassociate_connection) {
d889a8
+    Curl_ssl->disassociate_connection(data, FIRSTSOCKET);
d889a8
+    if(conn->sock[SECONDARYSOCKET] && conn->bits.sock_accepted)
d889a8
+      Curl_ssl->disassociate_connection(data, SECONDARYSOCKET);
d889a8
+  }
d889a8
+}
d889a8
 
d889a8
 void Curl_ssl_close_all(struct Curl_easy *data)
d889a8
 {
d889a8
@@ -1207,7 +1226,9 @@ static const struct Curl_ssl Curl_ssl_multi = {
d889a8
   Curl_none_set_engine_default,      /* set_engine_default */
d889a8
   Curl_none_engines_list,            /* engines_list */
d889a8
   Curl_none_false_start,             /* false_start */
d889a8
-  NULL                               /* sha256sum */
d889a8
+  NULL,                              /* sha256sum */
d889a8
+  NULL,                              /* associate_connection */
d889a8
+  NULL                               /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 const struct Curl_ssl *Curl_ssl =
d889a8
diff --git a/lib/vtls/vtls.h b/lib/vtls/vtls.h
d889a8
index 2b43e77..78d1003 100644
d889a8
--- a/lib/vtls/vtls.h
d889a8
+++ b/lib/vtls/vtls.h
d889a8
@@ -83,6 +83,11 @@ struct Curl_ssl {
d889a8
   bool (*false_start)(void);
d889a8
   CURLcode (*sha256sum)(const unsigned char *input, size_t inputlen,
d889a8
                     unsigned char *sha256sum, size_t sha256sumlen);
d889a8
+
d889a8
+  void (*associate_connection)(struct Curl_easy *data,
d889a8
+                               struct connectdata *conn,
d889a8
+                               int sockindex);
d889a8
+  void (*disassociate_connection)(struct Curl_easy *data, int sockindex);
d889a8
 };
d889a8
 
d889a8
 #ifdef USE_SSL
d889a8
@@ -277,6 +282,11 @@ bool Curl_ssl_cert_status_request(void);
d889a8
 
d889a8
 bool Curl_ssl_false_start(void);
d889a8
 
d889a8
+void Curl_ssl_associate_conn(struct Curl_easy *data,
d889a8
+                             struct connectdata *conn);
d889a8
+void Curl_ssl_detach_conn(struct Curl_easy *data,
d889a8
+                          struct connectdata *conn);
d889a8
+
d889a8
 #define SSL_SHUTDOWN_TIMEOUT 10000 /* ms */
d889a8
 
d889a8
 #else /* if not USE_SSL */
d889a8
@@ -303,6 +313,8 @@ bool Curl_ssl_false_start(void);
d889a8
 #define Curl_ssl_cert_status_request() FALSE
d889a8
 #define Curl_ssl_false_start() FALSE
d889a8
 #define Curl_ssl_tls13_ciphersuites() FALSE
d889a8
+#define Curl_ssl_associate_conn(a,b) Curl_nop_stmt
d889a8
+#define Curl_ssl_detach_conn(a,b) Curl_nop_stmt
d889a8
 #endif
d889a8
 
d889a8
 #endif /* HEADER_CURL_VTLS_H */
d889a8
diff --git a/lib/vtls/wolfssl.c b/lib/vtls/wolfssl.c
d889a8
index c6f4280..9c1598b 100644
d889a8
--- a/lib/vtls/wolfssl.c
d889a8
+++ b/lib/vtls/wolfssl.c
d889a8
@@ -1164,7 +1164,9 @@ const struct Curl_ssl Curl_ssl_wolfssl = {
d889a8
   Curl_none_set_engine_default,    /* set_engine_default */
d889a8
   Curl_none_engines_list,          /* engines_list */
d889a8
   Curl_none_false_start,           /* false_start */
d889a8
-  wolfssl_sha256sum                /* sha256sum */
d889a8
+  wolfssl_sha256sum,               /* sha256sum */
d889a8
+  NULL,                            /* associate_connection */
d889a8
+  NULL                             /* disassociate_connection */
d889a8
 };
d889a8
 
d889a8
 #endif
d889a8
-- 
d889a8
2.31.1
d889a8
d889a8
d889a8
From dd657bd43c0dc406a0be442a3b6546b3f97bb13f Mon Sep 17 00:00:00 2001
d889a8
From: Koichi Shiraishi <zchee.io@gmail.com>
d889a8
Date: Mon, 24 May 2021 20:26:44 +0900
d889a8
Subject: [PATCH 3/3] sectransp: fix 7f4a9a9b2a49 commit about missing comma
d889a8
d889a8
Follow-up to 7f4a9a9b2a495
d889a8
d889a8
Closes #7119
d889a8
d889a8
Upstream-commit: 98770344b2d6527c5b504fa740d7bbddbee1728e
d889a8
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
d889a8
---
d889a8
 lib/vtls/sectransp.c | 2 +-
d889a8
 1 file changed, 1 insertion(+), 1 deletion(-)
d889a8
d889a8
diff --git a/lib/vtls/sectransp.c b/lib/vtls/sectransp.c
d889a8
index b24b489..f2d7835 100644
d889a8
--- a/lib/vtls/sectransp.c
d889a8
+++ b/lib/vtls/sectransp.c
d889a8
@@ -3313,7 +3313,7 @@ const struct Curl_ssl Curl_ssl_sectransp = {
d889a8
   Curl_none_set_engine_default,       /* set_engine_default */
d889a8
   Curl_none_engines_list,             /* engines_list */
d889a8
   sectransp_false_start,              /* false_start */
d889a8
-  sectransp_sha256sum                 /* sha256sum */
d889a8
+  sectransp_sha256sum,                /* sha256sum */
d889a8
   NULL,                               /* associate_connection */
d889a8
   NULL                                /* disassociate_connection */
d889a8
 };
d889a8
-- 
d889a8
2.31.1
d889a8