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: 02d431022c ("Refactored certificate management for the vici and stroke interfaces")
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: 0fa9c95811 ("windows: Provide a complete native Windows threading backend")
This would cause a use-after-free because `lookup_iv()` inserts, removes
and destroys the still returned entry.
Fixes: aeaab528e8 ("ikev1: Factor out IV and QM management")
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: e732fb11a9 ("child-sa-manager: Add a global manager storing CHILD_SA relations")
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.
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")
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")
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")
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")
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")
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")
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")
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.")
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")
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.
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()")
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")
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")
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")
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")
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")
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")
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.
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")
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")
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")
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.
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.
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.
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()")
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")
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")