Commit Graph
2456 Commits
Author SHA1 Message Date
seantywork 14cbe0bf24 whitelist: Fix deadlock when handling client disconnection
Calling stream_t::destroy from the stream_t::on_read callback will
block the thread in watcher_t::remove because the FD is currently "in
callback".  A similar issue was fixed in the lookip plugin with
961409b668 ("lookip: Disconnect asynchronously to avoid dead-locking
watcher unregistration").

Fixes: 85ebf6abd4 ("whitelist: Add error handling to socket reads and fix a memory leak")
2026-02-20 12:44:55 +01:00
Tobias Brunner 8a6f9ba70e kernel-netlink: Don't fallback to peer address as gateway/nexthop
This doesn't really seem useful (perhaps it was before we started to
configure the outbound interface on our routes). And it can actually
cause the route installation to fail e.g. for routes over point-to-point
interfaces where we'd get "Error: Nexthop has invalid gateway" errors.

Note that we can't return NULL if we find an interface as e.g. the updown
plugin uses this method to determine the outbound interface (it ignores
the nexthop), which it passes to the script.  If we returned NULL, it
would pass "unknown" instead, which would cause the firewall rules to
mismatch.  While it seems that 0.0.0.0/:: is ignored as nexthop by the
kernel on the installed route, I still explicitly ignore such addresses
to avoid any unintended side-effects.

The automatic route installation in the ikev2/shunt-manual-prio scenario
had to be disabled on the clients.  The reason is that the route in table
220 won't have a nexthop set (the peers are directly connected), so when
trying to reach alice or venus via SSH, which matches the port-specific
bypass policies for which we don't install throw routes, the hosts will
do ARP requests for the target IPs instead of routing the packets via
moon.

Closes strongswan/strongswan#2548
2026-02-20 12:44:55 +01:00
Tobias Brunner 116f36ba57 vici: Document attributes for additional KE methods in list-sa event 2026-02-20 12:44:55 +01:00
Tobias Brunner 22e502b286 vici: Make ICMP forwarding configurable 2026-02-12 15:33:44 +01:00
Tobias Brunner 11351f24ef kernel-netlink: Enable ICMP forwarding on inbound SA and out/fwd policies 2026-02-12 14:23:44 +01:00
Tobias Brunner f10b9adec9 ipsec-types: Add a proper hash function for ipsec_sa_cfg_t
While 3c12905103 ("ipsec: Add function to compare two ipsec_sa_cfg_t
instances") added a comparison function to avoid issues with non-zeroed
padding, hashes were still calculated using chunk_hash().
2026-02-12 14:23:44 +01:00
Tobias Brunner 79a52c488d dhcp: Don't release the address via DHCP if it's still used
This is useful during make-before-break reauthentication, where the
new SA is created before the old one is terminated and the virtual IP
gets released.

This also changes the hash() and equals() functions to avoid potential
collisions.

References strongswan/strongswan#2967
2026-02-05 17:57:01 +01:00
Tobias Brunner 9b0b1cb24e vici: Enforce maximum length for names when building a message
Otherwise, an integer overflow will shorten the name and cause
unpredictable outcomes.
2025-11-19 10:30:39 +01:00
Tobias Brunner c687ada6a6 eap-mschapv2: Fix length check for Failure Request packets on the client
For message lengths between 6 and 8, subtracting HEADER_LEN (9) causes
`message_len` to become negative, which is then used in calls to malloc()
and memcpy() that both take size_t arguments, causing an integer
underflow.

For 6 and 7, the huge size requested from malloc() will fail (it exceeds
PTRDIFF_MAX) and the returned NULL pointer will cause a segmentation
fault in memcpy().

However, for 8, the allocation is 0, which succeeds.  But then the -1
passed to memcpy() causes a heap-based buffer overflow (and possibly a
segmentation fault when attempting to read/write that much data).
Fortunately, if compiled with -D_FORTIFY_SOURCE=3 (the default on e.g.
Ubuntu), the compiler will use __memcpy_chk(), which prevents that buffer
overflow and causes the daemon to get aborted immediately instead.

Fixes: f98cdf7a47 ("adding plugin for EAP-MS-CHAPv2")
Fixes: CVE-2025-62291
2025-10-27 14:02:59 +01:00
Tobias Brunner 9ef637e782 eap-mschapv2: Fix length check for successful responses on the client
While wrong, this isn't an issue in practice as AUTH_RESPONSE_LEN is
long enough that subtracting HEADER_LEN is fine.

Fixes: f98cdf7a47 ("adding plugin for EAP-MS-CHAPv2")
2025-10-27 14:02:59 +01:00
Tobias Brunner ba2bc3f4fe vici: Add event listener of Python bindings to release tarball
Fixes: 4e065a9624 ("vici: Add decorators to Python bindings to simplify listening for events")
2025-10-24 15:15:45 +02:00
Tobias Brunner 4840507d7a vici: Allow callers of listen() to distinguish between disconnects and intended breaks 2025-10-08 16:53:01 +02:00
Tobias Brunner 8bfdf2fb60 vici: Export timeout in event listener of Python bindings
This allows running periodic tasks (e.g. check some outside condition)
and stop listening by raising the StopListening exception.
2025-10-07 09:22:40 +02:00
Tobias Brunner 79da117283 vici: Provide a way to stop listening and re-connect in Python bindings
This allows re-connecting to a new session in a disconnect listener and
continue listening without having to return from listen().  The exception
can also be used to stop listening after some condition (e.g. to wait
until a specific SA got created and then stop).
2025-10-07 09:22:38 +02:00
Tobias Brunner 4e065a9624 vici: Add decorators to Python bindings to simplify listening for events 2025-10-07 09:20:57 +02:00
Martin Willi d46529fe2d vici: Raise alert events from the bus alert listener hook
The bus alert infrastructure is currently exposed through the error-notify
plugin using a dedicated socket using a rather archaic message format.
Vici clients would need a dedicated socket connection just to receive such
alert messages, making their implementation more complex.

With vici, it is rather trivial to expose bus alerts through a dedicated
event message that vici clients may subscribe to. Add such an "alert"
event type to vici. Alert names are mapped to strings for simple consumption by
clients.

For now, the error-notify string message is omitted from events, as it mostly
contains static information without much value; instead add the IKE_SA details
for alerts associated to an IKE_SA. Other alert specific data may be added in
the future if needed; preferably using a structured format instead of the
arbitrary string messages used by error-notify. To allow future extensions,
wrap IKE_SA details under a dedicated "ike-sa" property.
2025-10-02 10:22:32 +02:00
Tobias Brunner 61daa338c7 vici: Remove deprecated license classifier in Python metadata 2025-10-01 19:08:34 +02:00
Tobias Brunner 5cab5672e7 Define plugin version in all existing plugins 2025-08-22 15:32:39 +02:00
Tobias Brunner 2f0a0fef3d vici: Fix indentation for some add_kv() calls 2025-08-22 15:22:33 +02:00
Mathias Aerts a24dc2e9ad vici: Include configured local and remote ports in list-conns
Closes strongswan/strongswan#2869
2025-08-22 15:22:13 +02:00
Tobias Brunner f02033664e vici: Add support for P-CSCF server attributes
Was apparently forgotten when support was added to the attr plugin
with 98a3ba8a5a ("attr: Add p-cscf keyword for P-CSCF server addresses").

For consistency, using an underscore like the `split*` options and not a
dash like in the attr plugin.

References strongswan/strongswan#2396
2025-08-21 16:04:39 +02:00
Tobias Brunner ff06159099 certexpire: Double size of internal buffer for identities
The error-notify, lookip, and whitelist (previous commit) plugins already
use the same buffer size for identities.
2025-07-23 18:50:53 +02:00
seantywork ae2e0b6cf2 whitelist: Double the length of the id field in the messages
Closes strongswan/strongswan#2842
2025-07-23 18:50:33 +02:00
Tobias Brunner 85ebf6abd4 whitelist: Add error handling to socket reads and fix a memory leak
This now adds some state (basically a message buffer), but simplifies
error handling as we don't have to handle two potential failure paths
and could avoid some potential issues by still calling the blocking
read_all().

It also fixes a memory leak when clients disconnect.
2025-07-18 12:07:45 +02:00
Rob Shearman 412231eecd whitelist: Use a watcher for control socket reading rather than blocking
Performing a stream read_all call (which is a blocking read) from
within the accept callback has the issue that if a whitelist client is
still connected whilst a shutdown of the charon deamon is triggered
then that shutdown won't complete gracefully due to the accept task
never exiting.

So fix shutting down gracefully by using the socket watcher rather than
a blocking read upon connection accept. Fall back to a blocking read
for partial messages to avoid the complexity associated (i.e. storing
state) for incomplete reads, which shouldn't block and cause the
original problem if the client only sends whole messages.
2025-07-15 14:50:56 +02:00
Tobias Brunner f88d824114 Fixed some typos, courtesy of codespell 2025-07-08 10:54:49 +02:00
Thomas Egerer a339468c93 vici: Allow backlog size configuration via compile option
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2025-07-07 14:20:13 +02:00
Tobias Brunner 6372b2890f kernel-netlink: Support IPTFS mode and attributes 2025-05-28 16:37:46 +02:00
Tobias Brunner 1afc76dd56 vici: Make IP-TFS mode configurable 2025-05-28 16:37:46 +02:00
Tobias Brunner e175abaf89 include: Add XFRM mode and attributes for IP-TFS 2025-05-28 16:37:46 +02:00
Tobias Brunner d83fbe82e4 kernel-netlink: Suppress NAT mapping updates for per-CPU SAs
As we set the remote port to 0, we'd get a mapping change message with
every packet. Setting the threshold avoids all kernel messages after the
first, which we suppress explicitly as well.
2025-05-28 16:35:27 +02:00
Tobias Brunner 73083503f2 vici: Make UDP encapsulation for per-CPU SAs configurable 2025-05-28 16:35:27 +02:00
Tobias Brunner c176d32a73 vici: Report per-CPU SA information 2025-05-28 16:35:27 +02:00
Tobias Brunner fbfae44dd1 vici: Make per-CPU CHILD_SAs configurable 2025-05-28 16:35:27 +02:00
Tobias Brunner a950ca3ec2 kernel-netlink: Forward CPU ID from acquires 2025-05-28 16:35:27 +02:00
Tobias Brunner d6eed3979b kernel-interface: Optionally pass CPU ID for which an acquire was triggered 2025-05-28 16:35:27 +02:00
Tobias Brunner 3a8bb93761 updown: Don't call the script for per-CPU SAs
Rules are installed for the fallback SA that has no CPU ID assigned.
2025-05-28 16:35:26 +02:00
Tobias Brunner 297be45275 ha: Ignore per-CPU CHILD_SAs
These only work on initiators (with trap policies), which is something
the plugin doesn't support.
2025-05-28 16:35:26 +02:00
Tobias Brunner 17f2188756 forecast: Ignore per-CPU CHILD_SAs
Not sure if this combination does make sense as the plugin itself would
be a major bottleneck.

Similar to the connmark plugin, PREROUTING rules list SPIs or UDP ports,
which would be necessary for all SAs while the OUTPUT rules would only be
required once.
2025-05-28 16:35:26 +02:00
Tobias Brunner 5faf884285 connmark: Ignore per-CPU CHILD_SAs
The combination probably doesn't make much sense.

The OUTPUT rules would definitely only be required once, while the INPUT
and PREROUTING rules list individual SPIs and/or UDP ports, which would
be necessary for all SAs.

By the way, the rules in PREROUTING might actually not be necessary
anymore if the set_mark_in option was used for such SAs.
2025-05-28 16:35:26 +02:00
Tobias Brunner a505f4b9b0 child-sa: Add support for per-CPU SAs
The CPU ID is also set on inbound SAs as it can be used to configure RSS
or some eBPF program.
2025-05-28 16:35:26 +02:00
Tobias Brunner bdfcfea1f2 kernel-netlink: Add support to enable per-CPU acquires on policies 2025-05-28 16:35:26 +02:00
Tobias Brunner 53be94d06c kernel-netlink: Add support to set CPU ID on SA 2025-05-28 16:35:26 +02:00
Tobias Brunner aa1322aed5 include: Add XFRM identifiers for per-CPU SAs/acquires 2025-05-28 16:35:26 +02:00
Tobias Brunner 6e274271af vici: Include reqid when listing trap policies 2025-05-28 10:11:53 +02:00
Tobias Brunner 5624f7ffaa kernel-pfkey: Don't use TS from acquire in tunnel mode
The addresses are actually the endpoints of the SA, not information on
the matched packet (except that the RFC says to set the ports and
protocol of the packet in the source address, which the Linux kernel
doesn't do).  So these are useless, unless transport mode is used, where
the addresses are needed for the wildcard trap policy use case.

The RFC mentions a PROXY address (a single one, not two), that could
apparently be something like the source address in tunnel mode.
However, the description of how this is used in the RFC is quite weird
and neither Linux nor FreeBSD send such an attribute in SADB_ACQUIRE.
2025-05-28 10:11:53 +02:00
Tobias Brunner b024b7e9a6 kernel-netlink: Add support for acquire sequence numbers
Note that while PF_KEYv2 also uses sequence numbers to identify acquires,
which we currently don't use correctly by the way, it does not include
information about the packet that triggered an acquire.  What we receive
in src and dst, and currently forward as traffic selectors, are actually
the designated endpoints of the SA. So especially in tunnel mode this is
useless to do narrowing on the responder (these addresses might not even
match the configured TS).
2025-05-28 10:01:19 +02:00
Tobias Brunner c5b2a8eaa3 child-cfg: Use separate method to get configured traffic selectors
Optionally with "dynamic" traffic selectors resolved.  A new method
is added for those cases where we actually want to select potentially
narrowed traffic selectors using a supplied list.  The latter now also
always logs details, while the former does not.
2025-05-28 10:01:19 +02:00
Tobias Brunner 981c82ab50 vici: Add support for POSIX regular expressions in identity fields 2025-05-28 09:58:17 +02:00
Tobias Brunner 362fa94ef5 vici: Document that the log event only receives messages on level 0 and 1 2025-05-22 14:05:51 +02:00