]> git.ipfire.org Git - thirdparty/strongswan.git/log
thirdparty/strongswan.git
2 days agowindows: Avoid potential races with canceling threads master
Tobias Brunner [Tue, 28 Jul 2026 09:51:16 +0000 (11:51 +0200)] 
windows: Avoid potential races with canceling threads

The previous code did not synchronize some of the flags, so it was
possible that `cancel()` did not work properly (e.g. no APC queued).

This change uses atomics to set/read the flags, it also avoids using
the global thread lock for synchronization as getting the condvar before
queuing the APC avoids having to sync with `docancel()`.  However, to
make sure we don't use a stale and potentially already freed condvar
when the thread is canceled a new lock is added and held until the
condvar has been signaled (using atomics for that member doesn't work as
the ordering rules enforced by atomics can not avoid that the thread in
`cancel()` potentially reads a stale value, or the race between reading
and signaling it).

2 days agoatomics: Add helpers to atomically load/store bools
Tobias Brunner [Tue, 28 Jul 2026 09:22:23 +0000 (11:22 +0200)] 
atomics: Add helpers to atomically load/store bools

2 days agovici: Make IKEv2 the default IKE version
Tobias Brunner [Fri, 24 Jul 2026 14:34:41 +0000 (16:34 +0200)] 
vici: Make IKEv2 the default IKE version

We don't want to accept IKEv1 clients anymore by default, so we also
warn them about it in the log.

6 days agoconfigure: Disable IKEv1 support by default
Tobias Brunner [Fri, 24 Jul 2026 14:24:42 +0000 (16:24 +0200)] 
configure: Disable IKEv1 support by default

The protocol has long been replaced by IKEv2 and is officially deprecated
since several years (RFC 9395).  As a first step to removing support for
it completely, this makes the configure option disabled by default and
warns users about its use.

7 days agotnccs-dynamic: Remove unused plugin
Tobias Brunner [Fri, 24 Jul 2026 13:43:20 +0000 (15:43 +0200)] 
tnccs-dynamic: Remove unused plugin

With only TNCCS-2.0 supported, there is no need for this plugin.

7 days agotnccs-11: Remove legacy TNCCS-1.1 implementation
Tobias Brunner [Fri, 24 Jul 2026 13:39:06 +0000 (15:39 +0200)] 
tnccs-11: Remove legacy TNCCS-1.1 implementation

There is no reason to keep this around anymore (has been superseded by
TNCCS-2.0 a long time ago).  Removed the corresponding test scenarios.

Since this is the last user of libxml, also removed those references.

7 days agotnc-ifmap: Remove prototypical IF-MAP plugin
Tobias Brunner [Fri, 24 Jul 2026 13:33:35 +0000 (15:33 +0200)] 
tnc-ifmap: Remove prototypical IF-MAP plugin

This was primarily used in our labs to visualize some TNC aspects but
the third-party daemon and frontend we used have not seen any development
in a decade.  There never was any industry interest in this protocol
anyway, so just remove it.

7 days agosoup: Remove limited fetcher plugin
Tobias Brunner [Fri, 24 Jul 2026 13:27:12 +0000 (15:27 +0200)] 
soup: Remove limited fetcher plugin

Besides the relatively recent update to libsoup-3, this has not seen
much development and lacks several features.  There does not seem to be
any advantage over using the curl plugin.  So just remove it to reduce
the maintenance burden.

7 days agogcrypt: Remove limited crypto plugin
Tobias Brunner [Fri, 24 Jul 2026 13:15:30 +0000 (15:15 +0200)] 
gcrypt: Remove limited crypto plugin

This has not seen any significant changes for years.  So it lacks support
for modern algorithms and would require quite some work for an overhaul.
Given that we support several other crypto backends, let's just remove
this to reduce the maintenance burden.

The test scenarios and other references are also removed.

7 days agoaf-alg: Remove plugin for deprecated AF_ALG interface
Tobias Brunner [Fri, 24 Jul 2026 13:12:03 +0000 (15:12 +0200)] 
af-alg: Remove plugin for deprecated AF_ALG interface

The 7.2 kernel has officially deprecated the interface and it will soon
be removed (support for hardware crypto offload has already been removed).

Also removed the corresponding test scenarios.

9 days agopadlock: Remove legacy hardware crypto plugin
Tobias Brunner [Fri, 24 Jul 2026 13:06:10 +0000 (15:06 +0200)] 
padlock: Remove legacy hardware crypto plugin

Unlikely there is even still hardware that would support this.

Also removed the CPU feature detection for these chips.

9 days agoled: Remove unused plugin
Tobias Brunner [Fri, 24 Jul 2026 13:03:58 +0000 (15:03 +0200)] 
led: Remove unused plugin

This was originally developed for a custom device.  No known users for
years.

9 days agoduplicheck: Remove confusing plugin
Tobias Brunner [Fri, 24 Jul 2026 12:56:13 +0000 (14:56 +0200)] 
duplicheck: Remove confusing plugin

This plugin was developed for a customer who had very specific
requirements.  It never did anything useful for regular users and
usually caused confusing errors if they enabled it by mistake.  So
just remove it.

9 days agoblowfish: Remove legacy Blowfish implementation
Tobias Brunner [Fri, 24 Jul 2026 12:52:13 +0000 (14:52 +0200)] 
blowfish: Remove legacy Blowfish implementation

There is no reason to use Blowfish nowadays.  Given that there are some
other plugins that still provide it, there is especially no reason to
maintain this custom implementation.  Also removed the two test scenarios
that used the plugin to avoid promoting the use of this algorithm.

10 days agoandroid-dns: Remove legacy Android DNS plugin
Tobias Brunner [Fri, 24 Jul 2026 12:48:23 +0000 (14:48 +0200)] 
android-dns: Remove legacy Android DNS plugin

This was written for the original native Android port.  It was never used
by the later Android app.

10 days agokeychain: Remove unused macOS KeyChain plugin
Tobias Brunner [Fri, 24 Jul 2026 12:41:43 +0000 (14:41 +0200)] 
keychain: Remove unused macOS KeyChain plugin

The macOS frontend was the only user of this plugin.

10 days agocharon-xpc: Remove prototypical macOS application
Tobias Brunner [Fri, 24 Jul 2026 12:39:18 +0000 (14:39 +0200)] 
charon-xpc: Remove prototypical macOS application

This has been deprecated for years.  As there are several potential
(security) issues, just remove the code.

10 days agolibfast: Remove FastCGI application server library
Tobias Brunner [Fri, 24 Jul 2026 12:31:10 +0000 (14:31 +0200)] 
libfast: Remove FastCGI application server library

The two users (manager, medsrv) are gone, so there is no reason to keep
this around.

10 days agomedsrv/medcli: Remove prototypical medsrv web application and plugins
Tobias Brunner [Fri, 24 Jul 2026 12:21:44 +0000 (14:21 +0200)] 
medsrv/medcli: Remove prototypical medsrv web application and plugins

This was from a student project that has never been developed further.
And similar to the manager web application it lacks all sorts of modern
standards.  So just remove it and the two plugins it relied on.

The test scenario is renamed to avoid confusion (neither of the two
p2pnat scenarios uses medsrv/medcli).

10 days agosmp: Remove legacy configuration/control interface
Tobias Brunner [Fri, 24 Jul 2026 12:15:24 +0000 (14:15 +0200)] 
smp: Remove legacy configuration/control interface

This has been replaced by VICI years ago, the only remaining user was
the manager.  So remove this as well.

10 days agomanager: Remove legacy PoC manager web application
Tobias Brunner [Fri, 24 Jul 2026 12:12:16 +0000 (14:12 +0200)] 
manager: Remove legacy PoC manager web application

This has not been developed for years and as far as web applications
go it has some serious (security) issues.  So just remove it.

10 days agofile-logger: Prevent potential race when opening log files and change permission
Tobias Brunner [Fri, 24 Jul 2026 10:35:23 +0000 (12:35 +0200)] 
file-logger: Prevent potential race when opening log files and change permission

This fixes a potential TOCTOU issue with opening log files.  The use of
`chown()` instead of `fchown()` could theoretically allow modifying the
ownership of an unintended file.

The log file now also is not world-readable anymore.

Also, the patch fixes the log groups for the two `(f)chown()` errors.

Fixes: d35d6691807d ("Make syslog and file loggers configurable at runtime")
10 days agotpm-tss-trousers: Add missing log argument if AIK private key is not found
Tobias Brunner [Thu, 23 Jul 2026 13:21:21 +0000 (15:21 +0200)] 
tpm-tss-trousers: Add missing log argument if AIK private key is not found

10 days agoRevert "Recognize critical IssuingDistributionPoint CRL extension"
Tobias Brunner [Thu, 23 Jul 2026 12:58:18 +0000 (14:58 +0200)] 
Revert "Recognize critical IssuingDistributionPoint CRL extension"

It might not be a good idea to blindly accept such extensions.  A scoped
CRL could be accepted for the wrong scope.  So just reject them again.

This reverts commit 126778679f9edc8ff2de38feddaf84759936939d.

10 days agoauth-cfg: Avoid overflow when checking key strength compliance
Tobias Brunner [Thu, 23 Jul 2026 10:39:03 +0000 (12:39 +0200)] 
auth-cfg: Avoid overflow when checking key strength compliance

The enumerator strictly handles pointers to pointers, so passing a
`u_int` is incorrect on 64-bit platforms.

Fixes: 918e92c4c9dc ("Support multiple different public key strength types in constraints")
10 days agosignature-params: Only modify passed params if parsing succeeded
Tobias Brunner [Thu, 23 Jul 2026 08:19:01 +0000 (10:19 +0200)] 
signature-params: Only modify passed params if parsing succeeded

This avoids issues if a caller doesn't expect e.g. the scheme to get
modified on failure.

10 days agochunk: Improve constant time comparison for chunks with unequal length
Tobias Brunner [Tue, 21 Jul 2026 09:52:46 +0000 (11:52 +0200)] 
chunk: Improve constant time comparison for chunks with unequal length

While for most uses the length is fixed and public (e.g. PRF/MAC outputs),
there are a few (e.g. in xauth-generic) that compare variable length
data.

The previous code directly leaked a differing length by short-circuiting
before comparing anything.  While we could limit the comparison by the
minimum length (and call `memeq_const()`), that could still leak the
length because the time will plateau once the secret's length is reached.
Similarly, if the comparison was bound by the longer chunk (would prevent
the use of `memeq_const()`), the length could also be revealed once the
input gets longer than the secret and the time increases.

This changes the semantics of the function by declaring the first
argument the expected/reference secret and the second the variable input.
This strictly makes the function constant-time, bound by the secret's
length.  So the length can't be guessed by providing different input (but
if an attacker can trigger the comparison against different secrets, of
potentially known lengths, it might still be possible).  If the chunks
are known to have the same length, the order doesn't matter.

Callers of this function have been updated accordingly.

10 days agoencrypted-payload: Do basic decryption check only once
Tobias Brunner [Mon, 20 Jul 2026 10:29:21 +0000 (12:29 +0200)] 
encrypted-payload: Do basic decryption check only once

The check only references the original chunk, so for each parsed payload
it checks the same thing.  The length of each individual payload is
checked by the parser anyway.  So I think this was primarily added for
the IKEv1 "wrong PSK" use case.  Let's keep it for now.

Fixes: dd5c3787dc38 ("Give a hint that decryption failed if payload length invalid")
10 days agopem: Avoid integer underflow when verifying padding after decryption
Tobias Brunner [Mon, 20 Jul 2026 10:05:31 +0000 (12:05 +0200)] 
pem: Avoid integer underflow when verifying padding after decryption

If the padding was larger than the whole blob, all available bytes were
checked for a match and the blob's length was eventually adjusted and
SUCCESS returned.  Due to the underflow this could result in a huge size
that would then get copied.  Zero-length padding was also incorrectly
accepted as was padding larger than the block size.

Fixes: 160f4c225db0 ("moved PEM parsing functionality to its own plugin")
10 days agoeap-ttls: Fix memory leaks in error cases related to EAP-Identity handling
Tobias Brunner [Mon, 20 Jul 2026 07:42:39 +0000 (09:42 +0200)] 
eap-ttls: Fix memory leaks in error cases related to EAP-Identity handling

Should be rare that the eap-identity plugin is not loaded when
authenticating clients with EAP.  And the second error path will
currently never get used as `process()` always succeeds.

Fixes: 79f2102cb442 ("implemented server side support for EAP-TTLS")
10 days agoprintf-hook-builtin: Avoid leaking stack contents when printing very long strings
Tobias Brunner [Tue, 14 Jul 2026 17:09:00 +0000 (19:09 +0200)] 
printf-hook-builtin: Avoid leaking stack contents when printing very long strings

Because `builtin_vsnprintf()` returns the length of the (theoretically)
produced string even if the buffer is too small, the `fwrite()` calls
would read past the buffer.  While it rarely happens that log messages
are even close to the current buffer size, it might get triggered by an
overlong IKE/EAP identity or similar.

For `vasprintf()`, the allocation for the complete required length is
now correctly handled (capped at `INT_MAX` as that's what
`builtin_vsnprintf()` can technically return).

Also fixed is an incorrect mapping of the return value of `fwrite()` in
case of an error.  While the latter returns the elements written so far,
the expected return value from `vfprintf()` is negative.

Fixes: cabe5c0ff40f ("printf-hook-builtin: Add a new "builtin" backend using its own printf() routines")
10 days agoml: Properly implement ByteDecode with d=12
Tobias Brunner [Tue, 14 Jul 2026 15:50:26 +0000 (17:50 +0200)] 
ml: Properly implement ByteDecode with d=12

I've overlooked the "m = q if d = 12" note in the pseudo-code for
Algorithm 6.  The text further up in the section actually clarifies
this:

  For d = 12, ByteDecode produces integers modulo q as output...(it)
  converts each 12-bit segment of its input into an integer modulo 4096
  and then reduces the result modulo q. This is no longer a one-to-one
  operation.

This did not have any practical impact (other than accepting public keys
that are technically non-compliant) because the values would get properly
reduced anyway by the Barrett reduction used in `mul_modq()`.

Fixes: 89f4b345e336 ("ml: Add software implementation of ML-KEM")
10 days agostroke: Avoid sharing a certificate printer between multiple clients
Tobias Brunner [Tue, 14 Jul 2026 14:01:13 +0000 (16:01 +0200)] 
stroke: Avoid sharing a certificate printer between multiple clients

If multiple clients call list commands concurrently, each would replace
the global certificate printer instance the previous client created
and then operate on shared state.  The destruction then causes a
double-free or NULL-pointer dereference.

Fixes: 02d431022c45 ("Refactored certificate management for the vici and stroke interfaces")
10 days agowindows: Fix potential use-after-free when joining a thread
Tobias Brunner [Tue, 14 Jul 2026 11:12:33 +0000 (13:12 +0200)] 
windows: Fix potential use-after-free when joining a thread

Because the flag was set before running the TLS cleanup, a thread
waiting in `join()` could exit the loop and destroy the thread object
before `docleanup()` is called in `end_thread()`.

This change removes the `terminated` flag and instead properly waits for
the thread to exit in `join()`.  By always removing the threads from the
hashtable in `end_thread()`, we also avoid requiring to check any flags
in `cleanup_tls()`, as it now only finds an object for external threads.

We now also make sure to call `docleanup()` before removing the thread
from the hashtable.  Otherwise, if a TLS cleanup callback calls
`thread_current[_id]()`, a new thread object would get created that is
never cleaned up.

Fixes: 0fa9c958114f ("windows: Provide a complete native Windows threading backend")
10 days agoiv-manager: Don't allow zero max_ikev1_exchanges
Tobias Brunner [Tue, 14 Jul 2026 10:27:05 +0000 (12:27 +0200)] 
iv-manager: Don't allow zero max_ikev1_exchanges

This would cause a use-after-free because `lookup_iv()` inserts, removes
and destroys the still returned entry.

Fixes: aeaab528e89c ("ikev1: Factor out IV and QM management")
10 days agofips-prf: Increase log level when logging secret state
Tobias Brunner [Mon, 13 Jul 2026 17:00:28 +0000 (19:00 +0200)] 
fips-prf: Increase log level when logging secret state

Fixes: f27f6296e6ae ("merged EAP framework from branch into trunk includes a lot of other modifications")
10 days agosha3: Fix applying second padding bit on big-endian platforms
Tobias Brunner [Mon, 13 Jul 2026 16:57:43 +0000 (18:57 +0200)] 
sha3: Fix applying second padding bit on big-endian platforms

Fixes: 56f4b2096aec ("sha3: Fix Keccak when compiled with GCC 13.x")
10 days agochild-sa-manager: Correctly remove replaced entry in lookup tables
Tobias Brunner [Mon, 13 Jul 2026 16:25:48 +0000 (18:25 +0200)] 
child-sa-manager: Correctly remove replaced entry in lookup tables

In the (very) unlikely case that a unique ID is reused (e.g. due to
counter wraparound) while the original SA is still in this manager,
the entries should properly get removed from the other lookup tables
before the entry is destroyed to prevent stale pointers from getting
used in later lookups.

Fixes: e732fb11a915 ("child-sa-manager: Add a global manager storing CHILD_SA relations")
10 days agoikev2: Make sure to correctly compare nonces of unequal length
Tobias Brunner [Mon, 13 Jul 2026 16:05:42 +0000 (18:05 +0200)] 
ikev2: Make sure to correctly compare nonces of unequal length

The previous code would not correctly compare nonces of unequal length
where the shorter is the prefix of the longer one.

10 days agochunk: Add utility that compares the prefix of two chunks
Tobias Brunner [Mon, 13 Jul 2026 16:00:26 +0000 (18:00 +0200)] 
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.

10 days agogcrypt: Fix zeroing padding when extracting RSA value from S-expression
Tobias Brunner [Mon, 13 Jul 2026 15:25:08 +0000 (17:25 +0200)] 
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: a2f1bb238ecc ("enforce correct RSA signature lenght in gcrypt")
10 days agoeap-sim-pcsc: Properly release context if determining list of readers fails
Tobias Brunner [Mon, 13 Jul 2026 15:14:12 +0000 (17:14 +0200)] 
eap-sim-pcsc: Properly release context if determining list of readers fails

Fixes: 80dca77a50ec ("Added SIM card backend based on pcsc-lite")
10 days agoeap-md5: Avoid memory leak caused by repeated challenges
Tobias Brunner [Mon, 13 Jul 2026 14:52:44 +0000 (16:52 +0200)] 
eap-md5: Avoid memory leak caused by repeated challenges

Fixes: 4b403e7672a1 ("merged EAP-MD5 into trunk")
10 days agokernel-netlink: Properly clean up pending entry if VIP installation failed
Tobias Brunner [Mon, 13 Jul 2026 14:36:39 +0000 (16:36 +0200)] 
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: c6b401581a75 ("Changed how kernel-netlink handles virtual IP addresses")
10 days agoha: Fix offset checks in HA address pool
Tobias Brunner [Mon, 13 Jul 2026 14:10:39 +0000 (16:10 +0200)] 
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: 98d03438706f ("Implemented a HA enabled in-memory address pool")
10 days agomem-pool: Enforce size limit also for range-based pools and fix overflow
Tobias Brunner [Mon, 13 Jul 2026 13:16:15 +0000 (15:16 +0200)] 
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: 0897cda33b63 ("Add a constructor to create in-memory pools from an address range")
10 days agoxauth-pam: Use proper method to read session option
Tobias Brunner [Sun, 12 Jul 2026 18:27:44 +0000 (20:27 +0200)] 
xauth-pam: Use proper method to read session option

10 days agonm: Fix double-free of IKE config in error cases and some leaks and potential NULL...
Tobias Brunner [Sun, 12 Jul 2026 17:47:30 +0000 (19:47 +0200)] 
nm: Fix double-free of IKE config in error cases and some leaks and potential NULL dereferences

10 days agoopenssl: Fix memory leak when verifying plain RSA signatures with old BoringSSL versions
Tobias Brunner [Sun, 12 Jul 2026 17:24:30 +0000 (19:24 +0200)] 
openssl: Fix memory leak when verifying plain RSA signatures with old BoringSSL versions

Fixes: 21b586c61c95 ("openssl: Fixes for RSA with OpenSSL 3.0")
10 days agopt-tls-client: Don't store PT-TLS message on stack
Tobias Brunner [Thu, 23 Jul 2026 14:54:48 +0000 (16:54 +0200)] 
pt-tls-client: Don't store PT-TLS message on stack

Basically the same as the previous commit.

10 days agopt-tls-server: Don't store PT-TLS message on stack
Tobias Brunner [Sun, 12 Jul 2026 17:15:31 +0000 (19:15 +0200)] 
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.

10 days agovici: Fix leak if selectors for redirect command are missing or invalid
Tobias Brunner [Sun, 12 Jul 2026 17:05:02 +0000 (19:05 +0200)] 
vici: Fix leak if selectors for redirect command are missing or invalid

Fixes: 43b46b26ea1e ("vici: Add redirect command")
10 days agoshunt-manager: Fix potential race between install and uninstall
Tobias Brunner [Sun, 12 Jul 2026 16:22:58 +0000 (18:22 +0200)] 
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
69cbe2ca3fe4 ("trap-manager: Wait for install to finish before
uninstalling").

Fixes: 616ff9a2369f ("shunt-manager: Remove stored entries if installation fails")
10 days agopem: Properly handle encrypted PEM files without DEK-Info
Tobias Brunner [Sun, 12 Jul 2026 15:53:10 +0000 (17:53 +0200)] 
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: 160f4c225db0 ("moved PEM parsing functionality to its own plugin")
10 days agoandroid: Fix reading split-tunneling block settings in managed configs
Tobias Brunner [Sun, 12 Jul 2026 15:22:37 +0000 (17:22 +0200)] 
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: c2007d5b09a3 ("android: Add managed_configuration.xml")
10 days agovici: Fix memory leaks if loading CA cert in authority section fails
Tobias Brunner [Sun, 12 Jul 2026 15:18:47 +0000 (17:18 +0200)] 
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: 63d370387d41 ("vici: Certification Authority support added.")
10 days agoha: Fix memory leak if Child SA key derivation fails
Tobias Brunner [Sun, 12 Jul 2026 15:03:47 +0000 (17:03 +0200)] 
ha: Fix memory leak if Child SA key derivation fails

Fixes: aa334daa9bf3 ("Use a sync message cache to resynchronize IKE_SAs without rekeying")
10 days agoconnmark: Only install one rule per Child SA in PREROUTING
Tobias Brunner [Sun, 12 Jul 2026 14:57:27 +0000 (16:57 +0200)] 
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: b8973b266131 ("connmark: Add CONNMARK rules to select correct output SA based on conntrack")
10 days agocharon-tkm: Fix potential use-after-free in chunk map
Tobias Brunner [Sun, 12 Jul 2026 14:41:41 +0000 (16:41 +0200)] 
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.

10 days agosha3: Make sure state and rate input buffers are 8-byte aligned
Tobias Brunner [Sun, 12 Jul 2026 13:25:52 +0000 (15:25 +0200)] 
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: 5ff88c96228c ("xof: Implemented SHAKE128 and SHAKE256 Extended Output Functions")
Fixes: 83c1883d0bb0 ("Use word-aligned XOR in sha3_absorb()")
10 days agoike-auth: Enforce PPK required constraint on the initiator
Tobias Brunner [Fri, 10 Jul 2026 18:32:59 +0000 (20:32 +0200)] 
ike-auth: Enforce PPK required constraint on the initiator

Fixes: a9e60c96dc88 ("ike-auth: Add basic PPK support")
10 days agoike-init: Make sure we received a KE payload as initiator
Tobias Brunner [Fri, 10 Jul 2026 18:24:51 +0000 (20:24 +0200)] 
ike-init: Make sure we received a KE payload as initiator

On the responder, dc8b479eb890 ("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: 0d49ddec2ef5 ("ike-init: Add support for multiple key exchanges")
10 days agoMake sure KEM implementations don't return an empty shared secret
Tobias Brunner [Fri, 10 Jul 2026 18:14:10 +0000 (20:14 +0200)] 
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.

10 days agoandroid: Fix leak of JNI local ref in IMC when creating string array
Tobias Brunner [Fri, 10 Jul 2026 17:07:22 +0000 (19:07 +0200)] 
android: Fix leak of JNI local ref in IMC when creating string array

Fixes: 036fa7a16611 ("android: Overload for getMeasurement() that takes a String array as argument")
10 days agoxauth-generic: Make sure to only use secrets that match the username
Tobias Brunner [Fri, 10 Jul 2026 06:22:17 +0000 (08:22 +0200)] 
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: 462c9a4f72ec ("Try all matching XAuth secrets we find, not only the first one")
10 days agokernel-wfp: Add support for SA deletion in either order
Tobias Brunner [Thu, 9 Jul 2026 17:29:26 +0000 (19:29 +0200)] 
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: f351d9ef7d70 ("kernel-wfp: Reference SA/SP sets by SPI and destination, not reqid")
Fixes: 44107cb7b755 ("child-delete: Delay the removal of the inbound SA of rekeyed CHILD_SAs")
10 days agohost: Do some proper validation when parsing CIDR-style subnets
Tobias Brunner [Thu, 9 Jul 2026 16:46:20 +0000 (18:46 +0200)] 
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: 65697c27345b ("Added a CIDR notation based host constructor")
10 days agoeap-radius: Limit number of concurrently cached DAE responses
Tobias Brunner [Thu, 9 Jul 2026 15:01:53 +0000 (17:01 +0200)] 
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.

10 days agosimaka-message: Prevent buffer overflow when generating messages
Tobias Brunner [Thu, 9 Jul 2026 10:03:58 +0000 (12:03 +0200)] 
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: f8330d03953b ("Added a libsimaka library with shared message handling code for EAP-SIM/AKA")
10 days agopkcs11: Avoid race condition in token hot-plug handling
Tobias Brunner [Thu, 9 Jul 2026 05:31:24 +0000 (07:31 +0200)] 
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: a6d2ec331ba8 ("Implemented a credential set on top of a PKCS#11 token")
10 days agohasher: Avoid theoretical memory leaks for hashers that could potentially fail
Tobias Brunner [Wed, 8 Jul 2026 21:42:31 +0000 (23:42 +0200)] 
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.

10 days agopkcs11: Fix memory leak in the hasher_t implementation
Tobias Brunner [Wed, 8 Jul 2026 20:21:17 +0000 (22:21 +0200)] 
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: 6e4f4d2fdfca ("Save/Load state of PKCS#11 hasher")
10 days agotls-eap: Only process ACKs on the server after processing an actual packet
Tobias Brunner [Wed, 8 Jul 2026 18:29:02 +0000 (20:29 +0200)] 
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.

10 days agotls-eap: Reject EAP Start packets from clients
Tobias Brunner [Wed, 8 Jul 2026 17:28:23 +0000 (19:28 +0200)] 
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.

10 days agotnccs-dynamic: Add missing checks for underlying TNCCS instance
Tobias Brunner [Wed, 8 Jul 2026 16:36:56 +0000 (18:36 +0200)] 
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: f652995b2123 ("implemented dynamic detection of TNCCS protocol")
10 days agowatcher: Properly handle conflict during concurrent FD removal
Tobias Brunner [Wed, 8 Jul 2026 14:54:28 +0000 (16:54 +0200)] 
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: b27663399b4b ("watcher: Avoid allocations due to enumerators")
10 days agowolfssl: Use Absorb/SqueezeBlocks API for SHAKE-128/256 XOFs
Tobias Brunner [Wed, 8 Jul 2026 14:27:29 +0000 (16:27 +0200)] 
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.

10 days agoRevert "nm: Pass back the username auth-dialog runs as to access ssh-agent socket"
Tobias Brunner [Wed, 8 Jul 2026 06:36:36 +0000 (08:36 +0200)] 
Revert "nm: Pass back the username auth-dialog runs as to access ssh-agent socket"

This partially reverts commit d7608ca1922152c07d5e3d4597c267cb84f0d7c0.

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.

10 days agocapabilities: Log warning if UID changes and no capability backend is compiled in
Tobias Brunner [Mon, 6 Jul 2026 13:27:16 +0000 (15:27 +0200)] 
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.

10 days agosocket-win: Bind the sockets exclusively
Tobias Brunner [Mon, 6 Jul 2026 09:46:23 +0000 (11:46 +0200)] 
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: 11e7d0677c3e ("socket-win: Install IKE bypass policies using bypass_socket()")
10 days agoeap-radius: Fix access to IKE_SA when sending interim updates
Tobias Brunner [Mon, 6 Jul 2026 08:59:39 +0000 (10:59 +0200)] 
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: d019764ab626 ("Add support for RADIUS Interim accounting updates")
10 days agoarray: Avoid issue when re-inserting existing element in value-based arrays
Tobias Brunner [Mon, 6 Jul 2026 08:17:13 +0000 (10:17 +0200)] 
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: d4a0dd9f93d6 ("mem-pool: Fix issue with make-before-break reauth and multiple IKE_SAs")
10 days agokernel-pfroute: Remove IP addresses from hashtable if interface disappears
Tobias Brunner [Mon, 6 Jul 2026 06:43:14 +0000 (08:43 +0200)] 
kernel-pfroute: Remove IP addresses from hashtable if interface disappears

Fixes: f80093e2ee65 ("kernel-pfroute: Delete interfaces on RTM_IFANNOUNCE/IFAN_DEPARTURE events")
10 days agoconstraints: Simplify policy constraint handling and fix some TODOs
Tobias Brunner [Sat, 4 Jul 2026 17:25:10 +0000 (19:25 +0200)] 
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 69232e2d3dd1 ("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.

10 days agopts: Fix potential crash when resolving symlinks
Tobias Brunner [Fri, 3 Jul 2026 10:18:25 +0000 (12:18 +0200)] 
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: 2ea1dac2030d ("libimcv: Support symlinks introduced by usrmerge")
10 days agoimv-attestation: Fix log message when failing to store file measurement
Tobias Brunner [Fri, 3 Jul 2026 09:33:19 +0000 (11:33 +0200)] 
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: 076aac70693d ("imv-attestation: Fixed file hash measurements")
10 days agopts-database: Update reference file measurements as hex and not binary
Tobias Brunner [Fri, 3 Jul 2026 09:19:24 +0000 (11:19 +0200)] 
pts-database: Update reference file measurements as hex and not binary

This ensures consistent behavior for inserts and updates.

10 days agopts-database: Reject reference file measurements with incorrect size
Tobias Brunner [Fri, 3 Jul 2026 09:03:37 +0000 (11:03 +0200)] 
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: 076aac70693d ("imv-attestation: Fixed file hash measurements")
10 days agoaesni: Make sure the CPU supports SSSE3
Tobias Brunner [Fri, 3 Jul 2026 06:06:20 +0000 (08:06 +0200)] 
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: 74d43cbde999 ("aesni: Implement a AES-NI based CTR crypter using the key schedule")
10 days agoldap: Replace deprecated function calls and support LDAPS
Tobias Brunner [Thu, 2 Jul 2026 14:36:52 +0000 (16:36 +0200)] 
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: 552cc11b1f01 ("merged the modularization branch (credentials) back to trunk")
Fixes: 8c06e9c0edc5 ("added #define LDAP_DEPRECATED in order to use old ldap_init() function")
10 days agounbound: Make sure RRs match the queried or canonical name
Tobias Brunner [Thu, 2 Jul 2026 11:01:19 +0000 (13:01 +0200)] 
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: 5a4126b49009 ("unbound: Implemented resolver_response_t as unbound_response_t")
10 days agosec-updater: Use process_t to avoid potential command injection
Tobias Brunner [Wed, 1 Jul 2026 17:34:50 +0000 (19:34 +0200)] 
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.

10 days agokey-exchange: Rename function that verifies pubkey lengths
Tobias Brunner [Wed, 1 Jul 2026 08:33:13 +0000 (10:33 +0200)] 
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.

10 days agobotan: Remove confusing documentation for DH helper function
Tobias Brunner [Wed, 1 Jul 2026 08:21:41 +0000 (10:21 +0200)] 
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.

10 days agomysql: Be more explicit when parsing database URI but don't log password
Tobias Brunner [Mon, 29 Jun 2026 14:33:16 +0000 (16:33 +0200)] 
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.

10 days agopgp: Log parsed packet data on level 4 as it may contain a private key
Tobias Brunner [Mon, 29 Jun 2026 14:01:55 +0000 (16:01 +0200)] 
pgp: Log parsed packet data on level 4 as it may contain a private key

10 days agokeymat_v2: Explicitly clear key derived during EAP/PSK authentication
Tobias Brunner [Mon, 29 Jun 2026 13:46:52 +0000 (15:46 +0200)] 
keymat_v2: Explicitly clear key derived during EAP/PSK authentication

10 days agovici: Also wipe cached PINs during clear-creds command
Tobias Brunner [Mon, 29 Jun 2026 13:41:08 +0000 (15:41 +0200)] 
vici: Also wipe cached PINs during clear-creds command

The PINs are not necessary anymore when we remove all loaded private keys.

Fixes: 2ceeb96db51a ("vici: Add command to load a private key from a token")
10 days agocurve25519: Explicitly wipe shared secret when destroying DH object
Tobias Brunner [Mon, 29 Jun 2026 13:32:05 +0000 (15:32 +0200)] 
curve25519: Explicitly wipe shared secret when destroying DH object

10 days agoeap-aka-3gpp: Fix length when logging AUTS and increase some log levels
Tobias Brunner [Sun, 12 Jul 2026 18:22:17 +0000 (20:22 +0200)] 
eap-aka-3gpp: Fix length when logging AUTS and increase some log levels