Skip to content

Create thunks for d2i/i2d functions in crypto/asn1/a_d2i_fp.c crypto/asn1/a_i2d_fp.c and crypto/pem/pem_lib.c - #31641

Closed
nhorman wants to merge 17 commits into
openssl:masterfrom
nhorman:pr1972
Closed

nhorman wants to merge 17 commits into
openssl:masterfrom
nhorman:pr1972

Conversation

@nhorman

@nhorman nhorman commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

To mitigate some of the ubsan errors in our build we need to create lots of thunking functions, which preform casts to the needed type in the relevant callbacks.

This PR addresses functions revealing such errors in a_d2i_fp.c a_i2d_fp.c and pem_lib.c.

Note: While some of these fixes cover errors in functions above and beyond these files (as it convenient to handle some cases in the macros that implement the functions), there are other potential errors lurking in these files, that aren't reported because they aren't executed during our unit tests.

I've opted to not fix those in this PR as they would likely benefit from having tests added to trigger said ubsan warnings. As such I think it would be better to keep this PR small, and handle those issues independently.

@nhorman nhorman self-assigned this Jun 22, 2026
@nhorman nhorman added branch: master Applies to master branch approval: review pending This pull request needs review by a committer labels Jun 22, 2026
@nhorman nhorman linked an issue Jun 22, 2026 that may be closed by this pull request
@nhorman
nhorman marked this pull request as draft June 22, 2026 17:20
@github-actions github-actions Bot added severity: fips change The pull request changes FIPS provider sources severity: ABI change This pull request contains ABI changes labels Jun 22, 2026
@nhorman
nhorman force-pushed the pr1972 branch 2 times, most recently from 317aab4 to feb7d14 Compare June 22, 2026 19:51
@nhorman nhorman added the no_news_changes_needed skip checks for the recommendation to add NEWS.md/CHANGES.md entries label Jun 22, 2026
@nhorman
nhorman marked this pull request as ready for review June 22, 2026 21:24
Comment thread include/openssl/pem.h Resolved
Comment thread crypto/pem/pem_all.c Resolved
Comment thread doc/man3/d2i_X509.pod Resolved
Comment thread crypto/pem/pem_info.c Resolved
nhorman added 9 commits June 25, 2026 10:30
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
create shim functions to cast our void pointers to the proper type so as
to avoid undefined behavior warnings
nhorman added 3 commits June 25, 2026 16:33
Note, implementing thunking in the PEM_conversion macros creates
thunking functions that are statically defined, and unreachable from
public apis.

As such, [d2i|i2d]_ECPKParameters_fp, which were formerly macros can't
use those thunking functions unless they are promoted to full functions,
where the implementation is co-located with the thunking function
defintion.  Make that change here.
@nhorman

nhorman commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

ok, I've rebased this on top of master, now that #31523 has merged, eliminated redundant commits and fixed up what remains. This PR now eliminates ubsan errors in the following functions:

d2i_DSAPrivateKey
d2i_ECPKParameters
d2i_ECPrivateKey
d2i_TS_REQ
d2i_TS_RESP
i2d_DHparams
i2d_ECPKParameters
i2d_KeyParams
i2d_OSSL_CMP_MSG
i2d_PKCS7
i2d_PKCS8_PRIV_KEY_INFO
i2d_PrivateKey
i2d_SSL_SESSION
i2d_TS_REQ
i2d_TS_RESP
i2d_TS_TST_INFO
i2d_X509
i2d_X509_AUX
i2d_X509_CRL
i2d_X509_PUBKEY
i2d_X509_REQ
i2d_X509_SIG

Which were the ones remaining as present in a_d2i_fp.c a_i2d_fp.c and pem_lib.c

Comment thread crypto/pem/pem_all.c Resolved
Comment thread doc/man3/d2i_X509.pod Resolved
Comment thread doc/man3/d2i_X509.pod Resolved
@nhorman
nhorman requested a review from andrewkdinh June 26, 2026 14:17
Comment thread crypto/cmp/cmp_msg.c Resolved
Comment thread crypto/ts/ts_asn1.c Resolved
Comment thread crypto/ts/ts_asn1.c Resolved
Comment thread crypto/ts/ts_asn1.c Resolved
Comment thread crypto/ts/ts_asn1.c Resolved
Comment thread crypto/ts/ts_asn1.c Resolved
Comment thread crypto/ts/ts_asn1.c Resolved
Comment thread include/openssl/pem.h Resolved
@nhorman
nhorman requested a review from npajkovsky July 1, 2026 19:58
@openssl-machine openssl-machine added approval: done This pull request has the required number of approvals approval: ready to merge The 24 hour grace period has passed, ready to merge and removed approval: review pending This pull request needs review by a committer approval: done This pull request has the required number of approvals labels Jul 2, 2026
@openssl-machine

Copy link
Copy Markdown
Collaborator

This pull request is ready to merge

@paulidale

Copy link
Copy Markdown
Contributor

With the other PR to turn off errors for these, I suggest that this not be merged.

@paulidale paulidale added the hold: discussion The community needs to establish a consensus how to move forward with the issue or PR label Jul 5, 2026
@nhorman

nhorman commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

closing this as we've decided to suppress these ubsan errors with a compiler flag

@nhorman nhorman closed this Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approval: ready to merge The 24 hour grace period has passed, ready to merge branch: master Applies to master branch hold: discussion The community needs to establish a consensus how to move forward with the issue or PR no_news_changes_needed skip checks for the recommendation to add NEWS.md/CHANGES.md entries severity: ABI change This pull request contains ABI changes severity: fips change The pull request changes FIPS provider sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ASN.1 d2i_of_void / i2d_of_void casts

6 participants