From owner-svn-src-all@freebsd.org Sat Jul 14 17:21:18 2018 Return-Path: Delivered-To: svn-src-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 E69E61033D89; Sat, 14 Jul 2018 17:21:17 +0000 (UTC) (envelope-from stevek@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 97EC881A65; Sat, 14 Jul 2018 17:21:17 +0000 (UTC) (envelope-from stevek@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 5F64221EDF; Sat, 14 Jul 2018 17:21:17 +0000 (UTC) (envelope-from stevek@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6EHLH1Q047726; Sat, 14 Jul 2018 17:21:17 GMT (envelope-from stevek@FreeBSD.org) Received: (from stevek@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6EHLHIU047725; Sat, 14 Jul 2018 17:21:17 GMT (envelope-from stevek@FreeBSD.org) Message-Id: <201807141721.w6EHLHIU047725@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: stevek set sender to stevek@FreeBSD.org using -f From: "Stephen J. Kiernan" Date: Sat, 14 Jul 2018 17:21:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336289 - head/sys/security/mac_veriexec X-SVN-Group: head X-SVN-Commit-Author: stevek X-SVN-Commit-Paths: head/sys/security/mac_veriexec X-SVN-Commit-Revision: 336289 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jul 2018 17:21:18 -0000 Author: stevek Date: Sat Jul 14 17:21:16 2018 New Revision: 336289 URL: https://svnweb.freebsd.org/changeset/base/336289 Log: Add mpo_vnode_check_setmode MAC method to MAC/veriexec. In the method, disallow changing SUID/SGID on verified files. Obtained from: Juniper Networks, Inc. Modified: head/sys/security/mac_veriexec/mac_veriexec.c Modified: head/sys/security/mac_veriexec/mac_veriexec.c ============================================================================== --- head/sys/security/mac_veriexec/mac_veriexec.c Sat Jul 14 17:20:27 2018 (r336288) +++ head/sys/security/mac_veriexec/mac_veriexec.c Sat Jul 14 17:21:16 2018 (r336289) @@ -550,6 +550,38 @@ mac_veriexec_vnode_check_open(struct ucred *cred, stru } /** + * @brief Check mode changes on file to ensure they should be allowed. + * + * We cannot allow chmod of SUID or SGID on verified files. + * + * @param cred credentials to use + * @param vp vnode of the file to open + * @param label vnode label assigned to the vnode + * @param mode mode flags to set + * + * @return 0 if the mode change should be allowed, EAUTH otherwise. + */ +static int +mac_veriexec_vnode_check_setmode(struct ucred *cred, struct vnode *vp, + struct label *label __unused, mode_t mode) +{ + int error; + + if ((mac_veriexec_state & VERIEXEC_STATE_ENFORCE) == 0) + return (0); + + /* + * Do not allow chmod (set-[gu]id) of verified file + */ + error = mac_veriexec_check_vp(cred, vp, VVERIFY); + if (error == EAUTH) /* it isn't verified */ + return (0); + if (error == 0 && (mode & (S_ISUID|S_ISGID)) != 0) + return (EAUTH); + return (0); +} + +/** * @internal * @brief Initialize the mac_veriexec MAC policy * @@ -673,6 +705,7 @@ static struct mac_policy_ops mac_veriexec_ops = .mpo_proc_check_debug = mac_veriexec_proc_check_debug, .mpo_vnode_check_exec = mac_veriexec_vnode_check_exec, .mpo_vnode_check_open = mac_veriexec_vnode_check_open, + .mpo_vnode_check_setmode = mac_veriexec_vnode_check_setmode, .mpo_vnode_copy_label = mac_veriexec_copy_label, .mpo_vnode_destroy_label = mac_veriexec_vnode_destroy_label, .mpo_vnode_init_label = mac_veriexec_vnode_init_label,