Commit Graph
100 Commits
Author SHA1 Message Date
Tobias Brunner 8aca7f9231 chunk: Add utility that compares the prefix of two chunks
Unlike chunk_compare() this first compares the prefix of two nonces,
then falls back to comparing the length.  This is basically intended to
compare nonces as specified in RFC 7296:

   "Lowest" means an octet-by-octet comparison (instead of, for instance,
   comparing the nonces as large integers).  In other words, start by
   comparing the first octet; if they're equal, move to the next octet,
   and so on.  If you reach the end of one nonce, that nonce is the
   lower one.
2026-07-24 08:47:39 +02:00
Tobias Brunner 0ffc3f3fd6 gcrypt: Fix zeroing padding when extracting RSA value from S-expression
When left-padding a value shorter than the RSA key, the code previously
calculated the length incorrectly so that some bytes might have been
cleared if the value was shorter than half the required length.

Fixes: a2f1bb238e ("enforce correct RSA signature lenght in gcrypt")
2026-07-24 08:47:39 +02:00
Tobias Brunner 322d947a04 eap-sim-pcsc: Properly release context if determining list of readers fails
Fixes: 80dca77a50 ("Added SIM card backend based on pcsc-lite")
2026-07-24 08:47:39 +02:00
Tobias Brunner 918e052ae1 eap-md5: Avoid memory leak caused by repeated challenges
Fixes: 4b403e7672 ("merged EAP-MD5 into trunk")
2026-07-24 08:47:39 +02:00
Tobias Brunner 4eaaf19217 kernel-netlink: Properly clean up pending entry if VIP installation failed
This could prevent the VIP from getting installed later and actually
causes those threads to block indefinitely as they wait for the entry to
either get removed or the VIP marked as installed, which will never
happen.

Fixes: c6b401581a ("Changed how kernel-netlink handles virtual IP addresses")
2026-07-24 08:47:39 +02:00
Tobias Brunner c52fd0c518 ha: Fix offset checks in HA address pool
This applies some of the same fixes found in the previous commit but also
ensures that the offsets are valid before accessing the bitmask.  Because
of an off-by-one error in the latter, the last address could get released
incorrectly (the pool constructor explicitly excludes it).

Fixes: 98d0343870 ("Implemented a HA enabled in-memory address pool")
2026-07-24 08:47:39 +02:00
Tobias Brunner e3607d546d mem-pool: Enforce size limit also for range-based pools and fix overflow
Due to the overflow when mapping addresses to offsets, no addresses could
get released when the pool was defined in a way that the last address
assignable is 255.255.255.255 (probably never the case in practice).

While not really useful in practice, the range 0.0.0.0-255.255.255.255
resulted in an empty pool (`size = 0xffffffff + 1`), which triggers the
%config like behavior.  Since the implementation currently uses signed
integers throughout, we make sure the largest assignable offset is
INT_MAX.

The two off-by-one fixes (`>= pool->size`) were never an issue in practice
because `get_new()` has a guard that caps the offset at the size and
released addresses originally came from the pool so are always in range.

Fixes: 0897cda33b ("Add a constructor to create in-memory pools from an address range")
2026-07-24 08:47:39 +02:00
Tobias Brunner a3ebaa82de xauth-pam: Use proper method to read session option 2026-07-24 08:47:38 +02:00
Tobias Brunner ad7d50f846 nm: Fix double-free of IKE config in error cases and some leaks and potential NULL dereferences 2026-07-24 08:47:38 +02:00
Tobias Brunner bde21aa4f9 openssl: Fix memory leak when verifying plain RSA signatures with old BoringSSL versions
Fixes: 21b586c61c ("openssl: Fixes for RSA with OpenSSL 3.0")
2026-07-24 08:47:38 +02:00
Tobias Brunner c64554b17f pt-tls-client: Don't store PT-TLS message on stack
Basically the same as the previous commit.
2026-07-24 08:47:38 +02:00
Tobias Brunner 3150e61e00 pt-tls-server: Don't store PT-TLS message on stack
The size of that buffer was ~2 MB, which is not ideal for systems
with restricted stack sizes.
2026-07-24 08:47:38 +02:00
Tobias Brunner 268c11fa8c vici: Fix leak if selectors for redirect command are missing or invalid
Fixes: 43b46b26ea ("vici: Add redirect command")
2026-07-24 08:47:38 +02:00
Tobias Brunner 6dca323ae0 shunt-manager: Fix potential race between install and uninstall
If the installation fails while a shunt is concurrently uninstalled,
the entry could already be destroyed when trying to remove and destroy
it after acquiring the lock again in `install()`.

This change handles the conflict the same way trap-manager does since
69cbe2ca3f ("trap-manager: Wait for install to finish before
uninstalling").

Fixes: 616ff9a236 ("shunt-manager: Remove stored entries if installation fails")
2026-07-24 08:47:38 +02:00
Tobias Brunner 40f40973c0 pem: Properly handle encrypted PEM files without DEK-Info
Since `key_size` remained zero, this caused a buffer overflow when the
derived key in `pem_decrypt()` was copied to the zero-length local
buffer.

Also fixed two potential memory leaks if hashing fails and make sure
the decryption key is wiped.

Fixes: 160f4c225d ("moved PEM parsing functionality to its own plugin")
2026-07-24 08:47:38 +02:00
Tobias Brunner 2367cda71e android: Fix reading split-tunneling block settings in managed configs
The key in a Bundle is apparently case-sensitive.  Also align the
spelling with the rest of the app.

Fixes: c2007d5b09 ("android: Add managed_configuration.xml")
2026-07-24 08:47:38 +02:00
Tobias Brunner e03ec46466 vici: Fix memory leaks if loading CA cert in authority section fails
The return value is now also fixed.  The reply allocation previously
prevented that sections with failed CA certs were rejected.

Also fixes two potential leaks if duplicate settings are sent by a VICI
client.

Fixes: 63d370387d ("vici: Certification Authority support added.")
2026-07-24 08:47:38 +02:00
Tobias Brunner 98fd5e9893 ha: Fix memory leak if Child SA key derivation fails
Fixes: aa334daa9b ("Use a sync message cache to resynchronize IKE_SAs without rekeying")
2026-07-24 08:47:38 +02:00
Tobias Brunner 77cfa835cd connmark: Only install one rule per Child SA in PREROUTING
These rules don't depend on traffic selectors, so for SAs with multiple
traffic selectors we'd install several duplicate rules.  Since this
plugin is used for transport mode SAs, it probably never was an issue
in practice.

Fixes: b8973b2661 ("connmark: Add CONNMARK rules to select correct output SA based on conntrack")
2026-07-24 08:47:38 +02:00
Tobias Brunner 71fff07aba charon-tkm: Fix potential use-after-free in chunk map
This isn't a problem in practice as the nonces stored in the map are
tied to the IKE SA that's currently checked out, so a found entry can't
get removed/replaced concurrently.
2026-07-24 08:47:38 +02:00
Tobias Brunner 4224c3f647 sha3: Make sure state and rate input buffers are 8-byte aligned
Both buffers are accessed directly by casting to `uint64_t`.  On platforms
that don't allow unaligned accesses this could cause a SIGBUS.  The
reorder should avoid extra padding between the two buffers.

Fixes: 5ff88c9622 ("xof: Implemented SHAKE128 and SHAKE256 Extended Output Functions")
Fixes: 83c1883d0b ("Use word-aligned XOR in sha3_absorb()")
2026-07-24 08:47:38 +02:00
Tobias Brunner 50177b4004 ike-auth: Enforce PPK required constraint on the initiator
Fixes: a9e60c96dc ("ike-auth: Add basic PPK support")
2026-07-24 08:47:38 +02:00
Tobias Brunner c40e8214ed ike-init: Make sure we received a KE payload as initiator
On the responder, dc8b479eb8 ("ike-init: Fix key derivation if SA is
reset after IKE_INTERMEDIATE retransmits") fixed this.  But the initiator
still accepted IKE_INTERMEDIATE exchanges without KE payload.

Fixes: 0d49ddec2e ("ike-init: Add support for multiple key exchanges")
2026-07-24 08:47:38 +02:00
Tobias Brunner 889d83b997 Make sure KEM implementations don't return an empty shared secret
If `set_public_key` is never called we won't have a shared secret to
return.  This aligns the implementations with the one in the openssl
plugin.
2026-07-24 08:47:38 +02:00
Tobias Brunner 455b3e2298 android: Fix leak of JNI local ref in IMC when creating string array
Fixes: 036fa7a166 ("android: Overload for getMeasurement() that takes a String array as argument")
2026-07-24 08:47:38 +02:00
Tobias Brunner dd6a984afb xauth-generic: Make sure to only use secrets that match the username
This ensures that secrets that are associated with the server identity,
usually they are assigned to the username exclusively, will only be tried
if the username also matched.  Otherwise, it could be possible for users
who know at least one password to impersonate another user.

Fixes: 462c9a4f72 ("Try all matching XAuth secrets we find, not only the first one")
2026-07-24 08:47:38 +02:00
Tobias Brunner 485f7645a2 kernel-wfp: Add support for SA deletion in either order
The code was written with `child_sa_t::destroy` in mind, which deletes
the inbound SA before the outbound SA.  The problem is that the rekeying
code was changed meanwhile so the outbound SA is removed before the
inbound SA in order to avoid traffic loss.  That could cause a
use-after-free as the already destroyed item remained in the `isas` list.

This change fixes this so the SAs can be removed in any order.  The SPIs
are used as marker for whether a specific direction is installed.  It
also fixes an issue in `expire_job()`, which removed the entry from
`osas` without holding the lock.

Fixes: f351d9ef7d ("kernel-wfp: Reference SA/SP sets by SPI and destination, not reqid")
Fixes: 44107cb7b7 ("child-delete: Delay the removal of the inbound SA of rekeyed CHILD_SAs")
2026-07-24 08:47:38 +02:00
Tobias Brunner 4ebd1c524a host: Do some proper validation when parsing CIDR-style subnets
The previous code returned negative or too large values (e.g. /33 or /-1)
to the caller, which some would then use unchecked.  In particular the
attribute parser in the vici plugin would use it directly to generate a
subnet mask using shifts by `32 - mask`, which could trigger undefined
behavior.

Fixes: 65697c2734 ("Added a CIDR notation based host constructor")
2026-07-24 08:47:38 +02:00
Tobias Brunner 6419fc8d3c eap-radius: Limit number of concurrently cached DAE responses
An attacker who knows the shared secret could send DAE requests from
different IPs/ports to produce basically unlimited cached responses.
2026-07-24 08:47:38 +02:00
Tobias Brunner cd24806543 simaka-message: Prevent buffer overflow when generating messages
A malicious (authenticated) server could send a long AT_NEXT_PSEUDONYM
or AT_NEXT_REAUTH_ID attribute (max. 1016 bytes) that the client then
attempts to return in an AT_IDENTITY attribute that could overflow the
fixed-sized stack buffer `out_buf` by a few bytes (writing into the
`encr_buf` buffer).

This refactoring first calculates the length required to encode the
attributes (with and without encryption) and accounts for the overhead
necessary for AT_ENCR_DATA, AT_PADDING, and AT_MAC (some limits are
enforced and error handling is added where appropriate).  Then correctly
sized buffers are allocated and the attributes are encoded pretty much
as before.  Except that the encoding of AT_RES is corrected (it actually
worked fine for up to 31 bytes, so in practice it wasn't a problem),
AT_PADDING is not added if data is already block-aligned, and it corrects
handling of AT_NOTIFICATION (they are never sent encrypted according to
the RFCs, but protected with a MAC).

Fixes: f8330d0395 ("Added a libsimaka library with shared message handling code for EAP-SIM/AKA")
2026-07-24 08:47:38 +02:00
Tobias Brunner f4798de88c pkcs11: Avoid race condition in token hot-plug handling
If a token is removed during initialization, where `token_event_cb()` is
called manually, the callback could be triggered after the credential set
was added to the list but before it was registered with the manager.
This could then cause a use-after-free if the manager accesses it after
the other thread destroyed it.  Note that there is still a race if the
removal runs before the other thread even acquires the mutex.  We'd end
up with a registered but defunct credential set that is not backed by a
valid token.  But that shouldn't cause any crashes.

Fixes: a6d2ec331b ("Implemented a credential set on top of a PKCS#11 token")
2026-07-24 08:47:38 +02:00
Tobias Brunner a4a123eb4f hasher: Avoid theoretical memory leaks for hashers that could potentially fail
These `get_hash()` implementations could potentially fail (realistically
only for serious system errors like OOM).  This change ensures we comply
with the documented behavior (i.e. only allocate memory on success), as
no callers currently expect they have to clean up on failure.
2026-07-24 08:47:38 +02:00
Tobias Brunner 4d843d3da8 pkcs11: Fix memory leak in the hasher_t implementation
If state was stored (for incremental hashing), the allocated memory was
leaked.  Added some limits for the allocation and use chunk_t to simplify
it.  The state is now also wiped just to be safe.

Also removed the useless mutex.  If the goal was to protect access
to the hasher from multiple threads, then no other hasher currently
implements such protection.  And if the idea was to serialize access to
the token (i.e. only allow a single hasher to concurrently load its state
into the token and update it), then a per-hasher mutex was not the right
approach.  If that was the reason, we'd need a token-level mutex that
all hashers shared.  Should `get_hash()` fail due to such an issue with
a transient error (e.g. `CKR_DEVICE_MEMORY`), we now at least don't leak
memory from `allocate_hash()`.

Fixes: 6e4f4d2fdf ("Save/Load state of PKCS#11 hasher")
2026-07-24 08:47:37 +02:00
Tobias Brunner 09d48b73f4 tls-eap: Only process ACKs on the server after processing an actual packet
This prevents us from calling build() before ever calling process() on
a server-side EAP method that might not expect that.
2026-07-24 08:47:37 +02:00
Tobias Brunner fd7fccabe8 tls-eap: Reject EAP Start packets from clients
The Start flag should only be set in the first packet from server to
client so we never should process one received from a client.
2026-07-24 08:47:37 +02:00
Tobias Brunner f1c70a04d5 tnccs-dynamic: Add missing checks for underlying TNCCS instance
In order for the TNCCS instance to get created, `process()` has to be
called first.  However, if the client responds to the initial request
with an empty EAP packet, `tls_eap_t` interprets that as acknowledgement
and directly calls `build_pkt()`, which attempts to call `build()` here
and triggers a NULL-pointer dereference.  Similarly, `process()` is
skipped if the client sends an EAP packet that has the EAP_TLS|PT_START
flag set.

The `get_pdp_server()` method is called when the EAP-TNC method that
owns this instance is destroyed and would likewise trigger a crash if
e.g. the client never responded and the EAP-TNC instance is destroyed
without `process()` ever being called.

Fixes: f652995b21 ("implemented dynamic detection of TNCCS protocol")
2026-07-24 08:47:37 +02:00
Tobias Brunner 313d1ef88a watcher: Properly handle conflict during concurrent FD removal
If an FD we intend to remove is currently busy in a callback, we wait
on a condvar to retry later.  If the FD is not the first in the list,
`prev` will be set to the previous entry in the list.  This is fine
when no other threads are concurrently removing FDs, the same entry will
be found on the next try and prev points to the same value again.
However, if other threads also remove one or more FDs and the initial FD
is now the first in the list `prev` should be NULL and not point to a
removed entry.

Fixes: b27663399b ("watcher: Avoid allocations due to enumerators")
2026-07-24 08:47:37 +02:00
Tobias Brunner 3ec8d3cff1 wolfssl: Use Absorb/SqueezeBlocks API for SHAKE-128/256 XOFs
This API is available since 5.5.1 (released in 2022) and allows us to
avoid the inefficient previous implementation (don't think it's worth
keeping that around for older versions).  Also added support for
SHAKE-128.  Note that the only user of SHAKE is the ml plugin nowadays
and since wolfSSL also provides ML-KEM, this might not actually
get used much.
2026-07-24 08:47:37 +02:00
Tobias Brunner e6dc515c97 Revert "nm: Pass back the username auth-dialog runs as to access ssh-agent socket"
This partially reverts commit d7608ca192.

This was not actually an improvement over just doing the access as root.
The auth-dialog is not run by NM directly.  Instead, it requests secrets
via DBus from anybody who implements the SecretAgent interface.  It's
then e.g. nm-applet who starts the auth-dialog.  But this can really be
anybody, i.e. it's easy to return arbitrary information to the plugin.
So we can't trust the returned username.  This means that we can't
improve the situation for system-wide connections that don't provide
a username from the config.

We keep resetting the cached agent socket that the commit also added.
2026-07-24 08:47:37 +02:00
Tobias Brunner 8efb533008 capabilities: Log warning if UID changes and no capability backend is compiled in
In this case, we preserve the complete set of capabilities not just the
ones we actually need.  Removing the `prctl()` call isn't an option as
the daemon wouldn't be functional without the capabilities.  But we now
warn users about this.  We also only call `prctl()` if we actually switch
to a non-zero UID, `has_capability()` in turn already checks that we are
running as root in the `!CAPABILITIES` case.

A similar warning has been added to the configure script if a user has
been set at compile time.
2026-07-24 08:47:37 +02:00
Tobias Brunner 47a583dfa2 socket-win: Bind the sockets exclusively
This prevents other processes from binding the same ports and
misusing the protocol/port-specific bypass rules installed in WFP to
bypass the VPN.

Fixes: 11e7d0677c ("socket-win: Install IKE bypass policies using bypass_socket()")
2026-07-24 08:47:37 +02:00
Tobias Brunner 2ed81ed53a eap-radius: Fix access to IKE_SA when sending interim updates
The previous code checked in the IKE_SA before using it again to
add attributes based on it to the interim update message.  This
change ensures the IKE_SA is only accessed while it is checked out.
The Acct-Status-Type attribute is still sent first, but the
Acct-Session-Id and Class attributes are now sent after the IKE
parameters, which shouldn't really matter, though.

Fixes: d019764ab6 ("Add support for RADIUS Interim accounting updates")
2026-07-24 08:47:37 +02:00
Tobias Brunner 588c7a80d1 array: Avoid issue when re-inserting existing element in value-based arrays
The insertion can cause the existing data to get reallocated/moved.  So
if the caller attempts to insert another copy of an existing element into
the array via its pointer, this can cause a undefined behavior or even
a use-after-free because the pointer might get invalid.

There is such a case in `mem_pool_t::get_existing()` since the referenced
commit.

Fixes: d4a0dd9f93 ("mem-pool: Fix issue with make-before-break reauth and multiple IKE_SAs")
2026-07-24 08:47:37 +02:00
Tobias Brunner 8b1f8e0e46 kernel-pfroute: Remove IP addresses from hashtable if interface disappears
Fixes: f80093e2ee ("kernel-pfroute: Delete interfaces on RTM_IFANNOUNCE/IFAN_DEPARTURE events")
2026-07-24 08:47:37 +02:00
Tobias Brunner 62a4cde4d0 constraints: Simplify policy constraint handling and fix some TODOs
The previous code was too strict in some respects but also contained
other flaws.

Let's start with the latter, the loop that checked requireExplicitPolicy
constraints didn't use the correct offset.  Because the subject wasn't
part of the list, it was one off (should have been `len - expl + 1`).
So the last relation was not checked.  However, that check was neither
necessary, nor correct anyway.  If a certificate didn't have policies or
mappings, it was accepted, so nothing was enforced in that case.  It also
didn't validate the policies to the root, it only looked at two immediate
siblings and basically checked their immediate consistency.  So whether
any policies were valid (i.e. would end up in a top-down built
`valid_policy_tree`) wasn't actually checked.  But as mentioned, such an
explicit check wasn't necessary anyway.

Because the only thing we care about is collecting valid policies in the
subject to match against configs.  So we implicitly enforce any
requireExplicitPolicy constraints by enumerating and validating them.
And while we don't reject certificates with invalid policies anymore
since 69232e2d3d ("constraints: Don't reject certificates with invalid
certificate policies"), we now require at least one valid policy in the
subject if a requireExplicitPolicy constraint applies to it.  For chains
where that's not the case, we still accept subjects without any valid
policy.

Next, the enforcement of the inhibitPolicyMapping and inhibitAnyPolicy
constraints was too strict.  It checked the chain and rejected
certificates just if they encoded anyPolicy or policyMapping.  The RFC
only uses the constraints to disable their function at a certain depth.
This is now corrected by first calculating thresholds for the two
constraints and then applying them when validating policies in the
subject.

Another thing that was technically incorrect is that mappings between
anyPolicy were allowed.  It didn't have much of an effect because the
mapped issuerDomainPolicy is always checked against the same
certificate's policies (in the RFC, encoding that policy is a SHOULD,
so we are stricter here).

The tests that previously failed due to the latter were adapted, the
certificates are now accepted but the asserts make sure the policy is
missing.  New and updated tests cover more edge cases, some make use
of new helpers that allow encoding two policies, checking how multiple
policies are handled.

The policy violation hook now also receives the subject certificate as
it's that certificate's missing/invalid policies that trigger it.
2026-07-24 08:47:37 +02:00
Tobias Brunner 2dfc1ac1a8 pts: Fix potential crash when resolving symlinks
When the passed path was longer than the local buffer, while still
passing the `opendir()` call (e.g. `/\0` followed by padding), the access
via original chunk length to write a final `/` wrote outside of the
buffer.  The same could happen later when adding directory names because
`path_len` was based on that same length.

Fixes: 2ea1dac203 ("libimcv: Support symlinks introduced by usrmerge")
2026-07-24 08:47:37 +02:00
Tobias Brunner fdf12edd85 imv-attestation: Fix log message when failing to store file measurement
Also fixes a double free in that case (the `break` only leaves the loop,
not the switch statement).

Fixes: 076aac7069 ("imv-attestation: Fixed file hash measurements")
2026-07-24 08:47:37 +02:00
Tobias Brunner ca4db3c512 pts-database: Update reference file measurements as hex and not binary
This ensures consistent behavior for inserts and updates.
2026-07-24 08:47:37 +02:00
Tobias Brunner 4be1883303 pts-database: Reject reference file measurements with incorrect size
If the received measurement hash exceeded 64 bytes, the `hex_meas_buf`
buffer overflowed in the `chunk_to_hex()` call.   Since this is only
called when collecting measurements from a trusted reference system,
it shouldn't be an issue in practice.

Fixes: 076aac7069 ("imv-attestation: Fixed file hash measurements")
2026-07-24 08:47:37 +02:00
Tobias Brunner 383b4cb0fc aesni: Make sure the CPU supports SSSE3
There are no real CPUs that support AES-NI/PCLMULQDQ but don't support
SSSE3.  However, in VMs the vCPU features might not exactly match those
of the underlying CPU.  So if SSSE3 is missing, the PSHUFB instruction
would cause a SIGILL.  The referenced commit is the first one that uses
the `_mm_shuffle_epi8` intrinsic.

Fixes: 74d43cbde9 ("aesni: Implement a AES-NI based CTR crypter using the key schedule")
2026-07-24 08:47:37 +02:00
Tobias Brunner e37aac7b4f ldap: Replace deprecated function calls and support LDAPS
The use of the deprecated `ldap_init()` meant that LDAPS, although
announced by the plugin, was not actually supported.  The plugin just
always used a plaintext connection.  Now we use the current API and
get support for LDAPS (requires a bit of an awkward URI construction).
Based on the URI's scheme we also set an option to enforce a certificate
check.  The new NEWCTX option creates a connection-specific TLS context.
Without that we get a global default context once bind is called that is
not freed until the daemon exits (it leaks in LD and also seems unsafe
in regards to multiple threads fetching CRLs via LDAP).

Fixes: 552cc11b1f ("merged the modularization branch (credentials) back to trunk")
Fixes: 8c06e9c0ed ("added #define LDAP_DEPRECATED in order to use old ldap_init() function")
2026-07-24 08:47:37 +02:00
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 8ae96ed798 sec-updater: Use process_t to avoid potential command injection
Since the version passed to the `dpkg` command comes from a local
`Packages` file, it is presumably trusted.  But if the script is called
on a random file or the attacker can control its contents, it might be
possible to inject commands.
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 4e7ade053e keymat_v2: Explicitly clear key derived during EAP/PSK authentication 2026-07-24 08:47:37 +02:00
Tobias Brunner 7a1c801512 vici: Also wipe cached PINs during clear-creds command
The PINs are not necessary anymore when we remove all loaded private keys.

Fixes: 2ceeb96db5 ("vici: Add command to load a private key from a token")
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 d3d7a27e46 eap-aka-3gpp: Fix length when logging AUTS and increase some log levels 2026-07-24 08:47:36 +02:00
Tobias Brunner 7a215e568e eap-aka-3gpp2: Log potentially sensitive material on level 4
Leave stuff that's exchanged publicly (e.g. RAND, AUTN) at level 3.
2026-07-24 08:47:36 +02:00
Tobias Brunner b31ce69722 eap-ttls: Add an upper bound for the length of the parsed AVP
On typical systems that have overcommitting enabled, the 16 MiB maximum
that's allocated via the 24-bit length field in the AVP header shouldn't
be an issue as there are various limits that affect how much data can
actually be written to the allocated buffer (e.g. the maximum IKE message
size, the maximum TLS record size, or the maximum number of accepted
EAP-TTLS payloads), so this is primarily a defense-in-depth measure.

The length field of an EAP payload, which is the only type of AVP we
accept, is 16 bits, so that's what we now enforce as maximum.
2026-07-24 08:47:36 +02:00
Tobias Brunner 43584ad981 ike-sa-manager: Fix some inaccuracies in the header file 2026-07-24 08:47:36 +02:00
Tobias Brunner 207ae20aa6 mediation-manager: Avoid potential use-after-free when checking online status
This is unlikely to be an issue in practice because only one caller
actually uses the ID and it does so immediately afterwards.  So there is
only a tiny window in which the peer could terminate or rekey its SA to
cause the returned ID to get destroyed.

Fixes: d5cc175833 ("experimental P2P-NAT-T for IKEv2 merged back from branch")
2026-07-24 08:47:36 +02:00
Tobias Brunner c485080958 connmark: Fix undefined shift if traffic selector is /0
Same as the previous commit for consistency, but not an issue here as
only transport mode SAs are handled.

Fixes: b8973b2661 ("connmark: Add CONNMARK rules to select correct output SA based on conntrack")
2026-07-24 08:47:36 +02:00
Tobias Brunner 117cf65030 forecast: Fix undefined shift if traffic selector is /0
Not an issue in typical scenarios where the plugin is used on a gateway
with roadwarriors that use /32 addresses.  But could be an issue if used
on a client that tunnels everything to the gateway.

Fixes: e5ad2e6614 ("forecast: Add the broadcast/multicast forwarding plugin called forecast")
2026-07-24 08:47:36 +02:00
Tobias Brunner d5e7426c4c ikev1: Fix arguments when logging a UNITY_LOAD_BALANCE with invalid address
Fixes: eff331f799 ("Parse IKEv1 Cisco Load Balancing notify (can't act on it yet).")
2026-07-24 08:47:36 +02:00
Tobias Brunner 65a30f7bab child-create: Fix crash when responder doesn't send TS payloads
There are multiple paths that can trigger a crash.  One is if transport
mode is negotiated via NAT and `get_transport_nat_ts()` is called to
substitute addresses in the received TS.  If that's not the case,
`narrow_ts()` will select the configured TS and continue.  Then,
`narrow_and_check_ts()` eventually attempts to destroy `this->tsi/tsr`,
which triggers a crash in any case.

The referenced commit refactored `select_and_install()` into
`narrow_and_check_ts()` and `install_child_sa()`.  It move a check
for TS from that function to only `build_r()`.

Fixes: d7760416d6 ("child-create: Add support for multiple key exchanges")
2026-07-24 08:47:36 +02:00
Tobias Brunner 4611f41b1e child-rekey: Only reset state of SAs not actively rekeyed if passive rekeying fails 2026-07-24 08:47:36 +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 6b58665697 kernel-wfp: Uninstall policies before deleting provider
The policies reference the provider, so it might not actually get removed
and be left dangling in the WFP system (maybe Windows refcounts it and
still removes it).
2026-07-24 08:47:36 +02:00
Tobias Brunner 5e89dd5c4d tls-crypto: Reject signature schemes not actually defined for current TLS version
Also adds a filter for the locally configured signature schemes that are
already used when sending the supported schemes.
2026-07-24 08:47:36 +02:00
Tobias Brunner c720ae2307 pts-file-meas: Fix mismatch between hash buffer size and largest possible hash
With the referenced commit, SHA-512 was added as a possible hash
function, but the buffer was not adjusted accordingly.

Fixes: 3ef5b23903 ("pts: Variable size PCR banks")
2026-07-24 08:47:36 +02:00
Tobias Brunner 2c65dacf60 me: Avoid crash when processing endpoint with invalid NO_FAMILY
Such endpoints are used to request a peer reflexive endpoint, but are
never expected in a response.

Fixes: d5cc175833 ("experimental P2P-NAT-T for IKEv2 merged back from branch")
2026-07-24 08:47:36 +02:00
Tobias Brunner d8c7fe0634 connect-manager: Ignore connectivity checks for incomplete checklists
This could cause a crash due to signature verification with missing
key (although, memcpy() likely just returns with length 0), but it
also makes the signature predictable as the key is omitted.

Fixes: d5cc175833 ("experimental P2P-NAT-T for IKEv2 merged back from branch")
2026-07-24 08:47:36 +02:00
Tobias Brunner dd94e8d70e systime-fix: Unregister validator also if time got valid
This avoids accepting expired certificates again should the time get
rolled back for some reason.

Fixes: c81b87ac26 ("systime-fix: Add timeout option to stop waiting for valid system time")
Fixes: 295e42a47f ("systime-fix disables certificate lifetime validation if system time not synced")
2026-07-24 08:47:36 +02:00
Tobias Brunner be4b9f4aaa xauth-pam: Properly initialize response array when handling sessions
This is documented as a requirement in the man page, so the caller of the
conversation function might expect such an array.  Although, since we
only accept non-interactive requests, for which no response is expected,
it's doubtful whether it will actually try to access elements in the
array.  And if the passed pointer was initialized to NULL, passing it to
free() is probably also fine.

Fixes: 2312504d1e ("xauth-pam: Open/close a PAM session for each connected client")
2026-07-24 08:47:36 +02:00
Tobias Brunner 66f0f3a599 kernel-netlink: Add some safety checks when printing extended error messages
The previous code could potentially cause out-of-bound reads.

Fixes: 7988aea7d8 ("kernel-netlink: Log extended ACK error/warning messages")
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 c3b99c6982 ip-packet: Properly skip IPv6 fragment headers
Only skip the header, the `ip6e_len` field is reserved in these headers
and does not represent the length (I guess it's usually 0, but still).

Fixes: bdcaca76c5 ("ip-packet: Correctly determine protocol in fragmented IPv6 packets")
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 dafb082ae0 libtls: Check padding and MAC in constant time
Seems difficult to exploit when wrapped in EAP/IKEv2, and the keys for
those TLS sessions are short-lived anyway.

Fixes: c0bf721357 ("tls: Check all bytes of the padding if they equal the padding length")
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 db3f4c2955 eap-radius: Avoid NULL-pointer dereference in XAuth backend
Fixes: c434b2a4a9 ("eap-radius: support plain XAuth RADIUS authentication using User-Password")
2026-07-24 08:47:35 +02:00
Tobias Brunner 9965a64723 ike-me: Fix safety check to ensure peer ID payload in ME_CONNECT request
The presence of a peer ID is enforced by the message rules for ME_CONNECT,
this just mirrors the safety check also present in `process_r_ms()`.

Fixes: d5cc175833 ("experimental P2P-NAT-T for IKEv2 merged back from branch")
2026-07-24 08:47:35 +02:00
Tobias Brunner 4feb31d0e6 tls-peer: Fix memory leak when processing Finished messages with TLS 1.3 fails
Fixes: 7a2b02667c ("libtls: Implement TLS 1.3 handshake on client-side")
2026-07-24 08:47:35 +02:00
Tobias Brunner be0ee2e806 tls-server: Fix memory leaks when processing certificates or Finished messages
Fixes: 7fbe2e27ec ("tls-server: TLS 1.3 support for TLS server implementation")
Fixes: d2fc9b0961 ("tls-server: Mutual authentication support for TLS 1.3")
Fixes: 760f3b730f ("tls-server: Add flag that makes client authentication optional")
2026-07-24 08:47:35 +02:00
Tobias Brunner b031cd27a8 connmark: Fix addresses when removing policies in ike_update() handler
These were never correct.  And the first referenced commit, unfortunately,
just simplified the incorrect code.

Fixes: 08a3ee0cce ("bus: Change ike_update() signature and only call it once")
Fixes: b8973b2661 ("connmark: Add CONNMARK rules to select correct output SA based on conntrack")
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 289d776904 dhcp: Make sure to only modify transactions after receiving an expected DHCP OFFER
The `transaction` variable was previously still set to the one that
was enumerated last even if the received DHCP OFFER did not match
it.  So the transaction was incorrectly modified.  Once the real
DHCP OFFER would arrive, it would get modified again, but it could
allow adding unintended DNS servers.
2026-07-24 08:47:35 +02:00
Tobias Brunner 8c696dc90a proposal-substructure: Avoid unaligned memory access when reading SPI 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 d19591edda charon-tkm: charon: Avoid potential TOCTOU issues when accessing/writing PID file
Same as the previous commit.
2026-07-24 08:47:35 +02:00
Tobias Brunner 18a104657e charon: Avoid potential TOCTOU issues when accessing/writing PID file
The previous code could potentially truncate and change ownership of
a file that's a symlink to an unintended target file (requires the
attacker to be able to create the symlink in the directory the PID file
is located, which generally requires root privileges).
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