From patchwork Sat Feb 16 14:55:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Selva Nair X-Patchwork-Id: 685 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director10.mail.ord1d.rsapps.net ([172.28.255.1]) by backend30.mail.ord1d.rsapps.net with LMTP id IITNBn6/aFxJOAAAIUCqbw for ; Sat, 16 Feb 2019 20:57:18 -0500 Received: from director3.mail.ord1c.rsapps.net ([172.28.255.1]) by director10.mail.ord1d.rsapps.net with LMTP id oDWmBn6/aFzrIgAApN4f7A ; Sat, 16 Feb 2019 20:57:18 -0500 Received: from smtp18.gate.ord1c ([172.28.255.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by director3.mail.ord1c.rsapps.net with LMTP id yB6GBn6/aFwYVwAAdSFV8w ; Sat, 16 Feb 2019 20:57:18 -0500 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp18.gate.ord1c.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dkim=fail (signature verification failed) header.d=gmail.com; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: 5a694f46-3257-11e9-8308-bc305bf00c68-1-1 Received: from [216.105.38.7] ([216.105.38.7:48354] helo=lists.sourceforge.net) by smtp18.gate.ord1c.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id E9/BB-05384-D7FB86C5; Sat, 16 Feb 2019 20:57:17 -0500 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.90_1) (envelope-from ) id 1gvBga-0001gM-U6; Sun, 17 Feb 2019 01:56:04 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gvBgZ-0001fq-0e for openvpn-devel@lists.sourceforge.net; Sun, 17 Feb 2019 01:56:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=KefkST+kurJlbvXzFT50hApjJfQoPDXEi/u7foQBTm8=; b=F7vknfdraLuJfyUinB72tcanF5 fp/F8IqFtLVkWG+uBuHu9YVngCFyDl5jX0R6HRAoUq0LfnxU7jtL+zGsn6Dm60AdXyVjTumT78v5a EDuYctpqU1r5BEhG+5KVTtG5QjSDqWbOJBWyS+a+RUGFcD7rZFpjSXzHvdPXt2avnRDg=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version: Content-Type:Content-Transfer-Encoding:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=KefkST+kurJlbvXzFT50hApjJfQoPDXEi/u7foQBTm8=; b=PgqwW8FU3Y5rjWYpwGmVUhrhVr roEntoqCgpyeaK5VuMvJTEvVsJk7ABcGgVO5GtH8EFAi/rILHMg7jaI+MaKH5uTSlIjLDJSciYTKa mvBEM8oeFmY+wYqufYQ7N5TXeFJIEsGZiPg86opdFWeJRQWBABYbEYUnGrp7fm1n7J1Q=; Received: from mail-it1-f195.google.com ([209.85.166.195]) by sfi-mx-1.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) id 1gvBgO-002L8e-Nx for openvpn-devel@lists.sourceforge.net; Sun, 17 Feb 2019 01:56:00 +0000 Received: by mail-it1-f195.google.com with SMTP id z131so22981835itf.5 for ; Sat, 16 Feb 2019 17:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=KefkST+kurJlbvXzFT50hApjJfQoPDXEi/u7foQBTm8=; b=AbkZZW/2jagwJXZiAwJY+p75TLglSDVd9/OF5acOuqYCjfRspCaiYFMxgA7H3J57Wm Y4/vzOc8A4d6/+vLddXw468+Nflo9jjFaRWIaEE/+V7LKsq8UjYJlTFMPyp/S3neUt5M MS3ljd1ZUf/rw+pdOFDqVnBJXZBf8hZyrWSg7kqGfm8MOCvef373zDC+yF4GGkRC9HHt MsBhb9ZB5pclWiAOqvO5FbKk/pSFRdQH/Az6Cr7zmWs/bhzPtvB9x/Q0BBcIxwI8uWpO DkaMUDKvqfAgh73Zl1vjhcBUbK/BfVe8S+7d8ryoG7ER2PjgkfqdYbrNX1+OSyz1JkJS XkfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=KefkST+kurJlbvXzFT50hApjJfQoPDXEi/u7foQBTm8=; b=Vp2u8tHsXR7uEvQ2SWdQ8q0D3ORyvnfjy936g4gsp2g7XQ2ZDKGaIi5RXxM20dna+C e5MFxMLmIS2YBTwc5Bi5mP+4vvYO1pk7YSC8TwLBqZbPcyOl6pnwjuv885xZqFYEwThG yfp1uN6qeu+SaIW7rk+0Y+zfPvrinyX41CmjnJZprL7W6mYYF2q++nH4ZOq+eTn8OqDG W99BVgjJO+5CSJLr47AaSV4fc+PB4xgjyZcW59EoVUizJP9K5Q1islFokjryFm4phWp0 udFMCGvsjf6mP0eef0Lm9Bo1TGAYT5+XyIidxee0a2P6rWc8+Vw7OVG90a0WOEEbwu0y N20Q== X-Gm-Message-State: AHQUAubcgHUljxnCGVLrwfFwEa5Z07PsOTy5ABzPEuU5UFOZa6z/Q9J0 yx8lFZUCbfoZVUO1JWcsLeCtoFk2 X-Google-Smtp-Source: AHgI3IZWxlrP5Bsu+y3JHjTbjxvSbsYT/sIgP1lFN4q2X2hNj5RP3fcCXuVZt7ChptnhCFInTdocuA== X-Received: by 2002:a24:5352:: with SMTP id n79mr8167247itb.148.1550368546727; Sat, 16 Feb 2019 17:55:46 -0800 (PST) Received: from saturn.home.sansel.ca (CPE40167ea0e1c2-CM788df74daaa0.cpe.net.cable.rogers.com. [99.228.215.92]) by smtp.gmail.com with ESMTPSA id u18sm4081439ioc.64.2019.02.16.17.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 16 Feb 2019 17:55:46 -0800 (PST) From: selva.nair@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Sat, 16 Feb 2019 20:55:41 -0500 Message-Id: <1550368541-10402-1-git-send-email-selva.nair@gmail.com> X-Mailer: git-send-email 2.1.4 X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (selva.nair[at]gmail.com) -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.166.195 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.166.195 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-Headers-End: 1gvBgO-002L8e-Nx Subject: [Openvpn-devel] [PATCH] Better error message when script fails due to script-security setting 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: , MIME-Version: 1.0 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Selva Nair - Add a new return value (-2) for openvpn_execve() when external program execution is not allowed due to a low script-security setting. - Add a corresponding error message Errors and warnings in such cases will now display as "WARNING: failed running command () :" followed by "disallowed by script-security setting" on all platforms instead of the current "external program did not execute -- returned error code -1" on Windows and "external program fork failed" on other platforms. The error is FATAL for some scripts and that behaviour is unchanged. This helps the Windows GUI to detect when a connection failure results from a safer script-security setting enforced by the GUI, and show a relevant message. Signed-off-by: Selva Nair --- This is being presented as a better alternative for patch 684. A separate patch may be needed for 2.4 -- will do if this is found acceptable. src/openvpn/run_command.c | 25 +++++++++++++++++++++---- src/openvpn/win32.c | 10 +++++++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/openvpn/run_command.c b/src/openvpn/run_command.c index 2d75a3e..7df7576 100644 --- a/src/openvpn/run_command.c +++ b/src/openvpn/run_command.c @@ -65,12 +65,23 @@ system_error_message(int stat, struct gc_arena *gc) { buf_printf(&out, "external program did not execute -- "); } - buf_printf(&out, "returned error code %d", stat); + if (stat == -2) + { + buf_printf(&out, "disallowed by script-security setting"); + } + else + { + buf_printf(&out, "returned error code %d", stat); + } #else /* ifdef _WIN32 */ if (stat == -1) { buf_printf(&out, "external program fork failed"); } + else if (stat == -2) + { + buf_printf(&out, "disallowed by script-security setting"); + } else if (!WIFEXITED(stat)) { buf_printf(&out, "external program did not exit normally"); @@ -114,6 +125,8 @@ openvpn_execve_allowed(const unsigned int flags) * Run execve() inside a fork(). Designed to replicate the semantics of system() but * in a safer way that doesn't require the invocation of a shell or the risks * associated with formatting and parsing a command line. + * Returns the exit status of child, -2 if openvpn_execve_allowed() returned false, + * or -1 on other errors. */ int openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned int flags) @@ -150,10 +163,14 @@ openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned in } } } - else if (!warn_shown && (script_security() < SSEC_SCRIPTS)) + else { - msg(M_WARN, SCRIPT_SECURITY_WARNING); - warn_shown = true; + ret = -2; + if (!warn_shown && (script_security() < SSEC_SCRIPTS)) + { + msg(M_WARN, SCRIPT_SECURITY_WARNING); + warn_shown = true; + } } #else /* if defined(ENABLE_FEATURE_EXECVE) */ msg(M_WARN, "openvpn_execve: execve function not available"); diff --git a/src/openvpn/win32.c b/src/openvpn/win32.c index 463ac07..4eb7c40 100644 --- a/src/openvpn/win32.c +++ b/src/openvpn/win32.c @@ -1137,10 +1137,14 @@ openvpn_execve(const struct argv *a, const struct env_set *es, const unsigned in free(env); gc_free(&gc); } - else if (!exec_warn && (script_security() < SSEC_SCRIPTS)) + else { - msg(M_WARN, SCRIPT_SECURITY_WARNING); - exec_warn = true; + ret = -2; + if (!exec_warn && (script_security() < SSEC_SCRIPTS)) + { + msg(M_WARN, SCRIPT_SECURITY_WARNING); + exec_warn = true; + } } } else