From patchwork Wed Nov 18 17:27:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5740 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:b1c3:10b0:11b:d6c:f273 with SMTP id i3-n1csp474333laq; Wed, 18 Nov 2026 09:28:22 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErH1aHIMxVJg1IilBI1gALg6HbGud7g/Rj8xjOfarZxxizQSHyhILvb55EiD5VYQPFWyS1igU42bEWo=@openvpn.net X-Received: by 2002:a05:701b:271c:b0:145:ac96:3917 with SMTP id a92af1059eb24-1b54cbabe27mr84710c88.21.1795022902050; Wed, 18 Nov 2026 09:28:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795022902; cv=none; d=google.com; s=arc-20260327; b=R4fF3MaS6I+HvRXDgA7B3HY8xiDg86NMJdEfjcfutGngx0LMIzqxHLr/nWsXji4cgq ELhGIYcMDWALWjRY6jvuo2MJspAH3PspA7CMJeiIH9VR6utiNRqNGoGQGrw7tQeT94EQ Z67LGFDhhcdPOb6i+Lnad+V2CwIPFrMGVWRALG4lFR8nRJBGlDiuV0qhVNwbzHoZCiHP kAOu4Pa/A5aGNpE7aJcnV9BoETZf8VYbJqFtynHwFaY7tYQ8+PDoLNe6LgEAMpl0XjaH w9pc7XEi0eK79W7R7PEU8ly+8p45kX7teNUOWJV+Qhf54t2g5zWWVG5vNl2fq342u6xh L+1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=0dpXi5QpWLBARfZERCbgkdkCIHr387YWWCbOLotHN34=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=lCk2AUA2MmSoX2QHYt9e6PXwSewqlHywciKPB/jPVdfw9CSAVTQ3jEwdCmytiKtDeY IUs/pEOKj1mJmAD2ZrUQc7JWO/ZoH/Az65tHkvsOzvkPELh8aH2HRVul3tJW97dJtG/p wnGuG+ELz89RSadKqGfoZj/zeBZoX4o766fr7B1vP8WkXtp0FpCsSJWg+E8QmTWwG2Cu 53JfB6JOsh2pIQ3NjU7Y39IqxbWyxqoWkuIUatRLAhwLgLRHpU/zWz+Ckg2uvdaDAhPK Rhra1+Q8emoV7MjuJp3qaQSox01qVQCQewlvkU6wBM8WdsHO8eO8/dyc2g4rP3cDZb3L 2zHA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="G69k/kJz"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=nPBsMNRC; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=emTum4kc; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id a92af1059eb24-1b5454c21casi6058494c88.59.2026.11.18.09.28.21 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Nov 2026 09:28:22 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="G69k/kJz"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=nPBsMNRC; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=emTum4kc; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=0dpXi5QpWLBARfZERCbgkdkCIHr387YWWCbOLotHN34=; b=G69k/kJzdqdLbX 0gMK+sEUPQR+zspjIeUowihQCavSWk4tn8avYAuOcUphH/k5KFDBKuZQWamFiLk4zrL6Q1lYDygNk 8pJ3/Ot/Mlu9qJvwFuMdUIzUDTvJ2puQck9kj3CbH4uqBngoZGSDTVyFG9vhAxZ4WXMtDsQPNJNIn Uos=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xTjSG-000000008Dy-3FWo; Wed, 18 Nov 2026 17:28:20 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xTjSD-000000008Dh-3IKe for openvpn-devel@lists.sourceforge.net; Wed, 18 Nov 2026 17:28:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=gch0epSebdlnsfirktfYwR8LpItWgtvbacDTOHbTIxk=; b=nPBsMNRCFwZRxt5RjHIDDb+uGo myW4Yiu2X+WbxLPCfN0Eau8bzP0hq3xYocmUojxxSZ/JpLmGj/CWYHHsTz3JpGFl8FzHuv4MaZnMU qpMB6wU5PM5ZPjymfB1xGYZy0HjQSo60gOSxEDyKgtrWqTvNDeLbLYP9mujSdTElfIRM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Unsubscribe-Post: List-Subscribe:List-Post:List-Owner:List-Archive; bh=gch0epSebdlnsfirktfYwR8LpItWgtvbacDTOHbTIxk=; b=emTum4kcRdMYK4PL0DGz3B6wOs dKbEMS1m+H+HxNnuMajJy31H6HyIHMbE7yTLJQ95IDXjQwbrEC3VcyXy7g0SUrZWB5r/2bpE2ZTbx is7ngwv4liL+BfpkVdZEezS8OPDNgcpD701sQ3ZjMCnOCjDJpy+cGMVyloby+AMqyNW8=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xTjRw-000000005RK-2Jnx for openvpn-devel@lists.sourceforge.net; Wed, 18 Nov 2026 17:28:02 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 6AIHRrs5029973 for ; Wed, 18 Nov 2026 18:27:53 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AIHRrZH029972 for openvpn-devel@lists.sourceforge.net; Wed, 18 Nov 2026 18:27:53 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Wed, 18 Nov 2026 18:27:46 +0100 Message-ID: <20261118172753.29962-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.55.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Gianmarco De Gregori Every TCP client takes a file descriptor and accept() happens before the --max-clients check, so with the default limits (soft limit 1024, --max-clients 1024) the server runs out of descriptors before [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xTjRw-000000005RK-2Jnx Subject: [Openvpn-devel] [PATCH v3] multi: raise the open files limit for --max-clients X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: 1882217934581683351 X-GMAIL-MSGID: 1882217934581683351 From: Gianmarco De Gregori Every TCP client takes a file descriptor and accept() happens before the --max-clients check, so with the default limits (soft limit 1024, --max-clients 1024) the server runs out of descriptors before it can refuse a client. When the server has a TCP listener, raise the soft limit to --max-clients plus some room for the other descriptors, up to the hard limit, and warn if that is not enough. Processes started by OpenVPN inherit the new limit. Not on macOS, where the event loop uses select() and cannot watch descriptors >= FD_SETSIZE. GitHub: closes OpenVPN/openvpn#1148 Change-Id: I17fafbe65fd3ff510a72ed809c85b0d19343fad2 Signed-off-by: Gianmarco De Gregori Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2211 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2211 This mail reflects revision 3 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-options.rst index 7a09809..5c1b129 100644 --- a/doc/man-sections/server-options.rst +++ b/doc/man-sections/server-options.rst @@ -418,6 +418,9 @@ --max-clients n Limit server to a maximum of ``n`` concurrent clients. Defaults to 1024. + With a TCP listener, the soft limit on open files is raised up to the hard + limit if needed to accept ``n`` clients (not on Windows and macOS). + --max-routes-per-client n Allow a maximum of ``n`` internal routes per client (default :code:`256`). This is designed to help contain DoS attacks where an diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index ad9f9f4..900b5a3 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -270,6 +270,68 @@ #endif /* + * Every TCP client takes a file descriptor, and accept() happens before the + * --max-clients check: raise the soft limit so that --max-clients is reached + * first, or warn if the hard limit does not allow it. + */ +static void +multi_check_nofile_limit(const struct context *t) +{ +#if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE) && !defined(TARGET_DARWIN) + bool tcp = false; + for (int i = 0; i < t->c1.link_sockets_num; i++) + { + if (!proto_is_dgram(t->c2.link_sockets[i]->info.proto)) + { + tcp = true; + break; + } + } + if (!tcp) + { + return; + } + + /* room for the tun device, the listeners, log, management, scripts... */ + const rlim_t needed = (rlim_t)t->options.max_clients + 64; + + struct rlimit rl; + if (getrlimit(RLIMIT_NOFILE, &rl) < 0) + { + msg(M_WARN | M_ERRNO, "WARNING: getrlimit(RLIMIT_NOFILE) failed"); + return; + } + if (rl.rlim_cur >= needed) + { + return; + } + + const rlim_t old = rl.rlim_cur; + rl.rlim_cur = rl.rlim_max < needed ? rl.rlim_max : needed; + if (rl.rlim_cur > old) + { + if (setrlimit(RLIMIT_NOFILE, &rl) == 0) + { + msg(M_INFO, "NOTE: raised the open files limit from %lu to %lu", (unsigned long)old, + (unsigned long)rl.rlim_cur); + } + else + { + msg(M_WARN | M_ERRNO, "WARNING: setrlimit(RLIMIT_NOFILE) failed"); + rl.rlim_cur = old; + } + } + if (rl.rlim_cur < needed) + { + msg(M_WARN, + "WARNING: the open files limit (soft %lu, hard %lu) is too low for " + "--max-clients %" PRIu32 ", TCP clients may be refused before --max-clients is reached", + (unsigned long)rl.rlim_cur, (unsigned long)rl.rlim_max, t->options.max_clients); + } +#endif /* if defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE) && !defined(TARGET_DARWIN) */ +} + +/* * Main initialization function, init multi_context object. */ static void @@ -398,6 +460,7 @@ * Per-client limits */ m->max_clients = t->options.max_clients; + multi_check_nofile_limit(t); m->instances = calloc(m->max_clients, sizeof(struct multi_instance *)); check_malloc_return(m->instances);