]> code.ossystems Code Review - openembedded-core.git/commitdiff
wpa-supplicant: fix CVE-2021-30004
authorStefan Ghinea <stefan.ghinea@windriver.com>
Thu, 8 Apr 2021 16:43:30 +0000 (19:43 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Sun, 18 Apr 2021 10:29:05 +0000 (11:29 +0100)
In wpa_supplicant and hostapd 2.9, forging attacks may occur because
AlgorithmIdentifier parameters are mishandled in tls/pkcs1.c and
tls/x509v3.c.

References:
https://nvd.nist.gov/vuln/detail/CVE-2021-30004

Upstream patches:
https://w1.fi/cgit/hostap/commit/?id=a0541334a6394f8237a4393b7372693cd7e96f15

Signed-off-by: Stefan Ghinea <stefan.ghinea@windriver.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/CVE-2021-30004.patch [new file with mode: 0644]
meta/recipes-connectivity/wpa-supplicant/wpa-supplicant_2.9.bb

diff --git a/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/CVE-2021-30004.patch b/meta/recipes-connectivity/wpa-supplicant/wpa-supplicant/CVE-2021-30004.patch
new file mode 100644 (file)
index 0000000..e2540fc
--- /dev/null
@@ -0,0 +1,123 @@
+From a0541334a6394f8237a4393b7372693cd7e96f15 Mon Sep 17 00:00:00 2001
+From: Jouni Malinen <j@w1.fi>
+Date: Sat, 13 Mar 2021 18:19:31 +0200
+Subject: [PATCH] ASN.1: Validate DigestAlgorithmIdentifier parameters
+
+The supported hash algorithms do not use AlgorithmIdentifier parameters.
+However, there are implementations that include NULL parameters in
+addition to ones that omit the parameters. Previous implementation did
+not check the parameters value at all which supported both these cases,
+but did not reject any other unexpected information.
+
+Use strict validation of digest algorithm parameters and reject any
+unexpected value when validating a signature. This is needed to prevent
+potential forging attacks.
+
+Signed-off-by: Jouni Malinen <j@w1.fi>
+
+Upstream-Status: Backport
+CVE: CVE-2021-30004
+
+Reference to upstream patch:
+[https://w1.fi/cgit/hostap/commit/?id=a0541334a6394f8237a4393b7372693cd7e96f15]
+
+Signed-off-by: Stefan Ghinea <stefan.ghinea@windriver.com>
+---
+ src/tls/pkcs1.c  | 21 +++++++++++++++++++++
+ src/tls/x509v3.c | 20 ++++++++++++++++++++
+ 2 files changed, 41 insertions(+)
+
+diff --git a/src/tls/pkcs1.c b/src/tls/pkcs1.c
+index 141ac50..e09db07 100644
+--- a/src/tls/pkcs1.c
++++ b/src/tls/pkcs1.c
+@@ -240,6 +240,8 @@ int pkcs1_v15_sig_ver(struct crypto_public_key *pk,
+               os_free(decrypted);
+               return -1;
+       }
++      wpa_hexdump(MSG_MSGDUMP, "PKCS #1: DigestInfo",
++                  hdr.payload, hdr.length);
+       pos = hdr.payload;
+       end = pos + hdr.length;
+@@ -261,6 +263,8 @@ int pkcs1_v15_sig_ver(struct crypto_public_key *pk,
+               os_free(decrypted);
+               return -1;
+       }
++      wpa_hexdump(MSG_MSGDUMP, "PKCS #1: DigestAlgorithmIdentifier",
++                  hdr.payload, hdr.length);
+       da_end = hdr.payload + hdr.length;
+       if (asn1_get_oid(hdr.payload, hdr.length, &oid, &next)) {
+@@ -269,6 +273,23 @@ int pkcs1_v15_sig_ver(struct crypto_public_key *pk,
+               os_free(decrypted);
+               return -1;
+       }
++      wpa_hexdump(MSG_MSGDUMP, "PKCS #1: Digest algorithm parameters",
++                  next, da_end - next);
++
++      /*
++       * RFC 5754: The correct encoding for the SHA2 algorithms would be to
++       * omit the parameters, but there are implementation that encode these
++       * as a NULL element. Allow these two cases and reject anything else.
++       */
++      if (da_end > next &&
++          (asn1_get_next(next, da_end - next, &hdr) < 0 ||
++           !asn1_is_null(&hdr) ||
++           hdr.payload + hdr.length != da_end)) {
++              wpa_printf(MSG_DEBUG,
++                         "PKCS #1: Unexpected digest algorithm parameters");
++              os_free(decrypted);
++              return -1;
++      }
+       if (!asn1_oid_equal(&oid, hash_alg)) {
+               char txt[100], txt2[100];
+diff --git a/src/tls/x509v3.c b/src/tls/x509v3.c
+index 1bd5aa0..bf2289f 100644
+--- a/src/tls/x509v3.c
++++ b/src/tls/x509v3.c
+@@ -1834,6 +1834,7 @@ int x509_check_signature(struct x509_certificate *issuer,
+               os_free(data);
+               return -1;
+       }
++      wpa_hexdump(MSG_MSGDUMP, "X509: DigestInfo", hdr.payload, hdr.length);
+       pos = hdr.payload;
+       end = pos + hdr.length;
+@@ -1855,6 +1856,8 @@ int x509_check_signature(struct x509_certificate *issuer,
+               os_free(data);
+               return -1;
+       }
++      wpa_hexdump(MSG_MSGDUMP, "X509: DigestAlgorithmIdentifier",
++                  hdr.payload, hdr.length);
+       da_end = hdr.payload + hdr.length;
+       if (asn1_get_oid(hdr.payload, hdr.length, &oid, &next)) {
+@@ -1862,6 +1865,23 @@ int x509_check_signature(struct x509_certificate *issuer,
+               os_free(data);
+               return -1;
+       }
++      wpa_hexdump(MSG_MSGDUMP, "X509: Digest algorithm parameters",
++                  next, da_end - next);
++
++      /*
++       * RFC 5754: The correct encoding for the SHA2 algorithms would be to
++       * omit the parameters, but there are implementation that encode these
++       * as a NULL element. Allow these two cases and reject anything else.
++       */
++      if (da_end > next &&
++          (asn1_get_next(next, da_end - next, &hdr) < 0 ||
++           !asn1_is_null(&hdr) ||
++           hdr.payload + hdr.length != da_end)) {
++              wpa_printf(MSG_DEBUG,
++                         "X509: Unexpected digest algorithm parameters");
++              os_free(data);
++              return -1;
++      }
+       if (x509_sha1_oid(&oid)) {
+               if (signature->oid.oid[6] != 5 /* sha-1WithRSAEncryption */) {
+-- 
+2.17.1
+
index 357c28634aea7818e9afe1d19661a585aa24eb12..cddcfb68112dd6ec177eb07dcad1afe4ab106602 100644 (file)
@@ -32,6 +32,7 @@ SRC_URI = "http://w1.fi/releases/wpa_supplicant-${PV}.tar.gz  \
            file://0003-WPS-UPnP-Handle-HTTP-initiation-failures-for-events-.patch \
            file://CVE-2021-0326.patch \
            file://CVE-2021-27803.patch \
+           file://CVE-2021-30004.patch \
           "
 SRC_URI[md5sum] = "2d2958c782576dc9901092fbfecb4190"
 SRC_URI[sha256sum] = "fcbdee7b4a64bea8177973299c8c824419c413ec2e3a95db63dd6a5dc3541f17"