]> git.ipfire.org Git - thirdparty/openssl.git/commit
x509: Fix possible use-after-free when OOM
authorClemens Lang <cllang@redhat.com>
Wed, 24 May 2023 10:22:25 +0000 (12:22 +0200)
committerTomas Mraz <tomas@openssl.org>
Mon, 29 May 2023 12:54:54 +0000 (14:54 +0200)
commit34d5cbc76972ed55d6faa357d1a28efc5d49aa2d
treed21af34ddda57f67e924db28ea434ecc2daf2826
parent3afa246520852ba3bfc16c7c976cb3c2064a3baa
x509: Fix possible use-after-free when OOM

ossl_policy_level_add_node() first adds the new node to the level->nodes
stack, and then attempts to add extra data if extra_data is true. If
memory allocation or adding the extra data to tree->extra_data fails,
the allocated node (that has already been added to the level->nodes
stack) is freed using ossl_policy_node_free(), which leads to
a potential use after free.

Additionally, the tree's node count and the parent's child count would
not be updated, despite the new node being added.

Fix this by either performing the function's purpose completely, or not
at all by reverting the changes on error.

Signed-off-by: Clemens Lang <cllang@redhat.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Bernd Edlinger <bernd.edlinger@hotmail.de>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21040)

(cherry picked from commit de53817ec386ea9e943d8f33716945dd9dbe1f31)
crypto/x509/pcy_node.c