]> git.proxmox.com Git - mirror_edk2.git/commitdiff
CryptoPkg/TlsLib: TlsSetVerifyHost: parse IP address literals as such (CVE-2019-14553)
authorLaszlo Ersek <lersek@redhat.com>
Thu, 24 Oct 2019 19:17:36 +0000 (21:17 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Sat, 2 Nov 2019 11:08:05 +0000 (12:08 +0100)
Using the inet_pton() function that we imported in the previous patches,
recognize if "HostName" is an IP address literal, and then parse it into
binary representation. Passing the latter to OpenSSL for server
certificate validation is important, per RFC-2818
<https://tools.ietf.org/html/rfc2818#section-3.1>:

> In some cases, the URI is specified as an IP address rather than a
> hostname. In this case, the iPAddress subjectAltName must be present in
> the certificate and must exactly match the IP in the URI.

Note: we cannot use X509_VERIFY_PARAM_set1_ip_asc() because in the OpenSSL
version that is currently consumed by edk2, said function depends on
sscanf() for parsing IPv4 literals. In
"CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c", we only provide an
empty -- always failing -- stub for sscanf(), however.

Cc: David Woodhouse <dwmw2@infradead.org>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Sivaraman Nainar <sivaramann@amiindia.co.in>
Cc: Xiaoyu Lu <xiaoyux.lu@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=960
CVE: CVE-2019-14553
Suggested-by: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Acked-by: Jian J Wang <jian.j.wang@intel.com>
Reviewed-by: Jiaxin Wu <jiaxin.wu@intel.com>
CryptoPkg/Library/TlsLib/TlsConfig.c

index 2bf5aee7c09365d8fbe3a64a77e4ef37e24722b0..307eb57896dc3d0db46abae4857311d864b5ca56 100644 (file)
@@ -517,7 +517,11 @@ TlsSetVerifyHost (
   IN     CHAR8                    *HostName\r
   )\r
 {\r
-  TLS_CONNECTION  *TlsConn;\r
+  TLS_CONNECTION    *TlsConn;\r
+  X509_VERIFY_PARAM *VerifyParam;\r
+  UINTN             BinaryAddressSize;\r
+  UINT8             BinaryAddress[MAX (NS_INADDRSZ, NS_IN6ADDRSZ)];\r
+  INTN              ParamStatus;\r
 \r
   TlsConn = (TLS_CONNECTION *) Tls;\r
   if (TlsConn == NULL || TlsConn->Ssl == NULL || HostName == NULL) {\r
@@ -526,11 +530,27 @@ TlsSetVerifyHost (
 \r
   SSL_set_hostflags(TlsConn->Ssl, Flags);\r
 \r
-  if (SSL_set1_host(TlsConn->Ssl, HostName) == 0) {\r
-    return EFI_ABORTED;\r
+  VerifyParam = SSL_get0_param (TlsConn->Ssl);\r
+  ASSERT (VerifyParam != NULL);\r
+\r
+  BinaryAddressSize = 0;\r
+  if (inet_pton (AF_INET6, HostName, BinaryAddress) == 1) {\r
+    BinaryAddressSize = NS_IN6ADDRSZ;\r
+  } else if (inet_pton (AF_INET, HostName, BinaryAddress) == 1) {\r
+    BinaryAddressSize = NS_INADDRSZ;\r
   }\r
 \r
-  return EFI_SUCCESS;\r
+  if (BinaryAddressSize > 0) {\r
+    DEBUG ((DEBUG_VERBOSE, "%a:%a: parsed \"%a\" as an IPv%c address "\r
+      "literal\n", gEfiCallerBaseName, __FUNCTION__, HostName,\r
+      (UINTN)((BinaryAddressSize == NS_IN6ADDRSZ) ? '6' : '4')));\r
+    ParamStatus = X509_VERIFY_PARAM_set1_ip (VerifyParam, BinaryAddress,\r
+                    BinaryAddressSize);\r
+  } else {\r
+    ParamStatus = X509_VERIFY_PARAM_set1_host (VerifyParam, HostName, 0);\r
+  }\r
+\r
+  return (ParamStatus == 1) ? EFI_SUCCESS : EFI_ABORTED;\r
 }\r
 \r
 /**\r