/[smecontribs]/rpms/openssl3/contribs10/0108-CVE-2023-0401-pkcs7-md.patch
ViewVC logotype

Contents of /rpms/openssl3/contribs10/0108-CVE-2023-0401-pkcs7-md.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Wed Jan 31 17:24:53 2024 UTC (9 months, 4 weeks ago) by jpp
Branch: MAIN
CVS Tags: openssl3-3_0_7-5_el7_sme_1, HEAD
Initial import

1 From d3b6dfd70db844c4499bec6ad6601623a565e674 Mon Sep 17 00:00:00 2001
2 From: Tomas Mraz <tomas@openssl.org>
3 Date: Wed, 18 Jan 2023 09:27:53 +0100
4 Subject: [PATCH 15/18] pk7_doit.c: Check return of BIO_set_md() calls
5
6 These calls invoke EVP_DigestInit() which can fail for digests
7 with implicit fetches. Subsequent EVP_DigestUpdate() from BIO_write()
8 or EVP_DigestFinal() from BIO_read() will segfault on NULL
9 dereference. This can be triggered by an attacker providing
10 PKCS7 data digested with MD4 for example if the legacy provider
11 is not loaded.
12
13 If BIO_set_md() fails the md BIO cannot be used.
14
15 CVE-2023-0401
16
17 Reviewed-by: Paul Dale <pauli@openssl.org>
18 Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
19 ---
20 crypto/pkcs7/pk7_doit.c | 12 ++++++++++--
21 1 file changed, 10 insertions(+), 2 deletions(-)
22
23 diff --git a/crypto/pkcs7/pk7_doit.c b/crypto/pkcs7/pk7_doit.c
24 index bde9ac4787..5e562fbea5 100644
25 --- a/crypto/pkcs7/pk7_doit.c
26 +++ b/crypto/pkcs7/pk7_doit.c
27 @@ -84,7 +84,11 @@ static int pkcs7_bio_add_digest(BIO **pbio, X509_ALGOR *alg,
28 }
29 (void)ERR_pop_to_mark();
30
31 - BIO_set_md(btmp, md);
32 + if (BIO_set_md(btmp, md) <= 0) {
33 + ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
34 + EVP_MD_free(fetched);
35 + goto err;
36 + }
37 EVP_MD_free(fetched);
38 if (*pbio == NULL)
39 *pbio = btmp;
40 @@ -522,7 +526,11 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
41 }
42 (void)ERR_pop_to_mark();
43
44 - BIO_set_md(btmp, md);
45 + if (BIO_set_md(btmp, md) <= 0) {
46 + EVP_MD_free(evp_md);
47 + ERR_raise(ERR_LIB_PKCS7, ERR_R_BIO_LIB);
48 + goto err;
49 + }
50 EVP_MD_free(evp_md);
51 if (out == NULL)
52 out = btmp;
53 --
54 2.39.1
55
56 From a0f2359613f50b5ca6b74b78bf4b54d7dc925fd2 Mon Sep 17 00:00:00 2001
57 From: Tomas Mraz <tomas@openssl.org>
58 Date: Wed, 18 Jan 2023 17:07:24 +0100
59 Subject: [PATCH 16/18] Add testcase for missing return check of BIO_set_md()
60 calls
61
62 Reviewed-by: Paul Dale <pauli@openssl.org>
63 Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
64 ---
65 test/recipes/80-test_cms.t | 15 ++++++++--
66 test/recipes/80-test_cms_data/pkcs7-md4.pem | 32 +++++++++++++++++++++
67 2 files changed, 45 insertions(+), 2 deletions(-)
68 create mode 100644 test/recipes/80-test_cms_data/pkcs7-md4.pem
69
70 diff --git a/test/recipes/80-test_cms.t b/test/recipes/80-test_cms.t
71 index fd53683e6b..d45789de70 100644
72 --- a/test/recipes/80-test_cms.t
73 +++ b/test/recipes/80-test_cms.t
74 @@ -13,7 +13,7 @@ use warnings;
75 use POSIX;
76 use File::Spec::Functions qw/catfile/;
77 use File::Compare qw/compare_text compare/;
78 -use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file with/;
79 +use OpenSSL::Test qw/:DEFAULT srctop_dir srctop_file bldtop_dir bldtop_file with data_file/;
80
81 use OpenSSL::Test::Utils;
82
83 @@ -50,7 +50,7 @@ my ($no_des, $no_dh, $no_dsa, $no_ec, $no_ec2m, $no_rc2, $no_zlib)
84
85 $no_rc2 = 1 if disabled("legacy");
86
87 -plan tests => 13;
88 +plan tests => 14;
89
90 ok(run(test(["pkcs7_test"])), "test pkcs7");
91
92 @@ -941,6 +941,17 @@ subtest "CMS binary input tests\n" => sub {
93 "verify binary input with -binary missing -crlfeol");
94 };
95
96 +# Test case for missing MD algorithm (must not segfault)
97 +
98 +with({ exit_checker => sub { return shift == 4; } },
99 + sub {
100 + ok(run(app(['openssl', 'smime', '-verify', '-noverify',
101 + '-inform', 'PEM',
102 + '-in', data_file("pkcs7-md4.pem"),
103 + ])),
104 + "Check failure of EVP_DigestInit is handled correctly");
105 + });
106 +
107 sub check_availability {
108 my $tnam = shift;
109
110 diff --git a/test/recipes/80-test_cms_data/pkcs7-md4.pem b/test/recipes/80-test_cms_data/pkcs7-md4.pem
111 new file mode 100644
112 index 0000000000..ecff611deb
113 --- /dev/null
114 +++ b/test/recipes/80-test_cms_data/pkcs7-md4.pem
115 @@ -0,0 +1,32 @@
116 +-----BEGIN PKCS7-----
117 +MIIFhAYJKoZIhvcNAQcCoIIFdTCCBXECAQExDjAMBggqhkiG9w0CBAUAMB0GCSqG
118 +SIb3DQEHAaAQBA5UZXN0IGNvbnRlbnQNCqCCAyQwggMgMIICCKADAgECAgECMA0G
119 +CSqGSIb3DQEBCwUAMA0xCzAJBgNVBAMMAkNBMCAXDTE2MDExNTA4MTk0OVoYDzIx
120 +MTYwMTE2MDgxOTQ5WjAZMRcwFQYDVQQDDA5zZXJ2ZXIuZXhhbXBsZTCCASIwDQYJ
121 +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAKj/iVhhha7e2ywP1XP74reoG3p1YCvU
122 +fTxzdrWu3pMvfySQbckc9Io4zZ+igBZWy7Qsu5PlFx//DcZD/jE0+CjYdemju4iC
123 +76Ny4lNiBUVN4DGX76qdENJYDZ4GnjK7GwhWXWUPP2aOwjagEf/AWTX9SRzdHEIz
124 +BniuBDgj5ed1Z9OUrVqpQB+sWRD1DMFkrUrExjVTs5ZqghsVi9GZq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DgMCBzANBggqhkiG9w0DAgIBKDANBgkqhkiG9w0B
141 +AQEFAASCAQAe+xlm/TGg/s/7b0xBc3FFnmmUDEe7ljkehIx61OnBV9ZWA+LcBX/7
142 +kmMSMdaHjRq4w8FmwBMLzn0ttXVqf0QuPbBF/E6X5EqK9lpOdkUQhNiN2v+ZfY6c
143 +lrH4ADsSD9D+UHw0sxo5KEF+PPuneUfYCJZosFUJosBbuSEXK0C9yfJoDKVE8Syp
144 +0vdqh73ogLeNgZLAUGSSB66OmHDxwgAj4qPAv6FHFBy1Xs4uFZER5vniYrH9OrAk
145 +Z6XdvzDoYZC4XcGMDtcOpOM6D4owqy5svHPDw8wIlM4GVhrTw7CQmuBz5uRNnf6a
146 +ZK3jZIxG1hr/INaNWheHoPIhPblYaVc6
147 +-----END PKCS7-----
148 --
149 2.39.1
150

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed