Commit Graph
4228 Commits
Author SHA1 Message Date
Dimitri Papadopoulos d95d1ac53e Consistency for readability
Consistency across IPv4 and IPv6 paths. Set `sin_addr` first and then `sin_port`.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-19 23:22:37 +02:00
Dimitri Papadopoulos 550e9327cc Set sa before attempting to set sa->sin6_family
Fixes #711.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-19 23:22:34 +02:00
Dimitri Papadopoulos b97aa4d97f Build against GNU Nettle 4
Fixes #697. Follow-up of !535 / 82572986.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-19 21:23:03 +02:00
Nikos Mavrogiannopoulos 583f0c0be5 worker: fix ICMPv6 misclassification as data traffic affecting idle-timeout
ICMPv6 was never excluded from idle-timeout accounting because is_data()
inspected data[9] for both IPv4 and IPv6.  Offset 9 is the Protocol field
in the IPv4 fixed header (RFC 791), but the Next Header field in the IPv6
fixed header sits at offset 6 (RFC 8200 §3).  As a result, the idle timer
was reset on every ICMPv6 packet, preventing the server from disconnecting
clients that were sending only control traffic.

Resolves: #724
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-19 20:14:21 +02:00
Nikos Mavrogiannopoulos bf23e0d549 /svc handler: add the owasp headers for consistency
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-19 20:11:33 +02:00
Nikos Mavrogiannopoulos e567f92e64 Removed unnecessary CA and certificate handlers
This removes certificate and CA handlers not used by the openconnect
client. This is a hardening measure to further reduce the attack surface
of the worker process.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-19 20:11:33 +02:00
Nikos Mavrogiannopoulos 2dfb9acec5 Updated instructions for AI agents reporting vulnerabilities
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-19 16:57:44 +02:00
Dimitri Papadopoulos Orfanos e67582ba05 Merge branch 'tmp-nettle4' into 'master'
Build against GNU Nettle 4

Closes #697

See merge request openconnect/ocserv!535
2026-05-18 01:57:20 +03:00
Nikos Mavrogiannopoulos 0b47ea457d Merge branch 'tmp-uninitialised-handle' into 'master'
Do not use uninitialised PAM/GnuTLS handles

Closes #722

See merge request openconnect/ocserv!547
2026-05-17 19:56:55 +00:00
Dimitri Papadopoulos d019cd1c84 Do not use uninitialised gnutls_x509_crt_t
Initialise `issuer` at each iteration, since we clean up at each iteration.

Fixes #722.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-17 13:17:14 +02:00
Dimitri Papadopoulos 23a08753e9 Do not use uninitialised pam_handle_t
In case of error in pam_start(3), the content of the `pam_handle_t **pamh`
handle is undefined:
	Following a successful return (PAM_SUCCESS) the contents of
	pamh is a handle that contains the PAM context for successive
	calls to the PAM functions. In an error case is the content
	of pamh undefined.

Although pam_sterror(3) does not use `pamh` in any way, pass plain
`NULL` instead of `pamh`.

Fixes #722.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-17 13:16:23 +02:00
Dimitri Papadopoulos 825729868e Build against GNU Nettle 4
From the NEWS file:
https://git.lysator.liu.se/nettle/nettle/-/blob/master/NEWS

	Interface changes:

	* The _digest functions for hash algorithms, MACs and AEADs no
	  longer take the desired digest size as argument, instead,
	  they always produce the full-size digest. The typedef
	  nettle_hash_digest_func has also been changed accordingly.

Fixes #697.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-17 13:13:39 +02:00
Nikos Mavrogiannopoulos 6e658f00ae Merge branch 'tmp-NULL-dereference' into 'master'
Avoid NULL dereference in case of memory exhaustion

Closes #721

See merge request openconnect/ocserv!545
2026-05-16 20:20:49 +00:00
Dimitri Papadopoulos 2e89f38e1e Avoid NULL dereference in case of memory exhaustion
Fixes #721.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-16 15:54:08 +02:00
Nikos Mavrogiannopoulos 01f2787ab6 worker: reject HTTP pipelining to prevent request confusion
When two HTTP requests arrived in the same TLS read buffer, a single
llhttp_execute() call would fire callbacks for both requests inline.
Because http_req_reset() is not called between them, ws->req ended up
reflecting the second request's URL and headers, silently discarding
the first.  In the worst case, body bytes from the first request
accumulated alongside the second request's body.

Fix this by registering an on_message_begin callback that returns
HPE_PAUSED when an existing message is detected.

Resolves: #716

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-15 06:42:24 +02:00
Dimitri PapadopoulosandNikos Mavrogiannopoulos e4c8d894db Fix typo [ci skip]
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-14 08:52:32 +02:00
Nikos Mavrogiannopoulos aeaf5a0896 Merge branch 'tmp-seclog-trailing-newline' into 'master'
Avoid trailing `\n` in messages passed to logging

See merge request openconnect/ocserv!544
2026-05-12 18:02:45 +00:00
Dimitri Papadopoulos 5a81433f47 Log messages don't need a trailing \n
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-12 08:14:21 +02:00
Nikos Mavrogiannopoulos 6c4a0aca93 Merge branch 'tmp-talloc_array' into 'master'
talloc_size() → talloc_array()

Closes #725

See merge request openconnect/ocserv!541
2026-05-12 05:21:44 +00:00
Nikos Mavrogiannopoulos 923187aa4c Merge branch 'tmp-strerror' into 'master'
Use strerror() and pass proper errno to it

Closes #723

See merge request openconnect/ocserv!542
2026-05-12 05:14:54 +00:00
Dimitri Papadopoulos 0fad7f71ac talloc_size() → talloc_array()
This fixes a theoretical risk of overflow. I suspect it's not an issue in
practice, but it doesn't hurt to switch to talloc_array() to remove the
problem altogether. Also, `talloc_array()` macro returns the proper type.

From `talloc.h`:

	/**
	 * talloc_array - allocate dynamic memory for an array of a given type
	 * @ctx: context to be parent of this allocation, or NULL.
	 * @type: the type to be allocated.
	 * @count: the number of elements to be allocated.
	 *
	 * The talloc_array() macro is a safe way of allocating an array.  It is
	 * equivalent to:
	 *
	 *  (type *)talloc_size(ctx, sizeof(type) * count);
	 *
	 * except that it provides integer overflow protection for the multiply,
	 * returning NULL if the multiply overflows.

	/**
	 * talloc_size - allocate a particular size of memory
	 * @ctx: context to be parent of this allocation, or NULL.
	 * @size: the number of bytes to allocate
	 *
	 * The function talloc_size() should be used when you don't have a convenient
	 * type to pass to talloc(). Unlike talloc(), it is not type safe (as it
	 * returns a void *), so you are on your own for type checking.
	 *
	 * Best to use talloc() or talloc_array() instead.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-11 20:13:35 +02:00
Dimitri Papadopoulos bd5e1636dc Use strerror() and pass proper errno to it
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-11 19:57:15 +02:00
Dimitri Papadopoulos Orfanos 3f37c8ea38 Merge branch 'tmp-protoc-c' into 'master'
Address build warning: protoc-c → protoc

See merge request openconnect/ocserv!492
2026-05-11 20:18:28 +03:00
Dimitri Papadopoulos Orfanos d090c79926 Merge branch 'tmp-fedora44-ubuntu26.04' into 'master'
CI: upgrade Fedora and Ubuntu

See merge request openconnect/ocserv!540
2026-05-11 20:17:30 +03:00
Nikos Mavrogiannopoulos 93c08b5c83 Merge branch 'pam-service' into 'master'
Add service sub-option to PAM auth

Closes #718

See merge request openconnect/ocserv!539
2026-05-11 17:06:56 +00:00
Dimitri Papadopoulos 6eb1cef514 This is a Bash script, not plain Bourne
Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-09 10:16:00 +02:00
Dimitri Papadopoulos c30bd5dca4 Address build warning
[libprotobuf WARNING protoc-gen-c/main.cc:44] `protoc-c` is deprecated. Please use `protoc` instead!

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-09 10:16:00 +02:00
Grigory Trenin 61f013ae3a pam: add 'service' sub-option to auth directive
This allows users to specify a custom PAM service name, enabling
per-virtual-host PAM stacks.For example:
auth = "pam[service=vpn1,gid-min=1000]"

Resolves: #718

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-05-08 21:00:07 -04:00
Dimitri Papadopoulos ad52625e0e Fix new Clang error
error: assigning to 'char *' from 'const char *' discards qualifiers
       [-Werror,-Wincompatible-pointer-types-discards-qualifiers]

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-08 15:08:53 +02:00
Dimitri Papadopoulos 174561dd66 CI: upgrade Fedora and Ubuntu
* Fedora 43 → 44
* Ubuntu 24.04 → 26.02 (we also test Ubuntu 22.04)

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-08 14:41:19 +02:00
Nikos Mavrogiannopoulos 2548a27b51 Merge branch 'tmp-AF_INET' into 'master'
Build on FreeBSD

See merge request openconnect/ocserv!514
2026-05-07 01:56:53 +00:00
Dimitri Papadopoulos eb886a7c67 Include <sys:socket.h> for AF_INET
Required to build on FreeBSD 15.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-06 20:33:03 +02:00
Nikos Mavrogiannopoulos 22bbad4eb5 worker: add per-worker memory limit via RLIMIT_DATA
Introduce a per-worker heap cap as defense-in-depth against
memory-exhaustion DoS attacks. The limit uses RLIMIT_DATA rather
than RLIMIT_AS: since Linux 4.7 RLIMIT_DATA covers brk and private
anonymous mmap regions, i.e, the paths used by malloc and talloc, while
ignoring shared-library file mappings that inflate RLIMIT_AS without
reflecting actual allocation.

This aligns with haproxy's handling. See also:
https://github.com/torvalds/linux/commit/84638335900f1995495838fe1bd4870c43ec1f67
https://sources.debian.org/src/haproxy/3.2.17-1/src/limits.c?hl=486#L486
https://www.kernel.org/doc/html/latest/mm/overcommit-accounting.html

The cap is computed at worker startup by reading the data+stack field
from /proc/self/statm.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-06 13:54:40 +02:00
Nikos Mavrogiannopoulos 4303a12f60 worker: harden HTTP request header size limits
Bound memory growth in the worker for unauthenticated connections by
enforcing HTTP headers limit in addition to HTTP body limit.

Resolves: #712

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-06 13:54:21 +02:00
Nikos Mavrogiannopoulos 7efa74f8e8 protobuf files were removed from the repository
This is a follow-up to a65f2c22a2
which did not actually remove the files.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-03 19:15:55 +02:00
Nikos Mavrogiannopoulos 8e0f7f460a Merge branch 'tmp-llhttp_cb' into 'master'
llhttp callbacks should return -1 on error

See merge request openconnect/ocserv!537
2026-05-03 17:05:13 +00:00
Dimitri Papadopoulos 9cc845e9d3 llhttp callbacks should return -1 on error
https://github.com/nodejs/llhttp#llhttp_settings_t

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-03 18:41:38 +02:00
Nikos Mavrogiannopoulos 8913ffadff doc: updated for nft/iptables dependencies
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-02 18:49:43 +02:00
Nikos Mavrogiannopoulos 4c85218f41 .gitignore: removed leftovers from autotools
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-02 17:21:42 +02:00
Nikos Mavrogiannopoulos 9c44e09356 ocserv-fw-nftables: replace ipcalc with pure-shell mask_to_prefix
ipcalc was used only to convert dotted-decimal subnet masks to CIDR
prefix lengths (e.g. 255.255.0.0 -> 16), replaced with a POSIX shell
script.

Relates: #709

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-02 17:21:38 +02:00
Nikos Mavrogiannopoulos dcb1b8d24e Merge branch 'tmp-prefer-nft' into 'master'
meson: nftables is preferred unless only iptables is found

See merge request openconnect/ocserv!531
2026-05-02 15:09:43 +00:00
Nikos Mavrogiannopoulos 465d3ce383 Merge branch 'tmp-framed-ipv6' into 'master'
radius-auth: fix Framed-IPv6-Prefix routes being silently dropped

Closes #710

See merge request openconnect/ocserv!532
2026-05-01 20:21:09 +00:00
Nikos Mavrogiannopoulos dda2015aa4 meson: nftables is preferred unless iptables is explicitly requested
Relates: #709

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-01 22:17:04 +02:00
Nikos Mavrogiannopoulos c41b6d52de Merge branch 'tmp-CID-645850' into 'master'
Fix new Coverity Scan defect

See merge request openconnect/ocserv!530
2026-05-01 19:26:45 +00:00
Dimitri Papadopoulos OrfanosandNikos Mavrogiannopoulos c0b282576e Fix new Coverity Scan defect
This adds checks in memory allocation, to address the following issue reported by coverity:
** CID 645850:       Null pointer dereferences  (FORWARD_NULL) /tests/ban-ips.c: 84           in main()

Signed-off-by: default avatarDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
2026-05-01 19:26:45 +00:00
Nikos Mavrogiannopoulos e7d79e232d radius-auth: fix Framed-IPv6-Prefix routes being silently dropped
When processing a RADIUS Access-Accept with Framed-IPv6-Prefix, the code
passed the wrong value for it. Corrected by passing the actual prefix.

Fixes: #710

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-05-01 16:31:38 +02:00
Nikos Mavrogiannopoulos ac5ee6a10b Merge branch 'type-limits-warning' into 'master'
Fix compiler warning when PAM/RADIUS are disabled

See merge request openconnect/ocserv!529
2026-05-01 14:12:10 +00:00
Grigory Trenin 86972b7200 Fix compiler warning when PAM/RADIUS are disabled
This fixes a -Wtype-limits warning encountered in builds without
PAM and RADIUS (e.g., OpenWRT). When the avail_acct_types array is
empty, ARRAY_SIZE evaluates to 0, making the unsigned comparison
always false.

Reported in #709.

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-27 12:00:09 -04:00
Nikos Mavrogiannopoulos 4334978fd6 Merge branch 'tunnel-all-dns' into 'master'
Fix tunnel-all-dns ignored in user config

Closes #708

See merge request openconnect/ocserv!527
2026-04-27 03:54:29 +00:00
Grigory Trenin a79e2f1cd5 Respect tunnel-all-dns in per-user/group config
Ensure that 'tunnel-all-dns' setting is honoured when overridden
in user or group-specific configuration files.

Resolves: #708

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-26 21:05:06 -04:00