← ALL ADVISORIES

LOW BYTERAY-2026-0502Disclosed

wolfSSL — Time-of-Check to Time-of-Use Race in X509 Hash-Directory CRL Lookup

On a CRL miss, LoadCertByIssuer checks that the issuer-hash CRL file exists and then loads it by name. The loader opens the same path twice in a row, so one lookup resolves the name three times. A local process that can write to the directory can replace the file between any of them.

Advisory
BYTERAY-2026-0502
CWE
CWE-363
CVSS
3.6 (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:L/I:L/A:N)
Vendor
wolfSSL
Product
wolfSSL
Reported
2026-09-28
Disclosure
2026-12-03
Affected
wolfSSL 5.9.2 (tested at master commit d95483f), builds with HAVE_CRL, OPENSSL_ALL, WOLFSSL_CERT_GEN and WOLFSSL_CERT_REQ or WOLFSSL_CERT_EXT, with filesystem and directory support, where the application configures a hash-directory lookup and enables CRL checking
Credit
Mehrun P. Hunter and Shahriyar Jalayeri, ByteRay Ltd.

Executive Summary

When CRL checking finds no CRL in memory for a certificate's issuer, builds with the OpenSSL compatibility layer can fall back to a hash directory. LoadCertByIssuer() builds a name of the form <dir>/<hash>.r<N>, checks that the file exists, and then calls wolfSSL_X509_load_crl_file() to load it.

The check and the load are separate resolutions of the same name. The loader adds to this: it calls wolfSSL_BIO_read_filename() on the path twice in succession. A single lookup therefore resolves the name once with stat and twice with independent opens. No lock covers the file or the directory. A local process that can write, rename or link in the CRL hash directory can replace the file between these steps and have different content parsed and installed as a CRL.

The consequence is bounded. Write access to that directory already allows a CRL file to be placed there with no race, and a CRL is still checked against the issuer's signature when it is used. A default build does not include this code path.

Affected Products and Versions

  • Component: src/internal.c, LoadCertByIssuer(), CRL branch (X509_LU_CRL), and src/x509.c, wolfSSL_X509_load_crl_file().
  • Required build: HAVE_CRL, OPENSSL_ALL, WOLFSSL_CERT_GEN, and WOLFSSL_CERT_REQ or WOLFSSL_CERT_EXT, with filesystem and directory support (src/crl.c:640-644). The application must configure a hash-directory lookup on the X509 store and enable CRL checking.
  • Tested: wolfSSL master d95483fff72d6e987394b72edca433d4b580a0f4 (version string 5.9.2).
  • A default ./configure build defines neither OPENSSL_ALL (configure.ac:3296-3297) nor CRL support (configure.ac:9144-9148) and does not reach this code.
  • Other releases were not checked.

Technical Details

The loader opens the same path twice before it reads anything (src/x509.c:9410-9415). The second call closes the first file and opens the name again. It does not pin the file. It adds a third point at which the directory entry can differ.

    if (wolfSSL_BIO_read_filename(bio, file) <= 0) {
        wolfSSL_BIO_free(bio);
        return ret;
    }

    if (wolfSSL_BIO_read_filename(bio, file) <= 0) {

Data flow:

  1. CRL checking on a peer certificate reaches CheckCertCRLCm(). When no in-memory CRL matches the issuer, it calls LoadCertByIssuer() with X509_LU_CRL (src/crl.c:650-653).
  2. LoadCertByIssuer() requires a hash-directory lookup (src/internal.c:16643) and builds the candidate name with the r prefix (src/internal.c:16670-16672, src/internal.c:16723).
  3. wc_FileExists() stats the name (src/internal.c:16732). The stat follows symlinks (wolfcrypt/src/wc_port.c:1376).
  4. wolfSSL_X509_load_crl_file() is called with the same name (src/internal.c:16749-16750).
  5. Inside it, the path is opened at src/x509.c:9410 and again at src/x509.c:9415.
  6. The parsed CRL is installed with wolfSSL_X509_STORE_add_crl() (src/x509.c:9430) and becomes revocation data for later checks.

The mutex taken in the lookup loop protects the cached suffix list only. It does not cover the file check or the opens. The path uses no O_NOFOLLOW and no open followed by fstat.

Reachability and Preconditions

  • Build flags as listed above, a hash-directory lookup configured on the store, CRL checking active, and no CRL in memory for the issuer in question.
  • A local process with permission to write, rename or link in the CRL hash directory.
  • A TLS peer whose certificate has an issuer with no loaded CRL starts the lookup. The issuer name selects the file name. The peer does not control the file content. The swap has to land between the stat and one of the two opens.

Impact

The CRL that is parsed and installed can differ from the file that the existence check saw. The realistic outcomes are disruption of revocation checking, or a stalled verification thread when the name is switched to an object that blocks on open or read. An unsigned replacement cannot by itself change a revocation outcome, because the CRL is verified against the issuer's signature when it is used. The local access the race needs already allows a CRL to be placed in the directory directly, so the added value is mostly in getting around file monitoring or rename-only restrictions.

ByteRay did not build a proof of concept for this issue. The analysis is from source review.

Remediation and Mitigation

ByteRay has not confirmed a fixed wolfSSL release for this issue as of 2026-12-03, and has not checked it against wolfSSL changes made after the tested commit.

The fix direction has two parts. Remove the duplicated wolfSSL_BIO_read_filename() call so the loader opens the file once. Replace the stat-then-open sequence with a single open, without following symlinks where supported, followed by fstat on the descriptor and a parse from that descriptor. Directory-relative opens against a descriptor for the hash directory are an alternative. Issuer signature verification should stay a mandatory gate for CRLs loaded this way. As a mitigation, restrict write access on the CRL hash directory to the identity that maintains it.

Timeline

  • 2026-09-28 — Reported to wolfSSL.
  • 2026-12-03 — Public disclosure.

Credits

Discovered and reported by Mehrun P. Hunter and Shahriyar Jalayeri of ByteRay Ltd.

References