|
| 1 | +From f35a51abd18af60bbc8cbad38c9e78b6aeecc22a Mon Sep 17 00:00:00 2001 |
| 2 | +From: AllSpark <allspark@microsoft.com> |
| 3 | +Date: Sat, 4 Jul 2026 16:11:17 +0000 |
| 4 | +Subject: [PATCH] Use VFY_VerifyDigestDirect for PKCS1.1.5 RSA signature |
| 5 | + verification |
| 6 | + |
| 7 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 8 | +Upstream-reference AI Backport of: https://libreswan.org/security/CVE-2026-50722/libreswan-5.3-CVE-2026-50722.patch |
| 9 | +--- |
| 10 | + lib/libswan/pubkey_rsa.c | 61 +++++++++------------------------------- |
| 11 | + 1 file changed, 14 insertions(+), 47 deletions(-) |
| 12 | + |
| 13 | +diff --git a/lib/libswan/pubkey_rsa.c b/lib/libswan/pubkey_rsa.c |
| 14 | +index a97590a..a68033b 100644 |
| 15 | +--- a/lib/libswan/pubkey_rsa.c |
| 16 | ++++ b/lib/libswan/pubkey_rsa.c |
| 17 | +@@ -533,7 +533,7 @@ static struct hash_signature RSA_pkcs1_1_5_sign_hash(const struct secret_pubkey_ |
| 18 | + static bool RSA_authenticate_signature_pkcs1_1_5_rsa(const struct crypt_mac *expected_hash, |
| 19 | + shunk_t signature, |
| 20 | + struct pubkey *pubkey, |
| 21 | +- const struct hash_desc *unused_hash_algo UNUSED, |
| 22 | ++ const struct hash_desc *hash_alg, |
| 23 | + diag_t *fatal_diag, |
| 24 | + struct logger *logger) |
| 25 | + { |
| 26 | +@@ -551,58 +551,25 @@ static bool RSA_authenticate_signature_pkcs1_1_5_rsa(const struct crypt_mac *exp |
| 27 | + LDBG_hunk(logger, *expected_hash); |
| 28 | + } |
| 29 | + |
| 30 | +- /* |
| 31 | +- * Use the same space used by the out going hash. |
| 32 | +- */ |
| 33 | +- |
| 34 | +- SECItem decrypted_signature = { |
| 35 | +- .type = siBuffer, |
| 36 | +- }; |
| 37 | +- |
| 38 | +- if (SECITEM_AllocItem(NULL, &decrypted_signature, signature.len) == NULL) { |
| 39 | +- llog_nss_error(RC_LOG, logger, "allocating space for decrypted RSA signature"); |
| 40 | +- return false; |
| 41 | +- } |
| 42 | +- |
| 43 | + /* NSS doesn't do const */ |
| 44 | +- const SECItem encrypted_signature = { |
| 45 | +- .type = siBuffer, |
| 46 | +- .data = DISCARD_CONST(unsigned char *, signature.ptr), |
| 47 | +- .len = signature.len, |
| 48 | +- }; |
| 49 | ++ SECItem hash_item = |
| 50 | ++ same_shunk_as_secitem(HUNK_AS_SHUNK(*expected_hash), siBuffer); |
| 51 | + |
| 52 | +- if (PK11_VerifyRecover(seckey_public, &encrypted_signature, &decrypted_signature, |
| 53 | +- lsw_nss_get_password_context(logger)) != SECSuccess) { |
| 54 | +- SECITEM_FreeItem(&decrypted_signature, PR_FALSE/*not-pointer*/); |
| 55 | +- ldbg(logger, "NSS RSA verify: decrypting signature is failed"); |
| 56 | +- *fatal_diag = NULL; |
| 57 | +- return false; |
| 58 | +- } |
| 59 | +- |
| 60 | +- if (LDBGP(DBG_CRYPT, logger)) { |
| 61 | +- LLOG_JAMBUF(DEBUG_STREAM, logger, buf) { |
| 62 | +- jam_string(buf, "NSS RSA verify: decrypted sig: "); |
| 63 | +- jam_nss_secitem(buf, &decrypted_signature); |
| 64 | +- } |
| 65 | +- } |
| 66 | +- |
| 67 | +- /* |
| 68 | +- * Expect the matching hash to appear at the end. See above |
| 69 | +- * for length check. It may, or may not, be prefixed by a |
| 70 | +- * PKCS#1 1.5 RSA ASN.1 blob. |
| 71 | +- */ |
| 72 | +- passert(decrypted_signature.len >= expected_hash->len); |
| 73 | +- uint8_t *start = (decrypted_signature.data |
| 74 | +- + decrypted_signature.len |
| 75 | +- - expected_hash->len); |
| 76 | +- if (!memeq(start, expected_hash->ptr, expected_hash->len)) { |
| 77 | +- ldbg(logger, "RSA Signature NOT verified"); |
| 78 | +- SECITEM_FreeItem(&decrypted_signature, PR_FALSE/*not-pointer*/); |
| 79 | ++ /* NSS doesn't do const */ |
| 80 | ++ SECItem signature_item = |
| 81 | ++ same_shunk_as_secitem(signature, siBuffer); |
| 82 | ++ |
| 83 | ++ if (VFY_VerifyDigestDirect(&hash_item, |
| 84 | ++ seckey_public, |
| 85 | ++ &signature_item, |
| 86 | ++ /*pubkey algorithm*/SEC_OID_PKCS1_RSA_ENCRYPTION, |
| 87 | ++ /*hash algorithm*/hash_alg->nss.oid_tag, |
| 88 | ++ lsw_nss_get_password_context(logger)) != SECSuccess) { |
| 89 | ++ ldbg_nss_error(logger, "NSS VFY_VerifyDigest() failed"); |
| 90 | + *fatal_diag = NULL; |
| 91 | + return false; |
| 92 | + } |
| 93 | + |
| 94 | +- SECITEM_FreeItem(&decrypted_signature, PR_FALSE/*not-pointer*/); |
| 95 | + *fatal_diag = NULL; |
| 96 | + return true; |
| 97 | + } |
| 98 | +-- |
| 99 | +2.45.4 |
| 100 | + |
0 commit comments