Blame SOURCES/0039-curl-7.61.1-CVE-2022-27782.patch

07e41b
From d4247fa7baf0859729fff2fe5cf0bfab8322d1a5 Mon Sep 17 00:00:00 2001
07e41b
From: Daniel Stenberg <daniel@haxx.se>
07e41b
Date: Mon, 9 May 2022 23:13:53 +0200
07e41b
Subject: [PATCH 1/2] tls: check more TLS details for connection reuse
07e41b
07e41b
CVE-2022-27782
07e41b
07e41b
Reported-by: Harry Sintonen
07e41b
Bug: https://curl.se/docs/CVE-2022-27782.html
07e41b
Closes #8825
07e41b
07e41b
Upstream-commit: f18af4f874cecab82a9797e8c7541e0990c7a64c
07e41b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
07e41b
---
07e41b
 lib/setopt.c       | 29 +++++++++++++++++------------
07e41b
 lib/url.c          | 19 ++++++++++++-------
07e41b
 lib/urldata.h      | 14 +++++++-------
07e41b
 lib/vtls/openssl.c | 10 +++++-----
07e41b
 lib/vtls/vtls.c    | 21 +++++++++++++++++++++
07e41b
 5 files changed, 62 insertions(+), 31 deletions(-)
07e41b
07e41b
diff --git a/lib/setopt.c b/lib/setopt.c
07e41b
index b07ccfe..319a010 100644
07e41b
--- a/lib/setopt.c
07e41b
+++ b/lib/setopt.c
07e41b
@@ -2044,6 +2044,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
07e41b
 
07e41b
   case CURLOPT_SSL_OPTIONS:
07e41b
     arg = va_arg(param, long);
07e41b
+    data->set.ssl.primary.ssl_options = (unsigned char)(arg & 0xff);
07e41b
     data->set.ssl.enable_beast = arg&CURLSSLOPT_ALLOW_BEAST?TRUE:FALSE;
07e41b
     data->set.ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
07e41b
     data->set.ssl.no_partialchain = !!(arg & CURLSSLOPT_NO_PARTIALCHAIN);
07e41b
@@ -2051,6 +2052,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
07e41b
 
07e41b
   case CURLOPT_PROXY_SSL_OPTIONS:
07e41b
     arg = va_arg(param, long);
07e41b
+    data->set.proxy_ssl.primary.ssl_options = (unsigned char)(arg & 0xff);
07e41b
     data->set.proxy_ssl.enable_beast = arg&CURLSSLOPT_ALLOW_BEAST?TRUE:FALSE;
07e41b
     data->set.proxy_ssl.no_revoke = !!(arg & CURLSSLOPT_NO_REVOKE);
07e41b
     break;
07e41b
@@ -2451,44 +2453,47 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option,
07e41b
   case CURLOPT_TLSAUTH_USERNAME:
07e41b
     result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME],
07e41b
                             va_arg(param, char *));
07e41b
-    if(data->set.str[STRING_TLSAUTH_USERNAME] && !data->set.ssl.authtype)
07e41b
-      data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
07e41b
+    if(data->set.str[STRING_TLSAUTH_USERNAME] &&
07e41b
+       !data->set.ssl.primary.authtype)
07e41b
+      data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
07e41b
     break;
07e41b
   case CURLOPT_PROXY_TLSAUTH_USERNAME:
07e41b
     result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_USERNAME_PROXY],
07e41b
                             va_arg(param, char *));
07e41b
     if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] &&
07e41b
-       !data->set.proxy_ssl.authtype)
07e41b
-      data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
07e41b
+       !data->set.proxy_ssl.primary.authtype)
07e41b
+      data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default to
07e41b
+                                                                  SRP */
07e41b
     break;
07e41b
   case CURLOPT_TLSAUTH_PASSWORD:
07e41b
     result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD],
07e41b
                             va_arg(param, char *));
07e41b
-    if(data->set.str[STRING_TLSAUTH_USERNAME] && !data->set.ssl.authtype)
07e41b
-      data->set.ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
07e41b
+    if(data->set.str[STRING_TLSAUTH_USERNAME] &&
07e41b
+       !data->set.ssl.primary.authtype)
07e41b
+      data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */
07e41b
     break;
07e41b
   case CURLOPT_PROXY_TLSAUTH_PASSWORD:
07e41b
     result = Curl_setstropt(&data->set.str[STRING_TLSAUTH_PASSWORD_PROXY],
07e41b
                             va_arg(param, char *));
07e41b
     if(data->set.str[STRING_TLSAUTH_USERNAME_PROXY] &&
07e41b
-       !data->set.proxy_ssl.authtype)
07e41b
-      data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP; /* default to SRP */
07e41b
+       !data->set.proxy_ssl.primary.authtype)
07e41b
+      data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP; /* default */
07e41b
     break;
07e41b
   case CURLOPT_TLSAUTH_TYPE:
07e41b
     argptr = va_arg(param, char *);
07e41b
     if(!argptr ||
07e41b
        strncasecompare(argptr, "SRP", strlen("SRP")))
07e41b
-      data->set.ssl.authtype = CURL_TLSAUTH_SRP;
07e41b
+      data->set.ssl.primary.authtype = CURL_TLSAUTH_SRP;
07e41b
     else
07e41b
-      data->set.ssl.authtype = CURL_TLSAUTH_NONE;
07e41b
+      data->set.ssl.primary.authtype = CURL_TLSAUTH_NONE;
07e41b
     break;
07e41b
   case CURLOPT_PROXY_TLSAUTH_TYPE:
07e41b
     argptr = va_arg(param, char *);
07e41b
     if(!argptr ||
07e41b
        strncasecompare(argptr, "SRP", strlen("SRP")))
07e41b
-      data->set.proxy_ssl.authtype = CURL_TLSAUTH_SRP;
07e41b
+      data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_SRP;
07e41b
     else
07e41b
-      data->set.proxy_ssl.authtype = CURL_TLSAUTH_NONE;
07e41b
+      data->set.proxy_ssl.primary.authtype = CURL_TLSAUTH_NONE;
07e41b
     break;
07e41b
 #endif
07e41b
   case CURLOPT_DNS_SERVERS:
07e41b
diff --git a/lib/url.c b/lib/url.c
07e41b
index 7dd5267..30fc5ad 100644
07e41b
--- a/lib/url.c
07e41b
+++ b/lib/url.c
07e41b
@@ -461,7 +461,7 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data)
07e41b
   set->ssl.primary.verifypeer = TRUE;
07e41b
   set->ssl.primary.verifyhost = TRUE;
07e41b
 #ifdef USE_TLS_SRP
07e41b
-  set->ssl.authtype = CURL_TLSAUTH_NONE;
07e41b
+  set->ssl.primary.authtype = CURL_TLSAUTH_NONE;
07e41b
 #endif
07e41b
   set->ssh_auth_types = CURLSSH_AUTH_DEFAULT; /* defaults to any auth
07e41b
                                                       type */
07e41b
@@ -1881,10 +1881,12 @@ static struct connectdata *allocate_conn(struct Curl_easy *data)
07e41b
   conn->ssl_config.verifystatus = data->set.ssl.primary.verifystatus;
07e41b
   conn->ssl_config.verifypeer = data->set.ssl.primary.verifypeer;
07e41b
   conn->ssl_config.verifyhost = data->set.ssl.primary.verifyhost;
07e41b
+  conn->ssl_config.ssl_options = data->set.ssl.primary.ssl_options;
07e41b
   conn->proxy_ssl_config.verifystatus =
07e41b
     data->set.proxy_ssl.primary.verifystatus;
07e41b
   conn->proxy_ssl_config.verifypeer = data->set.proxy_ssl.primary.verifypeer;
07e41b
   conn->proxy_ssl_config.verifyhost = data->set.proxy_ssl.primary.verifyhost;
07e41b
+  conn->proxy_ssl_config.ssl_options = data->set.proxy_ssl.primary.ssl_options;
07e41b
 
07e41b
   conn->ip_version = data->set.ipver;
07e41b
 
07e41b
@@ -4362,8 +4364,9 @@ static CURLcode create_conn(struct Curl_easy *data,
07e41b
   data->set.proxy_ssl.primary.cipher_list13 =
07e41b
     data->set.str[STRING_SSL_CIPHER13_LIST_PROXY];
07e41b
 
07e41b
-  data->set.ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE];
07e41b
-  data->set.proxy_ssl.CRLfile = data->set.str[STRING_SSL_CRLFILE_PROXY];
07e41b
+  data->set.ssl.primary.CRLfile = data->set.str[STRING_SSL_CRLFILE];
07e41b
+  data->set.proxy_ssl.primary.CRLfile =
07e41b
+    data->set.str[STRING_SSL_CRLFILE_PROXY];
07e41b
   data->set.ssl.cert = data->set.str[STRING_CERT];
07e41b
   data->set.proxy_ssl.cert = data->set.str[STRING_CERT_PROXY];
07e41b
   data->set.ssl.cert_type = data->set.str[STRING_CERT_TYPE];
07e41b
@@ -4377,10 +4380,12 @@ static CURLcode create_conn(struct Curl_easy *data,
07e41b
   data->set.ssl.primary.clientcert = data->set.str[STRING_CERT];
07e41b
   data->set.proxy_ssl.primary.clientcert = data->set.str[STRING_CERT_PROXY];
07e41b
 #ifdef USE_TLS_SRP
07e41b
-  data->set.ssl.username = data->set.str[STRING_TLSAUTH_USERNAME];
07e41b
-  data->set.proxy_ssl.username = data->set.str[STRING_TLSAUTH_USERNAME_PROXY];
07e41b
-  data->set.ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD];
07e41b
-  data->set.proxy_ssl.password = data->set.str[STRING_TLSAUTH_PASSWORD_PROXY];
07e41b
+  data->set.ssl.primary.username = data->set.str[STRING_TLSAUTH_USERNAME];
07e41b
+  data->set.ssl.primary.password = data->set.str[STRING_TLSAUTH_PASSWORD];
07e41b
+  data->set.proxy_ssl.primary.username =
07e41b
+    data->set.str[STRING_TLSAUTH_USERNAME_PROXY];
07e41b
+  data->set.proxy_ssl.primary.password =
07e41b
+    data->set.str[STRING_TLSAUTH_PASSWORD_PROXY];
07e41b
 #endif
07e41b
 
07e41b
   if(!Curl_clone_primary_ssl_config(&data->set.ssl.primary,
07e41b
diff --git a/lib/urldata.h b/lib/urldata.h
07e41b
index 026684b..0e48841 100644
07e41b
--- a/lib/urldata.h
07e41b
+++ b/lib/urldata.h
07e41b
@@ -229,6 +229,13 @@ struct ssl_primary_config {
07e41b
   char *egdsocket;       /* path to file containing the EGD daemon socket */
07e41b
   char *cipher_list;     /* list of ciphers to use */
07e41b
   char *cipher_list13;   /* list of TLS 1.3 cipher suites to use */
07e41b
+  char *CRLfile;         /* CRL to check certificate revocation */
07e41b
+#ifdef USE_TLS_SRP
07e41b
+  char *username; /* TLS username (for, e.g., SRP) */
07e41b
+  char *password; /* TLS password (for, e.g., SRP) */
07e41b
+  enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */
07e41b
+#endif
07e41b
+  unsigned char ssl_options;  /* the CURLOPT_SSL_OPTIONS bitmask */
07e41b
 };
07e41b
 
07e41b
 struct ssl_config_data {
07e41b
@@ -238,7 +245,6 @@ struct ssl_config_data {
07e41b
   bool no_revoke;    /* disable SSL certificate revocation checks */
07e41b
   bool no_partialchain;  /* don't accept partial certificate chains */
07e41b
   long certverifyresult; /* result from the certificate verification */
07e41b
-  char *CRLfile;   /* CRL to check certificate revocation */
07e41b
   curl_ssl_ctx_callback fsslctx; /* function to initialize ssl ctx */
07e41b
   void *fsslctxp;        /* parameter for call back */
07e41b
   bool certinfo;         /* gather lots of certificate info */
07e41b
@@ -249,12 +255,6 @@ struct ssl_config_data {
07e41b
   char *key; /* private key file name */
07e41b
   char *key_type; /* format for private key (default: PEM) */
07e41b
   char *key_passwd; /* plain text private key password */
07e41b
-
07e41b
-#ifdef USE_TLS_SRP
07e41b
-  char *username; /* TLS username (for, e.g., SRP) */
07e41b
-  char *password; /* TLS password (for, e.g., SRP) */
07e41b
-  enum CURL_TLSAUTH authtype; /* TLS authentication type (default SRP) */
07e41b
-#endif
07e41b
 };
07e41b
 
07e41b
 struct ssl_general_config {
07e41b
diff --git a/lib/vtls/openssl.c b/lib/vtls/openssl.c
07e41b
index 6c8faa2..75ff8d8 100644
07e41b
--- a/lib/vtls/openssl.c
07e41b
+++ b/lib/vtls/openssl.c
07e41b
@@ -2232,14 +2232,14 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
07e41b
     &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult;
07e41b
   const long int ssl_version = SSL_CONN_CONFIG(version);
07e41b
 #ifdef USE_TLS_SRP
07e41b
-  const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(authtype);
07e41b
+  const enum CURL_TLSAUTH ssl_authtype = SSL_SET_OPTION(primary.authtype);
07e41b
 #endif
07e41b
   char * const ssl_cert = SSL_SET_OPTION(cert);
07e41b
   const char * const ssl_cert_type = SSL_SET_OPTION(cert_type);
07e41b
   const char * const ssl_cafile = SSL_CONN_CONFIG(CAfile);
07e41b
   const char * const ssl_capath = SSL_CONN_CONFIG(CApath);
07e41b
   const bool verifypeer = SSL_CONN_CONFIG(verifypeer);
07e41b
-  const char * const ssl_crlfile = SSL_SET_OPTION(CRLfile);
07e41b
+  const char * const ssl_crlfile = SSL_SET_OPTION(primary.CRLfile);
07e41b
   char error_buffer[256];
07e41b
 
07e41b
   DEBUGASSERT(ssl_connect_1 == connssl->connecting_state);
07e41b
@@ -2501,15 +2501,15 @@ static CURLcode ossl_connect_step1(struct connectdata *conn, int sockindex)
07e41b
 #ifdef USE_TLS_SRP
07e41b
   if((ssl_authtype == CURL_TLSAUTH_SRP) &&
07e41b
      Curl_allow_auth_to_host(conn)) {
07e41b
-    char * const ssl_username = SSL_SET_OPTION(username);
07e41b
-
07e41b
+    char * const ssl_username = SSL_SET_OPTION(primary.username);
07e41b
+    char * const ssl_password = SSL_SET_OPTION(primary.password);
07e41b
     infof(data, "Using TLS-SRP username: %s\n", ssl_username);
07e41b
 
07e41b
     if(!SSL_CTX_set_srp_username(BACKEND->ctx, ssl_username)) {
07e41b
       failf(data, "Unable to set SRP user name");
07e41b
       return CURLE_BAD_FUNCTION_ARGUMENT;
07e41b
     }
07e41b
-    if(!SSL_CTX_set_srp_password(BACKEND->ctx, SSL_SET_OPTION(password))) {
07e41b
+    if(!SSL_CTX_set_srp_password(BACKEND->ctx, ssl_password)) {
07e41b
       failf(data, "failed setting SRP password");
07e41b
       return CURLE_BAD_FUNCTION_ARGUMENT;
07e41b
     }
07e41b
diff --git a/lib/vtls/vtls.c b/lib/vtls/vtls.c
07e41b
index bdff93f..2b14fa6 100644
07e41b
--- a/lib/vtls/vtls.c
07e41b
+++ b/lib/vtls/vtls.c
07e41b
@@ -88,6 +88,7 @@ Curl_ssl_config_matches(struct ssl_primary_config* data,
07e41b
 {
07e41b
   if((data->version == needle->version) &&
07e41b
      (data->version_max == needle->version_max) &&
07e41b
+     (data->ssl_options == needle->ssl_options) &&
07e41b
      (data->verifypeer == needle->verifypeer) &&
07e41b
      (data->verifyhost == needle->verifyhost) &&
07e41b
      (data->verifystatus == needle->verifystatus) &&
07e41b
@@ -96,6 +97,12 @@ Curl_ssl_config_matches(struct ssl_primary_config* data,
07e41b
      Curl_safecmp(data->clientcert, needle->clientcert) &&
07e41b
      Curl_safecmp(data->random_file, needle->random_file) &&
07e41b
      Curl_safecmp(data->egdsocket, needle->egdsocket) &&
07e41b
+#ifdef USE_TLS_SRP
07e41b
+     Curl_safecmp(data->username, needle->username) &&
07e41b
+     Curl_safecmp(data->password, needle->password) &&
07e41b
+     (data->authtype == needle->authtype) &&
07e41b
+#endif
07e41b
+     Curl_safe_strcasecompare(data->CRLfile, needle->CRLfile) &&
07e41b
      Curl_safe_strcasecompare(data->cipher_list, needle->cipher_list) &&
07e41b
      Curl_safe_strcasecompare(data->cipher_list13, needle->cipher_list13))
07e41b
     return TRUE;
07e41b
@@ -113,6 +120,10 @@ Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
07e41b
   dest->verifyhost = source->verifyhost;
07e41b
   dest->verifystatus = source->verifystatus;
07e41b
   dest->sessionid = source->sessionid;
07e41b
+  dest->ssl_options = source->ssl_options;
07e41b
+#ifdef USE_TLS_SRP
07e41b
+  dest->authtype = source->authtype;
07e41b
+#endif
07e41b
 
07e41b
   CLONE_STRING(CApath);
07e41b
   CLONE_STRING(CAfile);
07e41b
@@ -122,6 +133,11 @@ Curl_clone_primary_ssl_config(struct ssl_primary_config *source,
07e41b
   CLONE_STRING(egdsocket);
07e41b
   CLONE_STRING(cipher_list);
07e41b
   CLONE_STRING(cipher_list13);
07e41b
+  CLONE_STRING(CRLfile);
07e41b
+#ifdef USE_TLS_SRP
07e41b
+  CLONE_STRING(username);
07e41b
+  CLONE_STRING(password);
07e41b
+#endif
07e41b
 
07e41b
   return TRUE;
07e41b
 }
07e41b
@@ -136,6 +152,11 @@ void Curl_free_primary_ssl_config(struct ssl_primary_config* sslc)
07e41b
   Curl_safefree(sslc->egdsocket);
07e41b
   Curl_safefree(sslc->cipher_list);
07e41b
   Curl_safefree(sslc->cipher_list13);
07e41b
+  Curl_safefree(sslc->CRLfile);
07e41b
+#ifdef USE_TLS_SRP
07e41b
+  Curl_safefree(sslc->username);
07e41b
+  Curl_safefree(sslc->password);
07e41b
+#endif
07e41b
 }
07e41b
 
07e41b
 #ifdef USE_SSL
07e41b
-- 
07e41b
2.34.1
07e41b
07e41b
07e41b
From a9cf46e6c6c9a4261f3ea8500dfef87c1436908b Mon Sep 17 00:00:00 2001
07e41b
From: Daniel Stenberg <daniel@haxx.se>
07e41b
Date: Mon, 9 May 2022 23:13:53 +0200
07e41b
Subject: [PATCH 2/2] url: check SSH config match on connection reuse
07e41b
07e41b
CVE-2022-27782
07e41b
07e41b
Reported-by: Harry Sintonen
07e41b
Bug: https://curl.se/docs/CVE-2022-27782.html
07e41b
Closes #8825
07e41b
07e41b
Upstream-commit: 1645e9b44505abd5cbaf65da5282c3f33b5924a5
07e41b
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
07e41b
---
07e41b
 lib/ssh.h |  4 ++--
07e41b
 lib/url.c | 11 +++++++++++
07e41b
 2 files changed, 13 insertions(+), 2 deletions(-)
07e41b
07e41b
diff --git a/lib/ssh.h b/lib/ssh.h
07e41b
index 0620aac..1114f8a 100644
07e41b
--- a/lib/ssh.h
07e41b
+++ b/lib/ssh.h
07e41b
@@ -117,8 +117,8 @@ struct ssh_conn {
07e41b
 
07e41b
   /* common */
07e41b
   const char *passphrase;     /* pass-phrase to use */
07e41b
-  char *rsa_pub;              /* path name */
07e41b
-  char *rsa;                  /* path name */
07e41b
+  char *rsa_pub;              /* strdup'ed public key file */
07e41b
+  char *rsa;                  /* strdup'ed private key file */
07e41b
   bool authed;                /* the connection has been authenticated fine */
07e41b
   sshstate state;             /* always use ssh.c:state() to change state! */
07e41b
   sshstate nextstate;         /* the state to goto after stopping */
07e41b
diff --git a/lib/url.c b/lib/url.c
07e41b
index 30fc5ad..8653ebb 100644
07e41b
--- a/lib/url.c
07e41b
+++ b/lib/url.c
07e41b
@@ -1030,6 +1030,12 @@ static size_t max_pipeline_length(struct Curl_multi *multi)
07e41b
 }
07e41b
 
07e41b
 
07e41b
+static bool ssh_config_matches(struct connectdata *one,
07e41b
+                               struct connectdata *two)
07e41b
+{
07e41b
+  return (Curl_safecmp(one->proto.sshc.rsa, two->proto.sshc.rsa) &&
07e41b
+          Curl_safecmp(one->proto.sshc.rsa_pub, two->proto.sshc.rsa_pub));
07e41b
+}
07e41b
 /*
07e41b
  * Given one filled in connection struct (named needle), this function should
07e41b
  * detect if there already is one that has all the significant details
07e41b
@@ -1299,6 +1305,11 @@ ConnectionExists(struct Curl_easy *data,
07e41b
         }
07e41b
       }
07e41b
 
07e41b
+      if(needle->handler->protocol & (CURLPROTO_SCP|CURLPROTO_SFTP)) {
07e41b
+        if(!ssh_config_matches(needle, check))
07e41b
+          continue;
07e41b
+      }
07e41b
+
07e41b
       if(!needle->bits.httpproxy || (needle->handler->flags&PROTOPT_SSL) ||
07e41b
          needle->bits.tunnel_proxy) {
07e41b
         /* The requested connection does not use a HTTP proxy or it uses SSL or
07e41b
-- 
07e41b
2.34.1
07e41b