]> git.ipfire.org Git - thirdparty/openssl.git/commit
Fix potential use-after-free in REF_PRINT_COUNT
authorNeil Horman <nhorman@openssl.org>
Wed, 16 Oct 2024 18:34:08 +0000 (14:34 -0400)
committerTomas Mraz <tomas@openssl.org>
Tue, 10 Dec 2024 13:58:51 +0000 (14:58 +0100)
commit7b07bc4c99466b871de7c35312ada18fd5ec4af2
treedc410774cd6d7ab9becf302f2b0daedf1cfa50ba
parent4824e049c7171229335164ca1925c3cddfcab181
Fix potential use-after-free in REF_PRINT_COUNT

We use REF_PRINT_COUNT to dump out the value of various reference
counters in our code

However, we commonly use this macro after an increment or decrement.  On
increment its fine, but on decrement its not, because the macro
dereferences the object holding the counter value, which may be freed by
another thread, as we've given up our ref count to it prior to using the
macro.

The rule is that we can't reference memory for an object once we've
released our reference, so lets fix this by altering REF_PRINT_COUNT to
accept the value returned by CRYPTO_[UP|DOWN]_REF instead.  The
eliminates the need to dereference the memory the object points to an
allows us to use the call after we release our reference count

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25664)

(cherry picked from commit dc10ffc2834e0d2f5ebc1c3e29bd97f1f43a0ead)
22 files changed:
crypto/bio/bio_lib.c
crypto/dh/dh_lib.c
crypto/dsa/dsa_lib.c
crypto/dso/dso_lib.c
crypto/ec/ec_key.c
crypto/ec/ec_mult.c
crypto/ec/ecp_nistp224.c
crypto/ec/ecp_nistp256.c
crypto/ec/ecp_nistp384.c
crypto/ec/ecp_nistp521.c
crypto/ec/ecp_nistz256.c
crypto/ec/ecx_key.c
crypto/evp/p_lib.c
crypto/rsa/rsa_lib.c
crypto/x509/x509_lu.c
crypto/x509/x509_set.c
crypto/x509/x509cset.c
include/internal/refcount.h
ssl/ssl_cert.c
ssl/ssl_cert_comp.c
ssl/ssl_lib.c
ssl/ssl_sess.c