Skip to content

x509: fix use-after-free in wolfSSL_X509_STORE_get0_objects#10650

Draft
ColtonWilley wants to merge 1 commit into
wolfSSL:masterfrom
ColtonWilley:fix/x509-store-get0-objects-uaf
Draft

x509: fix use-after-free in wolfSSL_X509_STORE_get0_objects#10650
ColtonWilley wants to merge 1 commit into
wolfSSL:masterfrom
ColtonWilley:fix/x509-store-get0-objects-uaf

Conversation

@ColtonWilley

Copy link
Copy Markdown
Contributor

Description

wolfSSL_X509_STORE_get0_objects builds its list from CertManager certs (owned
by the list) and borrowed store->certs entries, using store->numAdded to
mark the borrowed tail so they aren't freed. When the store has a CRL, a CRL
object is appended after those certs, so the count freed a cert still owned by
store->certs. The next get0_objects call then returned a dangling pointer —
the use-after-free reported with HAProxy under ASAN.

The list now takes its own reference on every cert (wolfSSL_X509_up_ref), so it
owns all its entries and is freed uniformly, and the numAdded bookkeeping (and
its struct field) is removed.

Fixes #10123

Testing

Added test_X509_STORE_get0_objects_extern_repeat: loads a root and an
intermediate into a standalone X509_STORE and calls get0_objects repeatedly.
Faults under ASAN on master, passes with the fix. Full unit.test passes under
ASAN with --enable-haproxy.

Checklist

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

wolfSSL_X509_STORE_get0_objects builds its list from CertManager certs
(owned by the list) and borrowed store->certs entries, using
store->numAdded to mark the borrowed tail so they aren't freed. When the
store has a CRL, a CRL object is appended after those certs, so the count
freed a cert still owned by store->certs. The next get0_objects call then
returned a dangling pointer - the use-after-free reported with HAProxy
under ASAN.

The list now takes its own reference on every cert (wolfSSL_X509_up_ref),
so it owns all its entries and is freed uniformly, and the numAdded
bookkeeping (and its struct field) is removed.

Fixes wolfSSL#10123
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.

[Bug]: use-after-free in WolfSSL using HAProxy

1 participant