Skip to content

Commit 1dd43e0

Browse files
mattcaswellt8m
authored andcommitted
Ensure that EXFLAG_INVALID_POLICY is checked even in leaf certs
Even though we check the leaf cert to confirm it is valid, we later ignored the invalid flag and did not notice that the leaf cert was bad. Fixes: CVE-2023-0465 Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from #20587)
1 parent d2f0d05 commit 1dd43e0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

crypto/x509/x509_vfy.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -1654,15 +1654,23 @@ static int check_policy(X509_STORE_CTX *ctx)
16541654
goto memerr;
16551655
/* Invalid or inconsistent extensions */
16561656
if (ret == X509_PCY_TREE_INVALID) {
1657-
int i;
1657+
int i, cbcalled = 0;
16581658

16591659
/* Locate certificates with bad extensions and notify callback. */
1660-
for (i = 1; i < sk_X509_num(ctx->chain); i++) {
1660+
for (i = 0; i < sk_X509_num(ctx->chain); i++) {
16611661
X509 *x = sk_X509_value(ctx->chain, i);
16621662

1663+
if ((x->ex_flags & EXFLAG_INVALID_POLICY) != 0)
1664+
cbcalled = 1;
16631665
CB_FAIL_IF((x->ex_flags & EXFLAG_INVALID_POLICY) != 0,
16641666
ctx, x, i, X509_V_ERR_INVALID_POLICY_EXTENSION);
16651667
}
1668+
if (!cbcalled) {
1669+
/* Should not be able to get here */
1670+
ERR_raise(ERR_LIB_X509, ERR_R_INTERNAL_ERROR);
1671+
return 0;
1672+
}
1673+
/* The callback ignored the error so we return success */
16661674
return 1;
16671675
}
16681676
if (ret == X509_PCY_TREE_FAILURE) {

0 commit comments

Comments
 (0)