• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From b013765abfa80036dc779dd0e50602c57bb3bf95 Mon Sep 17 00:00:00 2001
2From: Matt Caswell <matt@openssl.org>
3Date: Tue, 7 Mar 2023 16:52:55 +0000
4Subject: [PATCH] Ensure that EXFLAG_INVALID_POLICY is checked even in leaf
5 certs
6
7Even though we check the leaf cert to confirm it is valid, we
8later ignored the invalid flag and did not notice that the leaf
9cert was bad.
10
11Fixes: CVE-2023-0465
12
13Reviewed-by: Hugo Landau <hlandau@openssl.org>
14Reviewed-by: Tomas Mraz <tomas@openssl.org>
15(Merged from https://github.com/openssl/openssl/pull/20588)
16---
17 crypto/x509/x509_vfy.c | 11 +++++++++--
18 1 file changed, 9 insertions(+), 2 deletions(-)
19
20diff --git a/crypto/x509/x509_vfy.c b/crypto/x509/x509_vfy.c
21index 925fbb5412..1dfe4f9f31 100644
22--- a/crypto/x509/x509_vfy.c
23+++ b/crypto/x509/x509_vfy.c
24@@ -1649,18 +1649,25 @@ static int check_policy(X509_STORE_CTX *ctx)
25     }
26     /* Invalid or inconsistent extensions */
27     if (ret == X509_PCY_TREE_INVALID) {
28-        int i;
29+        int i, cbcalled = 0;
30
31         /* Locate certificates with bad extensions and notify callback. */
32-        for (i = 1; i < sk_X509_num(ctx->chain); i++) {
33+        for (i = 0; i < sk_X509_num(ctx->chain); i++) {
34             X509 *x = sk_X509_value(ctx->chain, i);
35
36             if (!(x->ex_flags & EXFLAG_INVALID_POLICY))
37                 continue;
38+            cbcalled = 1;
39             if (!verify_cb_cert(ctx, x, i,
40                                 X509_V_ERR_INVALID_POLICY_EXTENSION))
41                 return 0;
42         }
43+        if (!cbcalled) {
44+            /* Should not be able to get here */
45+            X509err(X509_F_CHECK_POLICY, ERR_R_INTERNAL_ERROR);
46+            return 0;
47+        }
48+        /* The callback ignored the error so we return success */
49         return 1;
50     }
51     if (ret == X509_PCY_TREE_FAILURE) {
52--
532.34.1
54
55