Skip to contentSkip to conversation

nss: add a patch for CVE-2020-12403

PATCH New Marta Rybczynska 1 participant 1 message Nov 3, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nss: add a patch for CVE-2020-12403

From the description:
A flaw was found in the way CHACHA20-POLY1305 was implemented in NSS in versions before 3.55. When using multi-part Chacha20, it could cause out-of-bounds reads.

The fix includes two patches: one checking the length, and the other disabling the multi-part ChaCha20.

---
 .../nss/nss/CVE-2020-12403.patch              | 68 +++++++++++++
 .../nss/nss/CVE-2020-12403_2.patch            | 96 +++++++++++++++++++
 meta-oe/recipes-support/nss/nss_3.51.1.bb     |  2 +
 3 files changed, 166 insertions(+)
 create mode 100644 meta-oe/recipes-support/nss/nss/CVE-2020-12403.patch
 create mode 100644 meta-oe/recipes-support/nss/nss/CVE-2020-12403_2.patch
meta-oe/recipes-support/nss/nss/CVE-2020-12403.patch new file +68 -0
new file mode 100644
index 000000000..3ed8faf52
@@ -0,0 +1,68 @@
+From c6c2243be1a1359b4f22ffa51a90e84dc43b98d0 Mon Sep 17 00:00:00 2001
+From: Marta Rybczynska <[email protected]>
+Date: Wed, 3 Nov 2021 12:12:37 +0100
+Subject: [PATCH] nss: fix CVE-2020-12403
+
+# HG changeset patch
+# User Benjamin Beurdouche <[email protected]>
+# Date 1595031218 0
+# Node ID c25adfdfab34ddb08d3262aac3242e3399de1095
+# Parent  f282556e6cc7715f5754aeaadda6f902590e7e38
+Bug 1636771 - Fix incorrect call to Chacha20Poly1305 by PKCS11. r=jcj,kjacobs,rrelyea
+
+Differential Revision: https://phabricator.services.mozilla.com/D74801
+
+Upstream-Status: Backport
+
+CVE: CVE-2020-12403
+
+Signed-off-by: Marta Rybczynska <[email protected]>
+---
+ .../pk11_gtest/pk11_chacha20poly1305_unittest.cc      | 11 +++++++++--
+ nss/lib/freebl/chacha20poly1305.c                     |  2 +-
+ 2 files changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/nss/gtests/pk11_gtest/pk11_chacha20poly1305_unittest.cc b/nss/gtests/pk11_gtest/pk11_chacha20poly1305_unittest.cc
+index 2663441..a461977 100644
+--- a/nss/gtests/pk11_gtest/pk11_chacha20poly1305_unittest.cc
++++ b/nss/gtests/pk11_gtest/pk11_chacha20poly1305_unittest.cc
+@@ -44,7 +44,7 @@ class Pkcs11ChaCha20Poly1305Test
+     SECItem params = {siBuffer, reinterpret_cast<unsigned char*>(&aead_params),
+                       sizeof(aead_params)};
+ 
+-    // Encrypt with bad parameters.
++    // Encrypt with bad parameters (TagLen is too long).
+     unsigned int encrypted_len = 0;
+     std::vector<uint8_t> encrypted(data_len + aead_params.ulTagLen);
+     aead_params.ulTagLen = 158072;
+@@ -53,9 +53,16 @@ class Pkcs11ChaCha20Poly1305Test
+                      &encrypted_len, encrypted.size(), data, data_len);
+     EXPECT_EQ(SECFailure, rv);
+     EXPECT_EQ(0U, encrypted_len);
+-    aead_params.ulTagLen = 16;
++
++    // Encrypt with bad parameters (TagLen is too short).
++    aead_params.ulTagLen = 2;
++    rv = PK11_Encrypt(key.get(), kMech, &params, encrypted.data(),
++                      &encrypted_len, encrypted.size(), data, data_len);
++    EXPECT_EQ(SECFailure, rv);
++    EXPECT_EQ(0U, encrypted_len);
+ 
+     // Encrypt.
++    aead_params.ulTagLen = 16;
+     rv = PK11_Encrypt(key.get(), kMech, &params, encrypted.data(),
+                       &encrypted_len, encrypted.size(), data, data_len);
+ 
+diff --git a/nss/lib/freebl/chacha20poly1305.c b/nss/lib/freebl/chacha20poly1305.c
+index 4daba2a..9d94f59 100644
+--- a/nss/lib/freebl/chacha20poly1305.c
++++ b/nss/lib/freebl/chacha20poly1305.c
+@@ -60,7 +60,7 @@ ChaCha20Poly1305_InitContext(ChaCha20Poly1305Context *ctx,
+         PORT_SetError(SEC_ERROR_BAD_KEY);
+         return SECFailure;
+     }
+-    if (tagLen == 0 || tagLen > 16) {
++    if (tagLen != 16) {
+         PORT_SetError(SEC_ERROR_INPUT_LEN);
+         return SECFailure;
+     }
meta-oe/recipes-support/nss/nss/CVE-2020-12403_2.patch new file +96 -0

96 lines not on this page · raw message

meta-oe/recipes-support/nss/nss_3.51.1.bb +2 -0
index ac046ed0f..220610dea 100644
@@ -37,6 +37,8 @@ SRC_URI = "http://ftp.mozilla.org/pub/mozilla.org/security/nss/releases/${VERSIO
            file://0001-Bug-1631576-Force-a-fixed-length-for-DSA-exponentiat.patch \
            file://CVE-2020-12401.patch \
            file://CVE-2020-6829_12400.patch \
+           file://CVE-2020-12403.patch \
+           file://CVE-2020-12403_2.patch \
            "
 
 SRC_URI[md5sum] = "6acaf1ddff69306ae30a908881c6f233"
Signature · 1 line
2.33.0