From owner-svn-ports-all@freebsd.org Mon Apr 23 18:40:51 2018 Return-Path: Delivered-To: svn-ports-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6A57BFA90BA; Mon, 23 Apr 2018 18:40:51 +0000 (UTC) (envelope-from garga@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 1CA9C8390B; Mon, 23 Apr 2018 18:40:51 +0000 (UTC) (envelope-from garga@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1555A27E92; Mon, 23 Apr 2018 18:40:51 +0000 (UTC) (envelope-from garga@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w3NIeo2q048586; Mon, 23 Apr 2018 18:40:50 GMT (envelope-from garga@FreeBSD.org) Received: (from garga@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w3NIeouq048584; Mon, 23 Apr 2018 18:40:50 GMT (envelope-from garga@FreeBSD.org) Message-Id: <201804231840.w3NIeouq048584@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: garga set sender to garga@FreeBSD.org using -f From: Renato Botelho Date: Mon, 23 Apr 2018 18:40:50 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r468129 - in head/security/sudo: . files X-SVN-Group: ports-head X-SVN-Commit-Author: garga X-SVN-Commit-Paths: in head/security/sudo: . files X-SVN-Commit-Revision: 468129 X-SVN-Commit-Repository: ports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-all@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the ports tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Apr 2018 18:40:51 -0000 Author: garga Date: Mon Apr 23 18:40:50 2018 New Revision: 468129 URL: https://svnweb.freebsd.org/changeset/ports/468129 Log: Add a patch to fix cryptographic digest in command specification for shell scripts and other interpreted files. Error happens because fexecve() requires /dev/fd to be mounted. This patch detects if /dev/fd/N exists before attempt to use fexecve and workaround the issue. PR: 223587 Submitted by: Todd C. Miller Reported by: vas@mpeks.tomsk.su Obtained from: https://www.sudo.ws/repos/sudo/rev/30f7c5d64104 MFH: 2018Q2 Sponsored by: Rubicon Communications, LLC (Netgate) Added: head/security/sudo/files/patch-fix-fexecve (contents, props changed) Modified: head/security/sudo/Makefile Modified: head/security/sudo/Makefile ============================================================================== --- head/security/sudo/Makefile Mon Apr 23 18:37:39 2018 (r468128) +++ head/security/sudo/Makefile Mon Apr 23 18:40:50 2018 (r468129) @@ -3,7 +3,7 @@ PORTNAME= sudo PORTVERSION= 1.8.22 -PORTREVISION= 1 +PORTREVISION= 2 CATEGORIES= security MASTER_SITES= SUDO Added: head/security/sudo/files/patch-fix-fexecve ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/security/sudo/files/patch-fix-fexecve Mon Apr 23 18:40:50 2018 (r468129) @@ -0,0 +1,92 @@ + +# HG changeset patch +# User Todd C. Miller +# Date 1524502491 21600 +# Node ID 30f7c5d64104cdbae5c0a63e57aeec1d188c0f5b +# Parent a786a841f30a60c5f18b4ec476f8a749135d48ec +We can only use fexecve() on a script if /dev/fd/N exists. +Some systems, such as FreeBSD, don't have /dev/fd mounted +by default. Bug #831 + +diff -r a786a841f30a -r 30f7c5d64104 plugins/sudoers/match.c +--- plugins/sudoers/match.c Sun Apr 22 06:58:53 2018 -0600 ++++ plugins/sudoers/match.c Mon Apr 23 10:54:51 2018 -0600 +@@ -487,32 +487,22 @@ + debug_return_bool(stat(path, sb) == 0); + } + ++#ifdef HAVE_FEXECVE + /* +- * On systems with fexecve(2), set the close-on-exec flag on the file +- * descriptor only if the file is not a script. Because scripts need +- * to be executed by an interpreter the fd must remain open for the +- * interpreter to use. ++ * Check whether the fd refers to a shell script with a "#!" shebang. + */ +-static void +-set_cloexec(int fd) ++static bool ++is_script(int fd) + { +- bool is_script = false; +-#ifdef HAVE_FEXECVE ++ bool ret = false; + char magic[2]; + +- /* Check for #! cookie and set is_script. */ + if (read(fd, magic, 2) == 2) { + if (magic[0] == '#' && magic[1] == '!') +- is_script = true; ++ ret = true; + } + (void) lseek(fd, (off_t)0, SEEK_SET); +-#endif /* HAVE_FEXECVE */ +- /* +- * Shell scripts go through namei twice and so we can't set the close +- * on exec flag on the fd for fexecve(2). +- */ +- if (!is_script) +- (void)fcntl(fd, F_SETFD, FD_CLOEXEC); ++ return ret; + } + + /* +@@ -541,10 +531,36 @@ + if (fd == -1) + debug_return_bool(false); + +- set_cloexec(fd); ++ if (is_script(fd)) { ++ char fdpath[PATH_MAX]; ++ struct stat sb; ++ ++ /* We can only use fexecve() on a script if /dev/fd/N exists. */ ++ snprintf(fdpath, sizeof(fdpath), "/dev/fd/%d", fd); ++ if (stat(fdpath, &sb) != 0) { ++ close(fd); ++ debug_return_bool(false); ++ } ++ ++ /* ++ * Shell scripts go through namei twice so we can't set the ++ * close on exec flag on the fd for fexecve(2). ++ */ ++ } else { ++ /* Not a script, close on exec is safe. */ ++ (void)fcntl(fd, F_SETFD, FD_CLOEXEC); ++ } ++ + *fdp = fd; + debug_return_bool(true); + } ++#else /* HAVE_FEXECVE */ ++static bool ++open_cmnd(const char *path, const struct sudo_digest *digest, int *fdp) ++{ ++ return true; ++} ++#endif /* HAVE_FEXECVE */ + + static bool + command_matches_fnmatch(const char *sudoers_cmnd, const char *sudoers_args, +