summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2026-08-30 16:56:45 +0000
committertb <>2026-08-30 16:56:45 +0000
commit110827e7304c895649791b7065bcd3e0ffe1eb9a (patch)
tree37bc421e13c51ec5fe901ca7be89db8bd502c3e2
parentc21f3ed15976421f8bfd125da34f3b15fbeb05e7 (diff)
downloadopenbsd-110827e7304c895649791b7065bcd3e0ffe1eb9a.tar.gz
openbsd-110827e7304c895649791b7065bcd3e0ffe1eb9a.tar.bz2
openbsd-110827e7304c895649791b7065bcd3e0ffe1eb9a.zip
PKCS7_stream: avoid out of bounds access
The inner content of SignedData is represented by a PKCS7 object, which PKCS7_stream() assumes to be a plain data object and will thus access its content via an ASN1_OCTET_STRING. This need not be the case after parsing. In fact, the inner content type is essentially arbitrary. If the inner content isn't one of the explicitly supported content types, the fallback (via p7default_tt) will populate the union's d.other with an ASN1_ANY which unravels to ASN1_TYPE_new() deep in the guts of tasn_dec, allocating a 16-byte object on LP64 architectures. In that case, the 16-byte object is interpreted as an 24-byte ASN1_OCTET_STRING and if it isn't NULL, the read+write to os->flags (a long at offset 16) is out of bounds: os->flags | ASN1_STRING_FLAG_NDEF; Add a check that the content is actually id-data before accessing the d.data union member. From Acts1631
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
index 9ade3df552..58e5c88a5e 100644
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: pk7_lib.c,v 1.32 2026/08/30 16:52:56 tb Exp $ */ 1/* $OpenBSD: pk7_lib.c,v 1.33 2026/08/30 16:56:45 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -680,6 +680,10 @@ PKCS7_stream(unsigned char ***boundary, PKCS7 *p7)
680 PKCS7error(PKCS7_R_NO_CONTENT); 680 PKCS7error(PKCS7_R_NO_CONTENT);
681 break; 681 break;
682 } 682 }
683 if (!PKCS7_type_is_data(p7->d.sign->contents)) {
684 PKCS7error(PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
685 break;
686 }
683 os = p7->d.sign->contents->d.data; 687 os = p7->d.sign->contents->d.data;
684 break; 688 break;
685 689