From patchwork Tue Dec 1 14:23:11 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 5830 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:6022:91c9:10b0:11b:d6c:f273 with SMTP id tl9-n1csp14768261lad; Tue, 1 Dec 2026 06:23:29 -0800 (PST) X-Forwarded-Encrypted: i=2; AL+hErG6470Dg0HVZcCac92V1AnG6RTESnMKXJgknquoeXgR6P+eHFTN04EsiN3fYzT2sFrmDNm3j9AxR+Q=@openvpn.net X-Received: by 2002:a17:90b:4ec5:b0:3ac:7e3a:1033 with SMTP id 98e67ed59e1d1-3b41c96182bmr37176399a91.59.1796135009541; Tue, 01 Dec 2026 06:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1796135009; cv=none; d=google.com; s=arc-20260327; b=gIjxW4ScVMT8HVRN/YrRzLfZ9n9g/fFSkgMkz6KodT1evcSnpO/obQQ5ISWRdEHIob LotdJ64Cd63x0Cwr+o6gKtaQKhiyvufdpJe7qMp1cz+5EKFvH35dpm7kyemQVfAYSo5F /LmsP3qFjUaJnC9UqjP3Fb7g24EpKGQuEm3xyIsqeMdinlyQt4XX/UKPw+ZyeiLKUChe croO0YSFFs4viEH70nnP7oW2IKRiMQ9Er+7Ubx4sUH3QztvmRiCKb6O0DYfLpLBClGa5 er27sLFb0X11V80G5KiRbHN/9bMcdsUjcH3Sm3a5q3nlFUEvdUH7W8pvOD4Hi00EsTq2 FuZg== 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=vr1S5F5u4UOohYjOnedoQTD4+U3jfuP+zA9StrjTnxc=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=cQb8j67FKr3rZbmK1NbFFY6QDPl38LwlWzncLASl1BhqyrcQAUvebBaPRfcWvNuJKV QpuTB1FmDsflnExI8p+JDOUVCnSZHF7jT8ECDCSk/6oHWjWZjk+VU988dQG9cuVIPpLT qeuS/tfXwoOioKZC5148COfreDzEtT11JMW6Iw2WcaQgUQsEe3suV90XzyxnBaOmxFg5 KWbHcnKNvSGDu+rCykspyVp0A+HY02Vs8m4++YO77nJOIxhsDXEWfVCGs5B4o16gpPeo VhvB/jI2icMN9Kzg+XyQbiax8Ewzq+yEZA4r7YfJwbO8Kc7twNZd4fOZ2CoRpBC3nrz/ 6GBw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b=JzRc2rts; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RFIWxorD; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Hmom1zuH; 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 98e67ed59e1d1-3b41aecbbb2si76223607a91.10.2026.12.01.06.23.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Dec 2026 06:23:29 -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=JzRc2rts; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=RFIWxorD; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=Hmom1zuH; 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=vr1S5F5u4UOohYjOnedoQTD4+U3jfuP+zA9StrjTnxc=; b=JzRc2rtsnq+3Rq D6UNwmjltkcdP8j+FMOqW2LoWcNMj6+6RC4V4IJ4abGwDlnWN3fiSX9ns0vEP/ECbT4LBEoyPxgr0 a1CptZzTMpY9GXK79ovKauvpFfpm8eGBxO1ieN6BccPb82UwCXmy6a0CqGrj5mjkxXodSyucCsinc WXc=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.100.1) (envelope-from ) id 1xYOlU-00000000452-0WOo; Tue, 01 Dec 2026 14:23:28 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xYOlS-0000000044v-3xvs for openvpn-devel@lists.sourceforge.net; Tue, 01 Dec 2026 14:23:26 +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=PGGxYzxtpKUapOjQKQBHUa+o48z4ZV17qUwykOhHOBY=; b=RFIWxorDjsArAeifoiDwfXlJjo MLof09pLBBan8ljWw8AqhCifjEOERmshkVGP1Ffwkgx1GehkDV9Wy2Q5YpkBlLIRshjh5b3G5NwNu XGrYZveed3e1ZGLkd4FwnzBRfTFYQlKZqYOqtmk+ptdxxT4VA+iK2Hl7MfQYcNpzIAsY=; 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=PGGxYzxtpKUapOjQKQBHUa+o48z4ZV17qUwykOhHOBY=; b=Hmom1zuHew50Cclhd+dDY9U7M7 EDQjnjj2TzNKaukn6rUxzYfKyX/relh3K7JFe7O/Ji9x1m4wAV3tgYosNmDo+pbWbBNRX/owy0BAn pEv0SHsArDq74Krade+vTwg6bM74ttgyPNczSWrutWQvqj5hDz6kt0tnEJ3MPG5kgiiQ=; 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 1xYOlP-000000001Hs-3raO for openvpn-devel@lists.sourceforge.net; Tue, 01 Dec 2026 14:23:26 +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 6B1ENG0w030344 for ; Tue, 1 Dec 2026 15:23:16 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.2/8.18.1/Submit) id 6B1ENGY9030343 for openvpn-devel@lists.sourceforge.net; Tue, 1 Dec 2026 15:23:16 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Tue, 1 Dec 2026 15:23:11 +0100 Message-ID: <20261201142316.30318-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 ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1xYOlP-000000001Hs-3raO Subject: [Openvpn-devel] [PATCH v6] 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: 1883384063993002632 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 6 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..8c6fd97 100644 --- a/src/openvpn/dns.c +++ b/src/openvpn/dns.c @@ -591,10 +591,168 @@ #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. dns_vars_file is + * rejected, since older dns-updown scripts source the file it names. + * + * @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 (dns_var_name_is(name, size, "dns_vars_file")) + { + return false; + } + + 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 + * slash is only allowed on Haiku, where interface names look like tun/0, + * since it would turn the name into a path elsewhere. A name must not start + * with a dash or a dot, so that it cannot be taken for an option, a hidden + * file or a parent directory. + * + * @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) +{ +#if defined(TARGET_HAIKU) + const char extra[] = "+@%,=/"; +#else + const char extra[] = "+@%,="; +#endif + + if (size == 0 || size >= IFNAMSIZ || value[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) && !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 +775,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; }