Repository navigation
Fix various function pointer UBSAN - #31523
npajkovsky wants to merge 8 commits into
Conversation
call OPENSSL_sk_set_thunks for sk_${nametype}_new and
sk_${nametype}_new_reserve, and wrap the long generated stack
constructor and deep-copy macros across multiple lines so the nested
thunk setup is easier to read and maintain.
Signed-off-by: Nikola Pajkovsky <[email protected]>
ensure typed stack duplicates keep their compare, copy, and free thunks so later operations do not call typed callbacks through erased void * function pointer signatures. Signed-off-by: Nikola Pajkovsky <[email protected]>
d2i_OCSP_REQUEST/d2i_OCSP_RESPONSE are declared with type-specific
signatures returning OCSP_REQUEST*/OCSP_RESPONSE*, but the
d2i_OCSP_{REQUEST,RESPONSE}_bio macros routed them through
ASN1_d2i_bio_of -> ASN1_d2i_bio, which calls them via a
d2i_of_void* pointer:
void *(*)(void **, const unsigned char **, long)
The analogous i2d_OCSP_{REQUEST,RESPONSE}_bio macros did the same
through ASN1_i2d_bio_of -> ASN1_i2d_bio with i2d_of_void*.
Rewrite the macros to dispatch through
ASN1_item_d2i_bio/ASN1_item_i2d_bio with ASN1_ITEM_rptr(OCSP_*)
directly. This eliminates the function-pointer cast entirely; both old
and new paths bottom out in the same ASN1_item_d2i_ex / ASN1_item_i2d
call, so behavior is identical.
Signed-off-by: Nikola Pajkovsky <[email protected]>
PEM_X509_INFO_read_bio_ex stored d2i_X509, d2i_X509_AUX, d2i_X509_CRL
or d2i_AutoPrivateKey -- each with a distinct, type-specific signature
returning X509*, X509_CRL* or EVP_PKEY* -- in a single d2i_of_void*
variable and dispatched through it:
d2i = (D2I_OF(void))d2i_X509;
...
d2i(pp, &p, len)
Replace the function-pointer dispatch with an enum tag
(pem_info_type) and a switch that calls each typed d2i_* directly
with the correctly type.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Signed-off-by: Nikola Pajkovsky <[email protected]>
decode PEM payloads through the generated typed d2i_* functions in the PEM read macros instead of routing them through the d2i_of_void callback path. This avoids UBSan function type mismatch reports while preserving the public PEM reader APIs. Signed-off-by: Nikola Pajkovsky <[email protected]>
use IMPLEMENT_ASN1_DUP_FUNCTION(GENERAL_NAME) so duplication goes through ASN1_item_dup() instead of calling ASN1_dup() with cast i2d/d2i function pointers. This avoids UBSan function type errors while preserving the public GENERAL_NAME_dup() API. Signed-off-by: Nikola Pajkovsky <[email protected]>
the d2i_*/i2d_* fp and bio wrappers for RSA_PUBKEY, the DSA and EC key
types, and the EVP_PKEY Private/PUBKEY converters passed their
type-specific functions to ASN1_{d2i,i2d}_{fp,bio}, which invoke them
through the generic d2i_of_void / i2d_of_void / void *(*)(void) pointer
types.
Add file-local thunks with the exact generic signatures that forward to
the concrete functions, and pass those instead of cast pointers. This
removes the mismatched calls while keeping the public API unchanged.
Signed-off-by: Nikola Pajkovsky <[email protected]>
|
So have we decided between this PR and Neil's PR also thunking? @nhorman ? |
|
I'm honestly not sure, as I don't know which issues in the thinking epic this pr covers and what (if anything) is unique in mine. |
|
The external test fail looks related to this PR. |
mbroz
left a comment
There was a problem hiding this comment.
If external test is unrelated, LGTM.
@nikolapajkovsky ok, that explains it, thank you for clarifying, though I ran this pr under ubsan, and all the errors fixed in #31641 still seem to be present, so I'm wondering how much overlap there actually is here. |
@mbroz I think that external test error happens because this PR was branched prior to several fixes that went in to address various pkcs11 errors. I imagine a rebase of this PR to the head of master will resolve them. |
That would be the preferred way to continue. Thank you. |
I can do a rebase for sure. However, we already know that pkcs#11 is fixed on master, and the error is not related to this PR. If you want to have a clean CI before merge, just shout out loud. |
|
24 hours has passed since 'approval: done' was set, but as this PR has been updated in that time the label 'approval: ready to merge' is not being automatically set. Please review the updates and set the label manually. |
|
merged to master, thank you |
call OPENSSL_sk_set_thunks for sk_${nametype}_new and
sk_${nametype}_new_reserve, and wrap the long generated stack
constructor and deep-copy macros across multiple lines so the nested
thunk setup is easier to read and maintain.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:46 2026
(Merged from #31523)
ensure typed stack duplicates keep their compare, copy, and free thunks so later operations do not call typed callbacks through erased void * function pointer signatures. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:48 2026 (Merged from #31523)
d2i_OCSP_REQUEST/d2i_OCSP_RESPONSE are declared with type-specific
signatures returning OCSP_REQUEST*/OCSP_RESPONSE*, but the
d2i_OCSP_{REQUEST,RESPONSE}_bio macros routed them through
ASN1_d2i_bio_of -> ASN1_d2i_bio, which calls them via a
d2i_of_void* pointer:
void *(*)(void **, const unsigned char **, long)
The analogous i2d_OCSP_{REQUEST,RESPONSE}_bio macros did the same
through ASN1_i2d_bio_of -> ASN1_i2d_bio with i2d_of_void*.
Rewrite the macros to dispatch through
ASN1_item_d2i_bio/ASN1_item_i2d_bio with ASN1_ITEM_rptr(OCSP_*)
directly. This eliminates the function-pointer cast entirely; both old
and new paths bottom out in the same ASN1_item_d2i_ex / ASN1_item_i2d
call, so behavior is identical.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:50 2026
(Merged from #31523)
PEM_X509_INFO_read_bio_ex stored d2i_X509, d2i_X509_AUX, d2i_X509_CRL
or d2i_AutoPrivateKey -- each with a distinct, type-specific signature
returning X509*, X509_CRL* or EVP_PKEY* -- in a single d2i_of_void*
variable and dispatched through it:
d2i = (D2I_OF(void))d2i_X509;
...
d2i(pp, &p, len)
Replace the function-pointer dispatch with an enum tag
(pem_info_type) and a switch that calls each typed d2i_* directly
with the correctly type.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:53 2026
(Merged from #31523)
Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:55 2026 (Merged from #31523)
decode PEM payloads through the generated typed d2i_* functions in the PEM read macros instead of routing them through the d2i_of_void callback path. This avoids UBSan function type mismatch reports while preserving the public PEM reader APIs. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:57 2026 (Merged from #31523)
use IMPLEMENT_ASN1_DUP_FUNCTION(GENERAL_NAME) so duplication goes through ASN1_item_dup() instead of calling ASN1_dup() with cast i2d/d2i function pointers. This avoids UBSan function type errors while preserving the public GENERAL_NAME_dup() API. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:59 2026 (Merged from #31523)
the d2i_*/i2d_* fp and bio wrappers for RSA_PUBKEY, the DSA and EC key
types, and the EVP_PKEY Private/PUBKEY converters passed their
type-specific functions to ASN1_{d2i,i2d}_{fp,bio}, which invoke them
through the generic d2i_of_void / i2d_of_void / void *(*)(void) pointer
types.
Add file-local thunks with the exact generic signatures that forward to
the concrete functions, and pass those instead of cast pointers. This
removes the mismatched calls while keeping the public API unchanged.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:13:01 2026
(Merged from #31523)
call OPENSSL_sk_set_thunks for sk_${nametype}_new and
sk_${nametype}_new_reserve, and wrap the long generated stack
constructor and deep-copy macros across multiple lines so the nested
thunk setup is easier to read and maintain.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:46 2026
(Merged from openssl#31523)
ensure typed stack duplicates keep their compare, copy, and free thunks so later operations do not call typed callbacks through erased void * function pointer signatures. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:48 2026 (Merged from openssl#31523)
d2i_OCSP_REQUEST/d2i_OCSP_RESPONSE are declared with type-specific
signatures returning OCSP_REQUEST*/OCSP_RESPONSE*, but the
d2i_OCSP_{REQUEST,RESPONSE}_bio macros routed them through
ASN1_d2i_bio_of -> ASN1_d2i_bio, which calls them via a
d2i_of_void* pointer:
void *(*)(void **, const unsigned char **, long)
The analogous i2d_OCSP_{REQUEST,RESPONSE}_bio macros did the same
through ASN1_i2d_bio_of -> ASN1_i2d_bio with i2d_of_void*.
Rewrite the macros to dispatch through
ASN1_item_d2i_bio/ASN1_item_i2d_bio with ASN1_ITEM_rptr(OCSP_*)
directly. This eliminates the function-pointer cast entirely; both old
and new paths bottom out in the same ASN1_item_d2i_ex / ASN1_item_i2d
call, so behavior is identical.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:50 2026
(Merged from openssl#31523)
PEM_X509_INFO_read_bio_ex stored d2i_X509, d2i_X509_AUX, d2i_X509_CRL
or d2i_AutoPrivateKey -- each with a distinct, type-specific signature
returning X509*, X509_CRL* or EVP_PKEY* -- in a single d2i_of_void*
variable and dispatched through it:
d2i = (D2I_OF(void))d2i_X509;
...
d2i(pp, &p, len)
Replace the function-pointer dispatch with an enum tag
(pem_info_type) and a switch that calls each typed d2i_* directly
with the correctly type.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:53 2026
(Merged from openssl#31523)
Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:55 2026 (Merged from openssl#31523)
decode PEM payloads through the generated typed d2i_* functions in the PEM read macros instead of routing them through the d2i_of_void callback path. This avoids UBSan function type mismatch reports while preserving the public PEM reader APIs. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:57 2026 (Merged from openssl#31523)
use IMPLEMENT_ASN1_DUP_FUNCTION(GENERAL_NAME) so duplication goes through ASN1_item_dup() instead of calling ASN1_dup() with cast i2d/d2i function pointers. This avoids UBSan function type errors while preserving the public GENERAL_NAME_dup() API. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:59 2026 (Merged from openssl#31523)
the d2i_*/i2d_* fp and bio wrappers for RSA_PUBKEY, the DSA and EC key
types, and the EVP_PKEY Private/PUBKEY converters passed their
type-specific functions to ASN1_{d2i,i2d}_{fp,bio}, which invoke them
through the generic d2i_of_void / i2d_of_void / void *(*)(void) pointer
types.
Add file-local thunks with the exact generic signatures that forward to
the concrete functions, and pass those instead of cast pointers. This
removes the mismatched calls while keeping the public API unchanged.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:13:01 2026
(Merged from openssl#31523)
call OPENSSL_sk_set_thunks for sk_${nametype}_new and
sk_${nametype}_new_reserve, and wrap the long generated stack
constructor and deep-copy macros across multiple lines so the nested
thunk setup is easier to read and maintain.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:46 2026
(Merged from openssl#31523)
ensure typed stack duplicates keep their compare, copy, and free thunks so later operations do not call typed callbacks through erased void * function pointer signatures. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:48 2026 (Merged from openssl#31523)
d2i_OCSP_REQUEST/d2i_OCSP_RESPONSE are declared with type-specific
signatures returning OCSP_REQUEST*/OCSP_RESPONSE*, but the
d2i_OCSP_{REQUEST,RESPONSE}_bio macros routed them through
ASN1_d2i_bio_of -> ASN1_d2i_bio, which calls them via a
d2i_of_void* pointer:
void *(*)(void **, const unsigned char **, long)
The analogous i2d_OCSP_{REQUEST,RESPONSE}_bio macros did the same
through ASN1_i2d_bio_of -> ASN1_i2d_bio with i2d_of_void*.
Rewrite the macros to dispatch through
ASN1_item_d2i_bio/ASN1_item_i2d_bio with ASN1_ITEM_rptr(OCSP_*)
directly. This eliminates the function-pointer cast entirely; both old
and new paths bottom out in the same ASN1_item_d2i_ex / ASN1_item_i2d
call, so behavior is identical.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:50 2026
(Merged from openssl#31523)
PEM_X509_INFO_read_bio_ex stored d2i_X509, d2i_X509_AUX, d2i_X509_CRL
or d2i_AutoPrivateKey -- each with a distinct, type-specific signature
returning X509*, X509_CRL* or EVP_PKEY* -- in a single d2i_of_void*
variable and dispatched through it:
d2i = (D2I_OF(void))d2i_X509;
...
d2i(pp, &p, len)
Replace the function-pointer dispatch with an enum tag
(pem_info_type) and a switch that calls each typed d2i_* directly
with the correctly type.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:12:53 2026
(Merged from openssl#31523)
Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:55 2026 (Merged from openssl#31523)
decode PEM payloads through the generated typed d2i_* functions in the PEM read macros instead of routing them through the d2i_of_void callback path. This avoids UBSan function type mismatch reports while preserving the public PEM reader APIs. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:57 2026 (Merged from openssl#31523)
use IMPLEMENT_ASN1_DUP_FUNCTION(GENERAL_NAME) so duplication goes through ASN1_item_dup() instead of calling ASN1_dup() with cast i2d/d2i function pointers. This avoids UBSan function type errors while preserving the public GENERAL_NAME_dup() API. Signed-off-by: Nikola Pajkovsky <[email protected]> Reviewed-by: Neil Horman <[email protected]> Reviewed-by: Milan Broz <[email protected]> MergeDate: Thu Jun 25 12:12:59 2026 (Merged from openssl#31523)
the d2i_*/i2d_* fp and bio wrappers for RSA_PUBKEY, the DSA and EC key
types, and the EVP_PKEY Private/PUBKEY converters passed their
type-specific functions to ASN1_{d2i,i2d}_{fp,bio}, which invoke them
through the generic d2i_of_void / i2d_of_void / void *(*)(void) pointer
types.
Add file-local thunks with the exact generic signatures that forward to
the concrete functions, and pass those instead of cast pointers. This
removes the mismatched calls while keeping the public API unchanged.
Signed-off-by: Nikola Pajkovsky <[email protected]>
Reviewed-by: Neil Horman <[email protected]>
Reviewed-by: Milan Broz <[email protected]>
MergeDate: Thu Jun 25 12:13:01 2026
(Merged from openssl#31523)
This PR contains a bunch of UBSANs in various places. All of them are issues with casting function pointers.
Read it commit by commit; every ubsan is explained, and self-contained.