From patchwork Thu Nov 26 10:18:26 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5792 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp6964903lad; Thu, 26 Nov 2026 02:18:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErG76vaLl9wBbdak0M7Pl0H3p5s+qwancKxv8Ukn0UlMYdVM/408i58BSkGaOwsW202sye4q1j86Sfs=@openvpn.net X-Received: by 2002:a05:7300:b089:b0:386:9c9f:83d8 with SMTP id 5a478bee46e88-3869c9f86bbmr17288372eec.17.1795688326228; Thu, 26 Nov 2026 02:18:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1795688326; cv=none; d=google.com; s=arc-20260327; b=smJWy4QOyiz38D1KnOy0S8OT+P7m2DEFJo42GQmeXQI00XUicaHLV3YVYD5MVn81wb H+062jiRzStZobf1fudQVOxp8P8sby3Up0jzfvRMzqyHLRFZdmf+fKk1LTa1xK83ufGT U0hDhcZWmbyP3MmqAQyQdVusbdfz6gYHhNzGCMA1cBRW87SJmZr4o5py86OUFzjDRmrl UeR94yUzqH1tJA4CeDmoEluohCFV/U+qeKRcfM4lKPFsKHhXmVbkP8dDm852Pk45l2xI VP1xPt++P4sZ6lyRb8y6OyZXsBlEscf2mURlIbo6dhfOTTjS49n6Pt8nUO65il3Ru4cu xVww== 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=5ZV502vdlL7RfDTAVi0NgDX/WC4XL5jiTEU9CL2qbu4=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=oqUdqxbNLTzMRxXTMyOTpJjKDDX/lnbfBF7drKUd9egBemS/Vq39LzmRJ6F0m3Jwvf XZAj8zbcU8qKlEoO6F1FfUmeo2c6v4poJzvET+DoFEIK8X0Mp5Wh4QlIbp9IebuOcEMv oDF3h5sBx1U4KSuiH/y+LjaswrBnLiZS9lji59ZdwCuIqs3lhYR/o4XZooQnp/9MIpFX 2Tnmk4hUIoRYO1zTTRBllSszGz4+S/slirQgDieu7DYGLSwjvLM8aqc21NtLLPCUFoSi h8G/QzNaPouiwPD6jvPhmNn+L781pNnjx2Ww0DGskPKnTgbdKAz6qPNZMRWRthWH0m6/ K0MQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=Fz0GWbtX; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=iokUfRkL; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=NSZG6Fnm; 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 5a478bee46e88-386c24f5658si19050343eec.26.2026.11.26.02.18.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Nov 2026 02:18:46 -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=Fz0GWbtX; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=iokUfRkL; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=NSZG6Fnm; 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=5ZV502vdlL7RfDTAVi0NgDX/WC4XL5jiTEU9CL2qbu4=; b=Fz0GWbtXNi1g0D 2Du2dtSWmjBeo7Swbc5s8f3bBXoqAS+EhIK+4TZ/PIbAMbsW2zoPHqaKpxmGmzi8Vkaa4ZlhaOIo2 bT4LNc12dNjpk3IMga6PUfj6HM4929BlsSZfxuxvbh5i3zPM1dLmSgHfpHtaSwDBr2dZrSCNOZMv5 03o=; Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xWWYu-0000000088H-349Z; Thu, 26 Nov 2026 10:18:44 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xWWYs-00000000884-43Py for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 10:18:42 +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=Q+LbVsMMFyXjPwvGbOWNT+cfATMXhT7pmFK2GW2LF0U=; b=iokUfRkL/dUBpmGRdEEheK0O2b 6iYu6+uvScARv2LDjTBGWJFSV6x84pAs4C3fiOs1bgi51H4v/dxm+0CUR9lHurgz6En2AJi92gPwH b3N66UfZcE0HqdNBsPSvnQx45GQgHX0gIEz+9v8SfH94LS3hmrLUXfW9V1jrn6+zqadY=; 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=Q+LbVsMMFyXjPwvGbOWNT+cfATMXhT7pmFK2GW2LF0U=; b=NSZG6FnmWn7epkXvwZB4+g7OyV gTkTsYzVpT8h2txIhHUhd8nZE0Y1OoPeD7zLJFbVuExcoOMueI7IwfY50NKGA3d3trmUvr5OKy3d9 StChnDKHI4Kes9k8a0IbaRaIOio/S1lZk5a8/AkK8XKfqcxbRfZbxgKqbLVp/UxVgMlw=; Received: from [193.149.48.129] (helo=blue.greenie.muc.de) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.100.1) id 1xWWYp-000000003Kh-3mos for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 10:18:42 +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 6AQAIX2F029147 for ; Thu, 26 Nov 2026 11:18:33 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6AQAIXwi029143 for openvpn-devel@lists.sourceforge.net; Thu, 26 Nov 2026 11:18:33 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Thu, 26 Nov 2026 11:18:26 +0100 Message-ID: <20261126101832.29100-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: Heiko Hund The updown runner hands the vars it gets from the unprivileged process to a root script. Only accept what openvpn itself would send, so that a compromised process cannot affect the script beyond its D [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URI: openvpn.net] 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xWWYp-000000003Kh-3mos Subject: [Openvpn-devel] [PATCH v2] dns: restrict dns var names and values in the updown runner 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: 1882915682790902677 X-GMAIL-MSGID: 1882915682790902677 From: Heiko Hund The updown runner hands the vars it gets from the unprivileged process to a root script. Only accept what openvpn itself would send, so that a compromised process cannot affect the script beyond its DNS settings. Change-Id: I5847d602a024044d9109f521de7885d55d28a968 Signed-off-by: Heiko Hund Acked-by: Razvan Cojocaru Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2349 --- 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/+/2349 This mail reflects revision 2 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru diff --git a/src/openvpn/dns.c b/src/openvpn/dns.c index 1bd6c85..d00165a1 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -591,10 +591,155 @@ #define DNS_VARS_MAX_SIZE (64 * 1024) /** + * Check if a dns var name equals a given name + * + * @param name variable name, not NUL terminated + * @param size size of the name in bytes + * @param expected NUL terminated name to compare with + * + * @return bool to indicate if the names are equal + */ +static bool +dns_var_name_is(const char *name, size_t size, const char *expected) +{ + return size == strlen(expected) && memcmp(name, expected, size) == 0; +} + +/** + * Check if a dns var name is allowed + * + * Besides dev and script_type, only names starting with dns_ and made of + * lowercase letters, digits and underscores are allowed. + * + * @param name variable name, not NUL terminated + * @param size size of the name in bytes + * + * @return bool to indicate if the name is valid + */ +static bool +dns_var_name_valid(const char *name, size_t size) +{ + const char prefix[] = "dns_"; + + if (dns_var_name_is(name, size, "dev") || dns_var_name_is(name, size, "script_type")) + { + return true; + } + + if (size < sizeof(prefix) || strncmp(name, prefix, sizeof(prefix) - 1) != 0) + { + return false; + } + + for (size_t i = 0; i < size; ++i) + { + const char c = name[i]; + if (!((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_')) + { + return false; + } + } + + return true; +} + +/** + * Check if a dns var value contains only allowed characters + * + * Values are domain names, IP addresses, port numbers or keywords, so + * domain name characters and colons are allowed. A value must not start + * with a dash, so that it cannot be taken for an option. + * + * @param value variable value, not NUL terminated + * @param size size of the value in bytes + * + * @return bool to indicate if the value is valid + */ +static bool +dns_var_value_valid(const char *value, size_t size) +{ + if (size > 0 && value[0] == '-') + { + return false; + } + + for (size_t i = 0; i < size; ++i) + { + const unsigned char c = (unsigned char)value[i]; + if (!is_allowed_domain_ascii(c) && c != ':') + { + return false; + } + } + + return true; +} + +/** + * Check if a dev value contains only allowed characters + * + * Interface names may contain more than domain name characters, so a few + * characters without special meaning to the shell are allowed as well. A + * name must not start with a dash, so that it cannot be taken for an option. + * + * @param value interface name, not NUL terminated + * @param size size of the name in bytes + * + * @return bool to indicate if the value is valid + */ +static bool +dns_var_dev_valid(const char *value, size_t size) +{ + const char extra[] = "+@%,="; + + if (size == 0 || size >= IFNAMSIZ || value[0] == '-') + { + return false; + } + + for (size_t i = 0; i < size; ++i) + { + const unsigned char c = (unsigned char)value[i]; + if (!is_allowed_domain_ascii(c) && !memchr(extra, c, sizeof(extra) - 1)) + { + return false; + } + } + + return true; +} + +/** + * Check if a dns var has an allowed name and value + * + * @param name variable name, not NUL terminated + * @param name_size size of the name in bytes + * @param value variable value, not NUL terminated + * @param value_size size of the value in bytes + * + * @return bool to indicate if the var is valid + */ +static bool +dns_var_valid(const char *name, size_t name_size, const char *value, size_t value_size) +{ + if (!dns_var_name_valid(name, name_size)) + { + return false; + } + + if (dns_var_name_is(name, name_size, "dev")) + { + return dns_var_dev_valid(value, value_size); + } + + return dns_var_value_valid(value, value_size); +} + +/** * Add dns vars received by the updown runner to an env set * - * Every var must be a name=value pair. If anything is invalid, the vars - * are rejected as a whole. + * Every var must be a name=value pair with a valid name and value. If + * anything is invalid, the vars are rejected as a whole. * * @param vars NUL terminated name=value strings, modified in place * @param size size of @p vars in bytes @@ -617,7 +762,8 @@ const size_t var_size = strlen(var); char *next = var + var_size + 1; char *eq = memchr(var, '=', var_size); - if (!eq) + if (!eq + || !dns_var_valid(var, (size_t)(eq - var), eq + 1, var_size - (size_t)(eq - var) - 1)) { return false; }