Commit Graph
4335 Commits
Author SHA1 Message Date
Tobias Brunner e64877b46c unbound: Make sure RRs match the queried or canonical name
While `ub_resolve()` verifies the response is valid, only the `data`
array provided in `ub_result` contains filtered results.  The raw
response packet we parse here could theoretically contain (validated)
RRs for a different owner that would get accepted and returned in the
provided `rr_set_t`.

Fixes: 5a4126b490 ("unbound: Implemented resolver_response_t as unbound_response_t")
2026-07-24 08:47:37 +02:00
Tobias Brunner 80f8f5e9d4 key-exchange: Rename function that verifies pubkey lengths
The previous name confused LLMs as they assume it is intended to actually
cryptographically verify the public key.  The new name more clearly
describes what it actually does.
2026-07-24 08:47:37 +02:00
Tobias Brunner 1fbb14884c botan: Remove confusing documentation for DH helper function
This comment only referred to not calling `key_exchange_verify_pubkey()`,
not what Botan does, which will verify the passed public value as needed.
LLMs get confused by this and assume Botan doesn't so that.
2026-07-24 08:47:37 +02:00
Tobias Brunner 11999f1679 mysql: Be more explicit when parsing database URI but don't log password
This avoids logging the password that's potentially contained in the URI
and also gives clearer instructions about what's missing.

Also clears the memory that stores the URI/password.
2026-07-24 08:47:37 +02:00
Tobias Brunner 1487dbb4a3 pgp: Log parsed packet data on level 4 as it may contain a private key 2026-07-24 08:47:37 +02:00
Tobias Brunner 14a811b6af curve25519: Explicitly wipe shared secret when destroying DH object 2026-07-24 08:47:37 +02:00
Tobias Brunner 929065826b sqlite: Fix transaction handling for multiple concurrent threads
Due to the shared database connection, the previous code, while tracking
transaction metadata per thread, didn't actually enforce that separation
on the database level.  Which basically meant the transactions created
by multiple threads were shared.

This change uses an approach similar to the mysql plugin, using a pool of
connections.  However, we always use thread-specific connections, not
only during transactions.  That's because the implicit transactions
that are active in SQLite during queries block further queries from
other connections while enumerating (the pool utility uses such patterns).

It also fixes the issue that calling `rollback()` on the outer-most
transaction didn't have an effect.

Since it's very unlikely SQLite was built in single-thread mode and
handling that properly would require locking the mutex during
transactions, we remove that locking and move the check to the constructor
to refuse initialization.

Fixes: fad11d602d ("sqlite: Implement transaction handling")
2026-07-24 08:47:36 +02:00
Tobias Brunner bcef2c8f01 atomics: Use ACQUIRE ordering for ref_cur()
Before, `ref_cur()` used RELAXED memory ordering, which is sufficient
for diagnostic reads but provides no ordering guarantees against
concurrent `ref_put()` operations on other threads.  Since `ref_put()`
already uses ACQ_REL ordering, readers should use ACQUIRE ordering
so that observing a given refcount value (particularly zero) also
makes all prior stores by the releasing thread visible.

There is no significant performance impact as on x86 ACQUIRE loads
compile to the same instruction as RELAXED loads.  But this fixes
potential issues on weakly-ordered architectures (e.g. ARM).

The __sync* and spinlock fallbacks already provide full ordering (they
might not actually be necessary anymore nowadays).
2026-07-24 08:47:36 +02:00
Tobias Brunner b52fc6c284 stream-service: Avoid race condition when accepting sockets
Even if `poll()` indicates that the socket is ready it might block if
it's in blocking mode. This change avoids blocking in such cases (accept
will fail with EAGAIN/EWOULDBLOCK and `watch()` will return TRUE).

As the non-blocking mode is inherited on Windows (on Linux, the man page
documents the non-inheritance as a Linux specialty), we set the mode for
the accepted socket explicitly to blocking to match the expectations of
`stream_t`.

Fixes: daf1880b39 ("stream: add a stream service class abstracting services using BSD sockets")
2026-07-24 08:47:36 +02:00
Tobias Brunner 2eeb8965ed pkcs11: Fix ECDH derivation
The referenced commit moved the key derivation to `get_shared_secret()`
and broke the handling of ECDH public value as the copied struct now
referred to a buffer allocated on the stack.

Also fixes potential session leaks if generating key pairs fails.

Fixes: 26ca0c9f70 ("pkcs11: Move shared secret calculation to get_shared_secret()")
2026-07-24 08:47:36 +02:00
Tobias Brunner 75baeb9f35 constraints: Fallback to binary OIDs in log messages
Similar to the previous commit.
2026-07-24 08:47:36 +02:00
Tobias Brunner a5d815a6ef certificate-printer: Fallback to binary OID printing for policy mappings
This is the same fallback already used when printing the certificate
policies.

Fixes: 3317d0e77b ("Standardized printing of certificate information")
2026-07-24 08:47:35 +02:00
Tobias Brunner 502fa14536 asn1: Reject OIDs with too large sub-identifiers when converting to string
The shift would overflow the value which could produce garbage output
that might get interpreted as real OIDs (in case strings are compared).

This limit allows OID sub-identifiers to consist of at most 4 bytes,
which should be enough for any real-world OIDs (it's also the maximum we
used in tests so far).

Fixes: f813069e89 ("fixed asn1_oid_to_string() conversion")
2026-07-24 08:47:35 +02:00
Tobias Brunner 1372335d30 constant-time: Add 64-bit versions of the helpers
While we could use _Generic() C11 expression to let the compiler select
between the different versions, this only allows selection based on one
of the arguments, which seems a bit fragile.  So make this explicit for
now.  In the future we might consider using the overloadable attribute.
2026-07-24 08:47:35 +02:00
Tobias Brunner fe6dc7d256 af-alg: Fix output offset if not all data was processed during en-/decryption
If only parts of the total data could be written to the kernel, the result
of the next read chunk would incorrectly get written at the beginning of
the output buffer again.

Also makes sure to close the accepted FD in error cases.

Fixes: 1b5de7ce3b ("Use a generic AF_ALG wrapper for common operations")
2026-07-24 08:47:35 +02:00
Tobias Brunner d13b384536 byteorder: Add helpers to read from unaligned addresses without byte order changes
While utoh32/64 would also have been an option for the name, this is
more distinct to avoid confusion with the existing conversion functions.
2026-07-24 08:47:35 +02:00
Tobias Brunner 7bf9b6bad8 x509: Avoid memory leak if multiple nonce extensions are found in OCSP response 2026-07-23 10:26:08 +02:00
Tobias Brunner 7e7c2805df identification: Avoid truncating identities created from data blobs
This is not necessarily an issue, but we should avoid not using the
full identity data as best as possible.  The change also avoids the
dynamically sized buffer on the stack.

Fixes: 324528700d ("Added identification constructor using a chunk of data, guessing id type")
2026-07-23 10:26:08 +02:00
Tobias Brunner 45b2f8d91f revocation: Avoid that a skipped CRL lookup/fetch prevents fetching delta CRLs
If we find a stale CRL in the cache and finding a newer one via
CRLIssuer fails for some reason, the validation state would get
overwritten with VALIDATION_SKIPPED.  This would then prevent
fetching delta CRLs.

Fixes: 7d7beaa1fa ("Use certificate CRLIssuer information to look up cacched CRLs or CDPs")
2026-07-23 10:26:08 +02:00
Tobias Brunner 4110d2795a windows: Avoid unnecessarily locking the global thread lock when removing TLS
Holding the lock could potentially cause a deadlock depending the
behavior of the called cleanup functions.  The TLS removal happens in
the context of the respective thread, so no locking is necessary.

Looks like removing these lines was missed when the referenced commit
partly reverted 204098a752 ("thread-value: Immediately cleanup all
Windows TLS values on destroy"), which added the locking originally.

Fixes: 23750961d5 ("thread-value: Defer cleanup handling to thread termination on Windows")
2026-07-23 10:26:08 +02:00
Tobias Brunner 097c7a1e0a process: Correctly read last path character on Windows
Fixes: 7dd06d274d ("process: Add a wrapper to invoke a command under the system default shell")
2026-07-23 10:26:08 +02:00
Tobias Brunner 87f0bc2a6c cert-cache: Fix race conditions when inserting CRL/OCSP
Because no lock was held while comparing the type of the already stored
cache entry, it was theoretically possible that a NULL-pointer dereference
or use-after-free was caused if another thread concurrently replaced the
stored certificate.

While the cached type is also read without lock, the worst that can
happen is that we acquire the lock of an entry that doesn't match
eventually.  The double check actually uses the stored certificate,
just in case the cached value gets out of sync due to a future
refactoring.

Fixes: 2271ebb325 ("Newer CRLs replace older versions of the CRL in the cache")
Fixes: 47e8b21c76 ("cert_cache: Replace cached stale OCSP responses in-place")
2026-07-23 10:26:08 +02:00
Tobias Brunner 355d591967 openssl: Fix memory leak if HMAC instantiation fails late
Fixes: db0c53c207 ("openssl: Fixes for HMAC with OpenSSL 3.0")
2026-07-23 10:26:08 +02:00
Tobias Brunner 9598de465c unit-tests: Add tests to ensure our Curve25519/448 implementations don't return all-zero secrets
Note that wolfSSL before 5.9.2 required building with
WOLFSSL_ECDHX_SHARED_NOT_ZERO, which was added with 5.3.0, to get and
explicit check.  Since the plugin validates the public key, the test case
fails nonetheless.
2026-07-23 10:26:08 +02:00
Tobias Brunner 589a3a6729 curve25519: Reject all-zero shared secrets
While RFC 7748 states implementations MAY perform such a check, e.g.
TLS 1.3 explicitly requires it (RFC 8446, section 7.4.2).

Fixes: 7f9bfacd5a ("curve25519: Add a plugin providing Curve25519 DH using backend drivers")
2026-07-23 10:26:08 +02:00
Tobias Brunner d9cf1b0bff wolfssl: Avoid potential RNG state corruption during RSA/ECDSA operations
The WC_RNG instances are potentially shared between different threads
as private key objects are refcounted.  This may corrupt their internal
state as they are not thread-safe.

For ECDSA, using separate instances for each signing operation has some
performance impact, but for signature operations that should be fine.

The implementation for RSA uses mutexes.  That's due to the weird API.
While RNG instances can be passed for signing and encryption (probably
because they are also required for padding/salt besides blinding), they
can't for verifying and decryption.  The latter use an RNG instance that
has to be set on the key object before calling these operations.  So we
could potentially split the strategy, but to keep this consistent within
the RSA implementation, just continue with the shared RNG but use a
mutex around the API calls.

Fixes: c92eade82c ("wolfssl: Add wolfSSL plugin for cryptographic implementations")
2026-07-23 10:26:07 +02:00
Tobias Brunner 05625acc2a wolfssl: Ensure X25519/X448 public key is valid 2026-07-22 18:20:12 +02:00
Tobias Brunner 1fe813f05e wolfssl: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: c92eade82c ("wolfssl: Add wolfSSL plugin for cryptographic implementations")
2026-07-22 18:20:12 +02:00
Tobias Brunner 023c626525 openssl: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: 81f9cd39fd ("openssl: Provide AES-GCM implementation")
2026-07-22 18:20:12 +02:00
Tobias Brunner c6adb20ec7 chapoly: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: 370fb3feb0 ("chapoly: Provide a generic ChaCha20/Poly1305 AEAD supporting driver backends")
2026-07-22 18:20:12 +02:00
Tobias Brunner 85c02dc16c ccm: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: 80a93a1335 ("Implemented a ccm plugin providing CCM mode based on CBC crypters")
2026-07-22 18:20:12 +02:00
Tobias Brunner 40aa0a12c4 botan: Fix memory leak on failed ICV verification if not using in-place decryption
Fixes: af26cc4d85 ("botan: Add Botan plugin to libstrongswan")
2026-07-22 18:20:12 +02:00
Tobias Brunner a2f83d3075 aesni: Fix memory leak on failed ICV verification if not using in-place decryption
The `aead_t` interface states that `decrypt()` only allocates a plaintext
buffer if successful, so callers might not free it if the call failed.

Fixes: 313811b72d ("aesni: Add a GCM AEAD based on the AES-NI key schedule")
2026-07-22 18:20:12 +02:00
Tobias Brunner f5aeba0f02 watcher: Remove unnecessary pending flag
This was added with 5ce3c9b15a ("watcher: Rebuild fdset when select()
fails"), i.e. before switching to poll(), solely to suppress errors when
FDs are closed and select() would return with an error.  With poll()
this should not happen result in an error (it potentially indicates this
via POLLNVAL in revents of that FD in the array).

Because the flag was not consistently changed/read with the mutex held,
some analysis tools got confused and imagined wild deadlock scenarios.
2026-07-21 10:37:43 +02:00
Tobias Brunner 87bbfe4f5f gcm: Implement block multiplication in constant time 2026-07-21 10:37:43 +02:00
Tobias Brunner b3c0019c84 pgp: Fix validity calculation and potential overflow
The two fields were swapped in the calculation and the new code also
avoids overflowing on 32-bit systems.

Fixes: 4cb0e1bb76 ("Added basic support for PGP certificates (no trust relationships yet)")
2026-07-21 10:37:43 +02:00
Tobias Brunner 24c70db4b9 aesni: Split plugin to avoid potential SIGILL
Because the CFLAGS applied to the whole plugin, the compiler could
"optimize" the boilerplate plugin code, which could then cause a SIGILL
on hardware that doesn't support such instructions.  This change makes
sure only the actual AES implementation is compiled like that, which
would then not get registered depending on the CPU feature detection.
2026-07-21 10:21:51 +02:00
Tobias Brunner 528898a976 unit-tests: Allow Ed448 implementations to fail parsing small-order public keys
We already adapted the Ed25519 test with 36b1a6d76c ("Use Botan 3.1.1
for tests"), now wolfSSL refuses to create such Ed448 keys as well.
2026-06-29 17:45:29 +02:00
Tobias Brunner 98b133c54c wolfssl: Adapt to removed ML-KEM header
The mlkem.h header that mainly defined aliases for the old wc_Kyber* API
has been removed and its contents moved to the wc_mlkem.h header.
2026-06-26 08:10:16 +02:00
R. Elliott Childre 075323d895 identification: Fix double-free when cloning empty IDs
The clone() method was missing a branch when there is an encoded chunk
of length 0 that still needed to be cloned.  Otherwise, the destruction
of the clone frees the same pointer that the original owns.

This double free was found with an improved `fuzz_ids` fuzz harness and
a two byte input to create an identification from "@#" or [0x40, 0x23].
It can also be triggered with `<type>:#` e.g. `dns:#`.

One of the problematic constructors is used to parse EAP-Identities,
which are cloned before storing them in the auth-cfg.   So this can be
triggered by an unauthenticated attacker.

Note that while the length check was already added with 418dbd6243
("cloning %any ID without zero-byte memleak") and identities that trigger
this can be created since 86ab5636c2 ("support for @#hex ID_KEY_ID
identification_t"), it was the referenced commit that made the length
check problematic.

Fixes: 2147da40a5 ("simplified identification_t.clone() using memcpy")
Fixes: CVE-2026-47895
2026-06-05 17:35:06 +02:00
Tobias Brunner 5fc403702b leak-detective: Also ignore unknown memory freed in OPENSSL_cleanup()
It seems that 18a94525a7 was a bit hasty.  Apparently, it's still the
case that there were reports (at least in some test scenarios).  Luckily,
the new facility added in the previous commit allows us to whitelist
these allocations without having to ignore all unknown memory.
2026-06-05 16:58:45 +02:00
Tobias Brunner 3216646bdb leak-detective: Add workaround for unknown memory reports with glibc
With glibc, there is an issue if TZ is not set, which causes a change
of the internally cached TZ value.  Because the original value was
cached before LD was active via `init_static_allocations()`, the memory
is freed as unknown memory later.  This change allows whitelisting
a function that might free such memory (tzset() only for now).
2026-06-05 16:40:49 +02:00
Tobias Brunner 531de4d858 pkcs7: Fail parsing PKCS#7 signed-data if content can't be parsed
This avoids a crash after verifying the signed attributes in the signature
enumerator.
2026-06-01 18:21:43 +02:00
Tobias Brunner bff405c349 oid: Fix confusing identifiers for elliptic curves over prime fields
SECT (indicating a binary field) was incorrectly used in constants for
the SECP (prime field) curves.
2026-05-28 13:30:07 +02:00
Tobias Brunner 5fcf1fc0ef public-key: Fix mapping of RSA with PKCS#1 v1.5 and SHA3-512 to OID
Fixes: 40f2589abf ("gmp: Support of SHA-3 RSA signatures")
2026-05-28 13:21:22 +02:00
Thomas Jarosch f0a489f7e2 credential-manager: Check certificate expiry also for trusted self-signed certs
This serves as a defense-in-depth measure against forgotten
configs/credentials.
2026-05-22 14:33:28 +02:00
Thomas Jarosch 0d17838b99 credential-manager: Check expiry also for last cert in incomplete trust chain
While the validity of a pre-trusted certificate for which an issuer is
found is enforced via `check_certificate()`, the validity of such a
certificate in an incomplete trust chain, or rather that of the last
certificate in such a chain, was not enforced.  This fixes that
inconsistency.
2026-05-22 14:33:28 +02:00
Tobias Brunner ea569867d2 tun-device: Fix setting IPv6 address on Linux
Unlike `struct ifreq` that's used for IPv4, `struct in6_ifreq` contains
not a `struct sockaddr[_in6]` but only a `struct in6_addr`.

Setting addresses like this is currently not used on Linux (the feature
was added to install virtual IPs on FreeBSD/macOS).

Fixes: fccc76449d ("tun-device: Fix handling of IPv6 addresses")
2026-05-19 17:27:33 +02:00
Tobias Brunner 3b224a70ba xof: Fix mapping for SHA3-512 to a corresponding MGF1 identifier
Fixes: 3b7c49bc31 ("mgf1: Support of RSA PSS with SHA3 hash")
2026-05-19 17:27:33 +02:00
Tobias Brunner a26dd3da33 openssl: Check that EC keys don't have explicit params for internally loaded keys
Keys loaded via generic loader (KEY_ANY) or from a PKCS#12 file (or an
engine) don't go through the openssl_ec_private_key_load() constructor
that checks for explicit parameters.
2026-05-19 17:27:33 +02:00