Skip to content

Block cert modification in callbacks - #11191

Closed
padelsbach wants to merge 1 commit into
wolfSSL:masterfrom
padelsbach:sni-callback-detect-cert
Closed

Block cert modification in callbacks#11191
padelsbach wants to merge 1 commit into
wolfSSL:masterfrom
padelsbach:sni-callback-detect-cert

Conversation

@padelsbach

@padelsbach padelsbach commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

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

New unit tests.

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@padelsbach
padelsbach marked this pull request as ready for review August 18, 2026 18:50
@github-actions

Copy link
Copy Markdown

retest this please

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #11191

Scan targets checked: wolfcrypt-rs-bugs, wolfssl-bugs, wolfssl-src

Findings: 10
10 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread src/internal.c Outdated
Comment thread src/ssl_api_cert.c
Comment thread tests/api/test_tls.c Outdated
Comment thread tests/api/test_tls.c Outdated
Comment thread tests/api/test_tls.c Outdated
Comment thread src/internal.c
{
int ret = 0;

if (SslDerIsStale(ssl->buffers.certificate, ssl->buffers.weOwnCert,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 [Low] Cert-swap block is post-hoc and per-session; other sessions on the CTX keep dangling DER pointers · Use-after-free / double-free

The check runs only after the callback has already freed ctx->certificate/ctx->privateKey. In the default non-WOLFSSL_COPY_CERT build every other live WOLFSSL from that CTX still aliases the freed DerBuffer (assigned at src/internal.c:7627) and dereferences it when building its Certificate message, so the use-after-free remains reachable for concurrent sessions.

Fix: Prevent CTX cert/key replacement while sessions reference it (refcount the DerBuffers or reject the load) rather than detecting it after the free.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refcount solution was attempted and sprawling, but would allow us to support modification in the callbacks. But too invasive of a change for an invalid use case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ability to reach a UAF is a legit problem with this approach. Closing the PR

Comment thread src/internal.c
Comment thread src/internal.c Outdated
Comment thread tests/api/test_tls.c Outdated
Comment thread tests/api/test_tls.c
@github-actions

github-actions Bot commented Aug 18, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

gcc-arm-cortex-m3

  • FLASH: .text +72 B (+0.1%, 123,883 B / 262,144 B, total: 47% used)

gcc-arm-cortex-m4

  • FLASH: .text +64 B (+0.0%, 202,159 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m4-dtls13

  • FLASH: .text +64 B (+0.0%, 183,740 B / 1,048,576 B, total: 18% used)

gcc-arm-cortex-m4-openssl-compat

  • FLASH: .rodata +24 B, .text +128 B (+0.0%, 776,500 B / 1,048,576 B, total: 74% used)

gcc-arm-cortex-m4-pq

  • FLASH: .text +64 B (+0.0%, 298,012 B / 1,048,576 B, total: 28% used)

gcc-arm-cortex-m4-rsa-only

  • FLASH: .text +128 B (+0.0%, 328,496 B / 1,048,576 B, total: 31% used)

gcc-arm-cortex-m4-tls12

  • FLASH: .text +64 B (+0.1%, 124,659 B / 262,144 B, total: 48% used)

gcc-arm-cortex-m4-tls13

  • FLASH: .text +128 B (+0.1%, 238,817 B / 262,144 B, total: 91% used)

gcc-arm-cortex-m7

  • FLASH: .text +64 B (+0.0%, 202,159 B / 262,144 B, total: 77% used)

gcc-arm-cortex-m7-pq

  • FLASH: .text +128 B (+0.0%, 298,972 B / 1,048,576 B, total: 29% used)

gcc-arm-cortex-m7-tls13

  • FLASH: .text +64 B (+0.0%, 238,817 B / 262,144 B, total: 91% used)

linuxkm-standard

@padelsbach
padelsbach force-pushed the sni-callback-detect-cert branch from 070e66a to e90aefe Compare August 18, 2026 22:18
@padelsbach padelsbach closed this Aug 19, 2026
@padelsbach padelsbach mentioned this pull request Aug 21, 2026
4 tasks
@padelsbach

Copy link
Copy Markdown
Contributor Author

Superseded by #11203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants