openssl/util
Neil Horman 5c42ced0ff Introduce hash thunking functions to do proper casting
ubsan on clang17 has started warning about the following undefined
behavior:

crypto/lhash/lhash.c:299:12: runtime error: call to function err_string_data_hash through pointer to incorrect function type 'unsigned long (*)(const void *)'
[...]/crypto/err/err.c:184: note: err_string_data_hash defined here
    #0 0x7fa569e3a434 in getrn [...]/crypto/lhash/lhash.c:299:12
    #1 0x7fa569e39a46 in OPENSSL_LH_insert [...]/crypto/lhash/lhash.c:119:10
    #2 0x7fa569d866ee in err_load_strings [...]/crypto/err/err.c:280:15
[...]

The issue occurs because, the generic hash functions (OPENSSL_LH_*) will
occasionaly call back to the type specific registered functions for hash
generation/comparison/free/etc, using functions of the (example)
prototype:

[return value] <hash|cmp|free> (void *, [void *], ...)

While the functions implementing hash|cmp|free|etc are defined as
[return value] <fnname> (TYPE *, [TYPE *], ...)

The compiler, not knowing the type signature of the function pointed to
by the implementation, performs no type conversion on the function
arguments

While the C language specification allows for pointers to data of one
type to be converted to pointers of another type, it does not
allow for pointers to functions with one signature to be called
while pointing to functions of another signature.  Compilers often allow
this behavior, but strictly speaking it results in undefined behavior

As such, ubsan warns us about this issue

This is an potential fix for the issue, implemented using, in effect,
thunking macros.  For each hash type, an additional set of wrapper
funtions is created (currently for compare and hash, but more will be
added for free/doall/etc).  The corresponding thunking macros for each
type cases the actuall corresponding callback to a function pointer of
the proper type, and then calls that with the parameters appropriately
cast, avoiding the ubsan warning

This approach is adventageous as it maintains a level of type safety,
but comes at the cost of having to implement several additional
functions per hash table type.

Related to #22896

Reviewed-by: Sasa Nedvedicky <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/23192)
2024-01-17 10:47:04 -05:00
..
perl Introduce hash thunking functions to do proper casting 2024-01-17 10:47:04 -05:00
platform_symbols Create a rudimentary symbol scanning script 2023-11-01 16:32:26 +01:00
add-depends.pl
build.info Disable building quicserver utility when configured with no-apps option 2023-12-29 10:16:46 +01:00
c-compress-test.pl
cavs-to-evptest.pl
check-format-test-negatives.c
check-format-test-positives.c
check-format.pl Copyright year updates 2023-09-07 09:59:15 +01:00
check-malloc-errs
checkplatformsyms.pl Create a rudimentary symbol scanning script 2023-11-01 16:32:26 +01:00
ck_errf.pl
copy.pl
ctags.sh Fix new typos found by codespell 2023-06-18 16:53:09 +10:00
dofile.pl
echo.pl
engines.num
err-to-raise
find-doc-nits Copyright year updates 2023-09-07 09:59:15 +01:00
find-unused-errs
fips-checksums.sh
fix-deprecation
fix-includes
fix-includes.sed
help.pl
indent.pro Removed unused struct ssl3_comp_st 2023-08-29 16:59:54 +02:00
lang-compress.pl
libcrypto.num Introduce hash thunking functions to do proper casting 2024-01-17 10:47:04 -05:00
libssl.num Fix CI breakage due to ABIDIFF failure 2023-11-10 16:38:39 +01:00
markdownlint.rb Adjust mdl configuration 2023-10-24 17:34:07 +01:00
merge-err-lines
missingcrypto111.txt
missingcrypto-internal.txt
missingcrypto.txt Add missing documentation for X509_ATTRIBUTE related functions. 2024-01-03 12:50:54 +01:00
missingmacro111.txt
missingmacro.txt
missingssl111.txt
missingssl-internal.txt
missingssl.txt Add documentation for the function SSL_CONF_CTX_finish. 2023-09-20 10:25:51 +10:00
mk-fipsmodule-cnf.pl Copyright year updates 2023-09-07 09:59:15 +01:00
mkbuildinf.pl
mkdef.pl
mkdir-p.pl
mkerr.pl Copyright year updates 2023-09-07 09:59:15 +01:00
mkinstallvars.pl Add exporters for CMake 2023-11-15 08:22:29 +01:00
mknum.pl
mkpod2html.pl
mkrc.pl
mktar.sh
opensslwrap.sh
other-internal.syms
other.syms Add missing documentation for X509_ATTRIBUTE related functions. 2024-01-03 12:50:54 +01:00
providers.num
quicserver.c QUIC CHANNEL: Consolidate forward object declarations in a single header 2023-12-21 08:11:59 +00:00
shlib_wrap.sh.in
su-filter.pl
update_abi_check.sh Update ci and ABI xml files to validate function parameters 2023-11-15 11:08:17 +01:00
withlibctx.pl
wrap.pl.in
write-man-symlinks