Block cert modification in callbacks based on new flag - #11203
Block cert modification in callbacks based on new flag#11203padelsbach wants to merge 4 commits into
Conversation
7336dee to
e3deb50
Compare
|
retest this please |
|
aacdd5e to
8550ddf
Compare
|
jenkins retest this please |
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #11203
Scan targets checked: wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src
Findings: 5
4 finding(s) posted as inline comments (see file-level comments below)
Required changes (1)
AltPrivateKey Id/Label loaders bypass the new in-callback guard
File: src/ssl_load.c:4600
Function: wolfSSL_CTX_use_AltPrivateKey_Id
Category: Use-after-free / double-free
wolfSSL_CTX_use_AltPrivateKey_Id and _Label free and replace ctx->altPrivateKey with no CheckCtxCertLoad call, unlike the PrivateKey_Id/_Label siblings this PR guards. Without WOLFSSL_BLIND_PRIVATE_KEY, ssl->buffers.altKey aliases that buffer (src/internal.c:7706), so an in-callback call frees key bytes live handshakes still read. Adjacent to known finding #8917, which covers the cross-thread reload race rather than the in-callback path.
Related known finding #13391 (similar but distinct): Both involve the AltPrivateKey ID/label replacement APIs and key-buffer replacement, but this is a callback-time aliased-buffer free caused by an omitted CheckCtxCertLoad call, whereas #13391 is a stale blinding-mask overread. They require separate guards and cleanup changes.
Recommendation: Call CheckCtxCertLoad(ctx) before FreeDer(&ctx->altPrivateKey) in both the alt Id and alt Label loaders.
Referenced code: src/ssl_load.c:4600-4602 (3 lines)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
| return 0; | ||
| } | ||
|
|
||
| if (CheckCtxCertLoad(ctx) != 0) { |
There was a problem hiding this comment.
Alternate private-key Id/Label setters bypass the new callback guard · Logic errors
The guard was added to wolfSSL_CTX_use_PrivateKey_Id/_Label but not to their alternate-key twins at ssl_load.c:4600 and ssl_load.c:4651, which also FreeDer(&ctx->altPrivateKey). Under WOLFSSL_DUAL_ALG_CERTS without blinding, ssl->buffers.altKey aliases that buffer (internal.c:7706), so calling either from an SNI or cert-setup callback frees what in-flight handshakes read.
Related known finding #13391 (similar but distinct): Both affect CTX primary/alternate key ID/label replacement setters in ssl_load.c, but this frees an aliased alternate-key buffer during a callback due to a missing guard, while #13391 retains a stale blinding mask after replacement. The configurations, faulting state, and fixes differ.
Fix: Add the same CheckCtxCertLoad(ctx) check to wolfSSL_CTX_use_AltPrivateKey_Id and wolfSSL_CTX_use_AltPrivateKey_Label before they free ctx->altPrivateKey.
2bf229f to
6deb1a3
Compare
Description
Prevent the user from modifying certificates when those buffers are aliased across WOLFSSL and WOLFSSL_CTX objects. Specifically, the wolfSSL_CTX_use_certificate* and wolfSSL_CTX_user_PrivateKey* API families (and a few other one-offs) are blocked.
This is yet another approach to solving zd 22107
Testing
Added unit tests.
Checklist