Skip to content

Commit df96124

Browse files
CBL-Mariner-BotKanishk-BansalKanishk Bansaljslobodzian
authored
[AUTO-CHERRYPICK] Patch openssl for ASN1 validation, BIO buffer overflow, OCB encryption, UTF8 encoding, and PKCS12 NULL checks - branch main (#15956)
Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com> Co-authored-by: Kanishk Bansal <103916909+Kanishk-Bansal@users.noreply.github.com> Co-authored-by: Kanishk Bansal <kanbansal@microsoft.com> Co-authored-by: jslobodzian <joslobo@microsoft.com>
1 parent 0c2e13e commit df96124

10 files changed

+374
-24
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
From 41be0f216404f14457bbf3b9cc488dba60b49296 Mon Sep 17 00:00:00 2001
2+
From: Norbert Pocs <norbertp@openssl.org>
3+
Date: Thu, 11 Dec 2025 12:49:00 +0100
4+
Subject: [PATCH] Check return code of UTF8_putc
5+
6+
Signed-off-by: Norbert Pocs <norbertp@openssl.org>
7+
8+
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
9+
Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
10+
(Merged from https://github.com/openssl/openssl/pull/29376)
11+
12+
Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com>
13+
---
14+
crypto/asn1/a_strex.c | 6 ++++--
15+
crypto/pkcs12/p12_utl.c | 5 +++++
16+
2 files changed, 9 insertions(+), 2 deletions(-)
17+
18+
diff --git a/crypto/asn1/a_strex.c b/crypto/asn1/a_strex.c
19+
index 4879b33..b852e06 100644
20+
--- a/crypto/asn1/a_strex.c
21+
+++ b/crypto/asn1/a_strex.c
22+
@@ -203,8 +203,10 @@ static int do_buf(unsigned char *buf, int buflen,
23+
orflags = CHARTYPE_LAST_ESC_2253;
24+
if (type & BUF_TYPE_CONVUTF8) {
25+
unsigned char utfbuf[6];
26+
- int utflen;
27+
- utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c);
28+
+ int utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c);
29+
+
30+
+ if (utflen < 0)
31+
+ return -1; /* error happened with UTF8 */
32+
for (i = 0; i < utflen; i++) {
33+
/*
34+
* We don't need to worry about setting orflags correctly
35+
diff --git a/crypto/pkcs12/p12_utl.c b/crypto/pkcs12/p12_utl.c
36+
index 43b9e3a..4998fcc 100644
37+
--- a/crypto/pkcs12/p12_utl.c
38+
+++ b/crypto/pkcs12/p12_utl.c
39+
@@ -207,6 +207,11 @@ char *OPENSSL_uni2utf8(const unsigned char *uni, int unilen)
40+
/* re-run the loop emitting UTF-8 string */
41+
for (asclen = 0, i = 0; i < unilen; ) {
42+
j = bmp_to_utf8(asctmp+asclen, uni+i, unilen-i);
43+
+ /* when UTF8_putc fails */
44+
+ if (j < 0) {
45+
+ OPENSSL_free(asctmp);
46+
+ return NULL;
47+
+ }
48+
if (j == 4) i += 4;
49+
else i += 2;
50+
asclen += j;
51+
--
52+
2.45.4
53+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
From 572844beca95068394c916626a6d3a490f831a49 Mon Sep 17 00:00:00 2001
2+
From: Bob Beck <beck@openssl.org>
3+
Date: Wed, 7 Jan 2026 11:29:48 -0700
4+
Subject: [PATCH] Ensure ASN1 types are checked before use.
5+
6+
Some of these were fixed by LibreSSL in commit https://github.com/openbsd/src/commit/aa1f637d454961d22117b4353f98253e984b3ba8
7+
this fix includes the other fixes in that commit, as well as fixes for others found by a scan
8+
for a similar unvalidated access paradigm in the tree.
9+
10+
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
11+
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
12+
Reviewed-by: Tomas Mraz <tomas@openssl.org>
13+
(Merged from https://github.com/openssl/openssl/pull/29582)
14+
15+
Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com>
16+
---
17+
apps/s_client.c | 3 ++-
18+
crypto/pkcs12/p12_kiss.c | 10 ++++++++--
19+
crypto/pkcs7/pk7_doit.c | 2 ++
20+
3 files changed, 12 insertions(+), 3 deletions(-)
21+
22+
diff --git a/apps/s_client.c b/apps/s_client.c
23+
index 83b3fc9..ddd77f7 100644
24+
--- a/apps/s_client.c
25+
+++ b/apps/s_client.c
26+
@@ -2688,8 +2688,9 @@ int s_client_main(int argc, char **argv)
27+
goto end;
28+
}
29+
atyp = ASN1_generate_nconf(genstr, cnf);
30+
- if (atyp == NULL) {
31+
+ if (atyp == NULL || atyp->type != V_ASN1_SEQUENCE) {
32+
NCONF_free(cnf);
33+
+ ASN1_TYPE_free(atyp);
34+
BIO_printf(bio_err, "ASN1_generate_nconf failed\n");
35+
goto end;
36+
}
37+
diff --git a/crypto/pkcs12/p12_kiss.c b/crypto/pkcs12/p12_kiss.c
38+
index 7ab9838..d90404d 100644
39+
--- a/crypto/pkcs12/p12_kiss.c
40+
+++ b/crypto/pkcs12/p12_kiss.c
41+
@@ -183,11 +183,17 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
42+
ASN1_BMPSTRING *fname = NULL;
43+
ASN1_OCTET_STRING *lkid = NULL;
44+
45+
- if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName)))
46+
+ if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_friendlyName))) {
47+
+ if (attrib->type != V_ASN1_BMPSTRING)
48+
+ return 0;
49+
fname = attrib->value.bmpstring;
50+
+ }
51+
52+
- if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID)))
53+
+ if ((attrib = PKCS12_SAFEBAG_get0_attr(bag, NID_localKeyID))) {
54+
+ if (attrib->type != V_ASN1_OCTET_STRING)
55+
+ return 0;
56+
lkid = attrib->value.octet_string;
57+
+ }
58+
59+
switch (PKCS12_SAFEBAG_get_nid(bag)) {
60+
case NID_keyBag:
61+
diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c
62+
index 289db06..3f5acae 100644
63+
--- a/crypto/pkcs7/pk7_doit.c
64+
+++ b/crypto/pkcs7/pk7_doit.c
65+
@@ -1099,6 +1099,8 @@ ASN1_OCTET_STRING *PKCS7_digest_from_attributes(STACK_OF(X509_ATTRIBUTE) *sk)
66+
ASN1_TYPE *astype;
67+
if ((astype = get_attribute(sk, NID_pkcs9_messageDigest)) == NULL)
68+
return NULL;
69+
+ if (astype->type != V_ASN1_OCTET_STRING)
70+
+ return NULL;
71+
return astype->value.octet_string;
72+
}
73+
74+
--
75+
2.45.4
76+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
From 52d23c86a54adab5ee9f80e48b242b52c4cc2347 Mon Sep 17 00:00:00 2001
2+
From: Norbert Pocs <norbertp@openssl.org>
3+
Date: Thu, 8 Jan 2026 15:04:54 +0100
4+
Subject: [PATCH] Fix OCB AES-NI/HW stream path unauthenticated/unencrypted
5+
trailing bytes
6+
MIME-Version: 1.0
7+
Content-Type: text/plain; charset=UTF-8
8+
Content-Transfer-Encoding: 8bit
9+
10+
When ctx->stream (e.g., AES‑NI or ARMv8 CE) is available, the fast path
11+
encrypts/decrypts full blocks but does not advance in/out pointers. The
12+
tail-handling code then operates on the base pointers, effectively reprocessing
13+
the beginning of the buffer while leaving the actual trailing bytes
14+
unencrypted (encryption) or using the wrong plaintext (decryption). The
15+
authentication checksum excludes the true tail.
16+
17+
CVE-2025-69418
18+
19+
Fixes: https://github.com/openssl/srt/issues/58
20+
21+
Signed-off-by: Norbert Pocs <norbertp@openssl.org>
22+
23+
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
24+
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
25+
Reviewed-by: Tomas Mraz <tomas@openssl.org>
26+
MergeDate: Mon Jan 26 19:48:35 2026
27+
(cherry picked from commit be9375d5d45dfaf897b56ef148a0b58402491fcb)
28+
29+
Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com>
30+
---
31+
crypto/modes/ocb128.c | 10 ++++++++--
32+
1 file changed, 8 insertions(+), 2 deletions(-)
33+
34+
diff --git a/crypto/modes/ocb128.c b/crypto/modes/ocb128.c
35+
index b39a55a..2ef3982 100644
36+
--- a/crypto/modes/ocb128.c
37+
+++ b/crypto/modes/ocb128.c
38+
@@ -342,7 +342,7 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx,
39+
40+
if (num_blocks && all_num_blocks == (size_t)all_num_blocks
41+
&& ctx->stream != NULL) {
42+
- size_t max_idx = 0, top = (size_t)all_num_blocks;
43+
+ size_t max_idx = 0, top = (size_t)all_num_blocks, processed_bytes = 0;
44+
45+
/*
46+
* See how many L_{i} entries we need to process data at hand
47+
@@ -356,6 +356,9 @@ int CRYPTO_ocb128_encrypt(OCB128_CONTEXT *ctx,
48+
ctx->stream(in, out, num_blocks, ctx->keyenc,
49+
(size_t)ctx->sess.blocks_processed + 1, ctx->sess.offset.c,
50+
(const unsigned char (*)[16])ctx->l, ctx->sess.checksum.c);
51+
+ processed_bytes = num_blocks * 16;
52+
+ in += processed_bytes;
53+
+ out += processed_bytes;
54+
} else {
55+
/* Loop through all full blocks to be encrypted */
56+
for (i = ctx->sess.blocks_processed + 1; i <= all_num_blocks; i++) {
57+
@@ -434,7 +437,7 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx,
58+
59+
if (num_blocks && all_num_blocks == (size_t)all_num_blocks
60+
&& ctx->stream != NULL) {
61+
- size_t max_idx = 0, top = (size_t)all_num_blocks;
62+
+ size_t max_idx = 0, top = (size_t)all_num_blocks, processed_bytes = 0;
63+
64+
/*
65+
* See how many L_{i} entries we need to process data at hand
66+
@@ -448,6 +451,9 @@ int CRYPTO_ocb128_decrypt(OCB128_CONTEXT *ctx,
67+
ctx->stream(in, out, num_blocks, ctx->keydec,
68+
(size_t)ctx->sess.blocks_processed + 1, ctx->sess.offset.c,
69+
(const unsigned char (*)[16])ctx->l, ctx->sess.checksum.c);
70+
+ processed_bytes = num_blocks * 16;
71+
+ in += processed_bytes;
72+
+ out += processed_bytes;
73+
} else {
74+
OCB_BLOCK tmp;
75+
76+
--
77+
2.45.4
78+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
From 475c466ef2fbd8fc1df6fae1c3eed9c813fc8ff6 Mon Sep 17 00:00:00 2001
2+
From: Neil Horman <nhorman@openssl.org>
3+
Date: Wed, 7 Jan 2026 11:52:09 -0500
4+
Subject: [PATCH] Fix heap buffer overflow in BIO_f_linebuffer
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
9+
When a FIO_f_linebuffer is part of a bio chain, and the next BIO
10+
preforms short writes, the remainder of the unwritten buffer is copied
11+
unconditionally to the internal buffer ctx->obuf, which may not be
12+
sufficiently sized to handle the remaining data, resulting in a buffer
13+
overflow.
14+
15+
Fix it by only copying data when ctx->obuf has space, flushing to the
16+
next BIO to increase available storage if needed.
17+
18+
Fixes openssl/srt#48
19+
20+
Fixes CVE-2025-68160
21+
22+
Reviewed-by: Nikola Pajkovsky <nikolap@openssl.org>
23+
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
24+
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
25+
Reviewed-by: Tomas Mraz <tomas@openssl.org>
26+
MergeDate: Mon Jan 26 19:41:40 2026
27+
(cherry picked from commit b21663c35a6f0ed4c8de06855bdc7a6a21f00c2f)
28+
29+
Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com>
30+
---
31+
crypto/bio/bf_lbuf.c | 32 ++++++++++++++++++++++++++------
32+
1 file changed, 26 insertions(+), 6 deletions(-)
33+
34+
diff --git a/crypto/bio/bf_lbuf.c b/crypto/bio/bf_lbuf.c
35+
index 72f9901..34dd035 100644
36+
--- a/crypto/bio/bf_lbuf.c
37+
+++ b/crypto/bio/bf_lbuf.c
38+
@@ -191,14 +191,34 @@ static int linebuffer_write(BIO *b, const char *in, int inl)
39+
while (foundnl && inl > 0);
40+
/*
41+
* We've written as much as we can. The rest of the input buffer, if
42+
- * any, is text that doesn't and with a NL and therefore needs to be
43+
- * saved for the next trip.
44+
+ * any, is text that doesn't end with a NL and therefore we need to try
45+
+ * free up some space in our obuf so we can make forward progress.
46+
*/
47+
- if (inl > 0) {
48+
- memcpy(&(ctx->obuf[ctx->obuf_len]), in, inl);
49+
- ctx->obuf_len += inl;
50+
- num += inl;
51+
+ while (inl > 0) {
52+
+ size_t avail = (size_t)ctx->obuf_size - (size_t)ctx->obuf_len;
53+
+ size_t to_copy;
54+
+
55+
+ if (avail == 0) {
56+
+ /* Flush buffered data to make room */
57+
+ i = BIO_write(b->next_bio, ctx->obuf, ctx->obuf_len);
58+
+ if (i <= 0) {
59+
+ BIO_copy_next_retry(b);
60+
+ return num > 0 ? num : i;
61+
+ }
62+
+ if (i < ctx->obuf_len)
63+
+ memmove(ctx->obuf, ctx->obuf + i, ctx->obuf_len - i);
64+
+ ctx->obuf_len -= i;
65+
+ continue;
66+
+ }
67+
+
68+
+ to_copy = inl > (int)avail ? avail : (size_t)inl;
69+
+ memcpy(&(ctx->obuf[ctx->obuf_len]), in, to_copy);
70+
+ ctx->obuf_len += (int)to_copy;
71+
+ in += to_copy;
72+
+ inl -= (int)to_copy;
73+
+ num += (int)to_copy;
74+
}
75+
+
76+
return num;
77+
}
78+
79+
--
80+
2.45.4
81+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From 4e254b48ad93cc092be3dd62d97015f33f73133a Mon Sep 17 00:00:00 2001
2+
From: Bob Beck <beck@openssl.org>
3+
Date: Wed, 7 Jan 2026 11:29:48 -0700
4+
Subject: [PATCH] Verify ASN1 object's types before attempting to access them
5+
as a particular type
6+
MIME-Version: 1.0
7+
Content-Type: text/plain; charset=UTF-8
8+
Content-Transfer-Encoding: 8bit
9+
10+
Issue was reported in ossl_ess_get_signing_cert but is also present in
11+
ossl_ess_get_signing_cert_v2.
12+
13+
Fixes: https://github.com/openssl/srt/issues/61
14+
Fixes CVE-2025-69420
15+
16+
Reviewed-by: Norbert Pocs <norbertp@openssl.org>
17+
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
18+
Reviewed-by: Tomas Mraz <tomas@openssl.org>
19+
MergeDate: Mon Jan 26 19:53:36 2026
20+
(cherry picked from commit ea8fc4c345fbd749048809c9f7c881ea656b0b94)
21+
22+
Signed-off-by: Kanishk Bansal <kanbansal@microsoft.com>
23+
---
24+
crypto/ts/ts_rsp_verify.c | 4 ++--
25+
1 file changed, 2 insertions(+), 2 deletions(-)
26+
27+
diff --git a/crypto/ts/ts_rsp_verify.c b/crypto/ts/ts_rsp_verify.c
28+
index c2e7abd..156958c 100644
29+
--- a/crypto/ts/ts_rsp_verify.c
30+
+++ b/crypto/ts/ts_rsp_verify.c
31+
@@ -262,7 +262,7 @@ static ESS_SIGNING_CERT *ess_get_signing_cert(PKCS7_SIGNER_INFO *si)
32+
ASN1_TYPE *attr;
33+
const unsigned char *p;
34+
attr = PKCS7_get_signed_attribute(si, NID_id_smime_aa_signingCertificate);
35+
- if (!attr)
36+
+ if (attr == NULL || attr->type != V_ASN1_SEQUENCE)
37+
return NULL;
38+
p = attr->value.sequence->data;
39+
return d2i_ESS_SIGNING_CERT(NULL, &p, attr->value.sequence->length);
40+
@@ -274,7 +274,7 @@ static ESS_SIGNING_CERT_V2 *ess_get_signing_cert_v2(PKCS7_SIGNER_INFO *si)
41+
const unsigned char *p;
42+
43+
attr = PKCS7_get_signed_attribute(si, NID_id_smime_aa_signingCertificateV2);
44+
- if (attr == NULL)
45+
+ if (attr == NULL || attr->type != V_ASN1_SEQUENCE)
46+
return NULL;
47+
p = attr->value.sequence->data;
48+
return d2i_ESS_SIGNING_CERT_V2(NULL, &p, attr->value.sequence->length);
49+
--
50+
2.45.4
51+

SPECS/openssl/openssl.spec

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Summary: Utilities from the general purpose cryptography library with TLS implementation
55
Name: openssl
66
Version: 1.1.1k
7-
Release: 37%{?dist}
7+
Release: 38%{?dist}
88
License: OpenSSL
99
Vendor: Microsoft Corporation
1010
Distribution: Mariner
@@ -67,6 +67,11 @@ Patch43: openssl-1.1.1-jitterentropy-fix-intermittent-fips-selftest-failu
6767
Patch44: CVE-2024-5535.patch
6868
Patch45: openssl-1.1.1-Fix-timing-side-channel-in-ECDSA-signature-computation.patch
6969
Patch46: openssl-1.1.1-fix-incorrect-check-of-unwrapped-key-size.patch
70+
Patch47: openssl-1.1.1-ensure-ASN1-types-are-checked-before-use.patch
71+
Patch48: openssl-1.1.1-fix-heap-buffer-overflow-in-BIO_f_linebuffer.patch
72+
Patch49: openssl-1.1.1-fix-OCB-AES-NI-HW-stream-path-unauthenticated-unencrypted.patch
73+
Patch50: openssl-1.1.1-check-return-code-of-UTF8_putc.patch
74+
Patch51: openssl-1.1.1-verify-ASN1-objects-types.patch
7075

7176
BuildRequires: perl-Test-Warnings
7277
BuildRequires: perl-Text-Template
@@ -157,7 +162,6 @@ export HASHBANGPERL=%{_bindir}/perl
157162
# RPM_OPT_FLAGS, so we can skip specifiying them here.
158163

159164
# See https://wiki.openssl.org/index.php/Compilation_and_Installation for configure options
160-
161165
# NOTE: the 'no-<prot>-method' switches are not used by design. The changes inside 'Patch2'
162166
# make sure that protocols disabled through 'no-<prot>' will still be unaccessible.
163167
# This is a workaround until OpenSSL issue #7048 is officially resolved.
@@ -331,6 +335,13 @@ rm -f %{buildroot}%{_sysconfdir}/pki/tls/ct_log_list.cnf.dist
331335
%postun libs -p /sbin/ldconfig
332336

333337
%changelog
338+
* Fri Feb 20 2026 Kanishk Bansal <kanbansal@microsoft.com> - 1.1.1k-38
339+
- Ensure ASN1 types are checked before use in s_client, PKCS12, and PKCS7
340+
- Fix heap buffer overflow in BIO_f_linebuffer on short writes
341+
- Fix OCB AES-NI HW stream path leaving bytes unauthenticated and unencrypted
342+
- Check return code of UTF8_putc to handle encoding errors
343+
- Verify ASN1 object types before access in ESS and timestamp verification
344+
334345
* Thu Nov 06 2025 Lynsey Rydberg <lyrydber@microsoft.com> - 1.1.1k-37
335346
- Fix incorrect check of unwrapped key size
336347

0 commit comments

Comments
 (0)