Commit Graph
4160 Commits
Author SHA1 Message Date
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
Nikos Mavrogiannopoulos 54e3244b45 tests: fix radius failures with radcli 1.5.0
radcli 1.5.0 validates Message-Authenticator in RADIUS responses
CVE-2024-3596 (BlastRADIUS) and silently discards responses that lack
it.  Make sure that the Message-Authenticator message is known to
the client via the dictionary.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 19:40:56 +02:00
Nikos Mavrogiannopoulos 5148c723cb tests: fix flaky radius tests by waiting for server readiness
All six radius tests used a fixed sleep 4 after starting radiusd and
ocserv.  On slow or ASAN-instrumented hosts (CentOS 10 CI) this is
insufficient: freeradius with -xx debug logging takes longer than 4
seconds to load its modules, and even after binding UDP 1812 it continues
initializing its user database before it can process auth requests.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 17:20:38 +02:00
Nikos Mavrogiannopoulos 5137ba4309 ai: add AI policy
CONTRIBUTING.md: new AI Assistance Policy section stating that AI use is
assumed and requires no disclosure, that human accountability is what
matters, and that reviewers may request additional explanation for
submissions showing signs of unchecked generation.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 12:08:32 +02:00
Nikos Mavrogiannopoulos 855966cd95 ai: add AI guidance, personas
Introduce a structured AI assistance framework for the project:

- AGENTS.md: single, comprehensive AI guidance file for all tools
  (Claude Code, Codex, Copilot, Cursor). Covers the privilege-separation
  architecture invariant, build/test instructions, code style (including
  a rule against deep preprocessor conditionals), memory allocator policy,
  IPC modification procedure, module-specific doc pointers, and a
  contribution checklist split into agent-runnable and human-judgment items.
  Includes a security disclosure gate that redirects potential vulnerability
  reports to the confidential issue tracker before any public MR is opened.

- contrib/ai/personas/ocserv-core-dev.md: maintainer-facing persona with
  project-specific protocols for anti-hallucination (GnuTLS/protobuf/seccomp
  APIs), memory safety (talloc-first, gnutls_malloc exception), a taxonomy
  of ocserv-specific vulnerability classes, and a self-verification protocol
  that distinguishes what an agent can check automatically from what requires
  human judgment.

- contrib/ai/personas/ocserv-contributor.md: external-contributor-facing
  persona with mandatory architecture orientation, a prominent security
  disclosure gate, five hard guardrails (privilege boundary, syscall
  portability, GnuTLS-only, protobuf regeneration, talloc), and a
  step-by-step workflow for features, bug fixes, and security fixes.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-25 12:08:32 +02:00
Nikos Mavrogiannopoulos a65f2c22a2 protobuf source files are generated during release
Protobuf files are removed from the repository and are only
auto-generated during dist.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-23 19:21:27 +02:00
Nikos Mavrogiannopoulos 58a67f14f3 config: extend vhost_inherit_static_config to cover vhost-scoped fields
All [scope: vhost (non-reloadable)] fields in static_cfg_st now inherit
from the default vhost when not explicitly set in a named-vhost section,
consistent with how ReloadableConfig fields already behave.  This means
a named vhost that shares the same TLS cert, CA, auth method, or PKCS#11
pins as the default no longer has to repeat them.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-23 10:51:26 +02:00
Nikos Mavrogiannopoulos 112afa683c config: treat expose-iroutes as a normal configuration option
That is store it in VhostConfig and avoid manual clearing of it.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:26 +02:00
Nikos Mavrogiannopoulos 836e6f0785 config: fix scope annotation and vhost guards for global-only options
NetworkConfig.name ('device' key) is global-only: the parser calls
error_on_vhost() and tun.c always reads it from the default vhost.
Annotate it as [scope: global] in cfg.proto to match the implementation.

Also add missing error_on_vhost() guards to the deprecated aliases
'use-seccomp' (for isolate-workers), 'use-dbus' (for use-occtl) and
'min-reauth-time' (for ban-time). Their canonical replacements already
reject vhost use; the aliases did not.

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:24 +02:00
Nikos Mavrogiannopoulos 139ff827d9 config: restructure per-vhost configuration for clarity and maintainability
Introduce a protobuf-generated ReloadableConfig (cfg.proto) to hold all
fields that reload on SIGHUP, and separate them from static_cfg_st, which
holds fields that require a server restart.  Named vhosts inherit from the
default vhost via a pack/unpack round-trip. Adding a new config field
only requires editing cfg.proto.  Struct and accessor names (ReloadableConfig,
static_cfg_st, GETRCONFIG, GETSCONFIG) now reflect each field's lifetime.
A new unit test covers the full inheritance path.

Resolves: #705

Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-22 20:29:15 +02:00
Nikos Mavrogiannopoulos 1228688fb2 Merge branch 'tmp-rfc1123' into 'master'
valid_hostname: enhance to cover RFC 1123 requirements

See merge request openconnect/ocserv!525
2026-04-22 11:20:05 +00:00
Nikos Mavrogiannopoulos caacc92c28 Merge branch 'doc-user-config' into 'master'
doc: clarify reload behavior for per-user/group configs

See merge request openconnect/ocserv!526
2026-04-21 18:58:01 +00:00
Nikos Mavrogiannopoulos 745d7883be design.md: include auth state in the diagram
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-21 19:19:32 +02:00
Nikos Mavrogiannopoulos 56055a2ed0 Merge branch 'udp-desync' into 'master'
Do not forward UDP until client is authenticated

Closes #706

See merge request openconnect/ocserv!522
2026-04-21 16:42:35 +00:00
Grigory Trenin eddd29f59b Do not forward UDP until client is authenticated
Do not forward DTLS packets until the client is authenticated to
prevent the race between AUTH_COOKIE_REP and CMD_UDP_FD messages
on the command socket.

Closes #706

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-21 07:06:59 -04:00
Grigory Trenin 50c59cd53b doc: clarify reload behavior for per-user/group configs
Document that there is no need to reload ocserv after modifying per-user
or per-group configuration.

Signed-off-by: Grigory Trenin <grigory.trenin@gmail.com>
2026-04-19 09:08:07 -04:00
Nikos Mavrogiannopoulos a9f42c892c valid_hostname: enhance to cover RFC 1123 requirements
Signed-off-by: Nikos Mavrogiannopoulos <n.mavrogiannopoulos@gmail.com>
2026-04-18 15:51:20 +02:00
Nikos Mavrogiannopoulos 0f7640bcea Merge branch 'tmp-claude' into 'master'
RFC 952 prohibits trailing hyphen

See merge request openconnect/ocserv!523
2026-04-18 13:43:36 +00:00
Nikos Mavrogiannopoulos c0e3aa6c5c Merge branch 'tmp-disable-adaptive-rate-limit' into 'master'
Add check to disable adaptive rate limiting

Closes #493

See merge request openconnect/ocserv!476
2026-04-18 13:32:07 +00:00