Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S261464AbVETPHj (ORCPT ); Fri, 20 May 2005 11:07:39 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S261470AbVETPHi (ORCPT ); Fri, 20 May 2005 11:07:38 -0400 Received: from e31.co.us.ibm.com ([32.97.110.129]:16295 "EHLO e31.co.us.ibm.com") by vger.kernel.org with ESMTP id S261464AbVETPGs (ORCPT ); Fri, 20 May 2005 11:06:48 -0400 Date: Fri, 20 May 2005 10:06:33 -0500 From: Michael Halcrow To: Andrew Morton Cc: linux-kernel@vger.kernel.org, Chris Wright , Serge Hallyn , mhalcrow@us.ibm.com Subject: [updated patch 3/7] BSD Secure Levels: allow suid and sgid on directories Message-ID: <20050520150632.GB5534@halcrow.us> Reply-To: Michael Halcrow References: <20050517152303.GA2814@halcrow.us> <20050519205525.GB16215@halcrow.us> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050519205525.GB16215@halcrow.us> User-Agent: Mutt/1.5.9i Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2423 Lines: 72 This patch is applies cleanly against the new printk() patch. It allows setuid and setgid on directories. It also disallows the creation of setuid/setgid executables via open or mknod. Signed off by: Michael Halcrow Index: linux-2.6.12-rc4-mm2-seclvl/security/seclvl.c =================================================================== --- linux-2.6.12-rc4-mm2-seclvl.orig/security/seclvl.c 2005-05-19 17:46:13.000000000 -0500 +++ linux-2.6.12-rc4-mm2-seclvl/security/seclvl.c 2005-05-20 09:09:03.000000000 -0500 @@ -582,7 +582,11 @@ static int seclvl_inode_setattr(struct dentry *dentry, struct iattr *iattr) { if (seclvl > 0) { - if (iattr->ia_valid & ATTR_MODE) + if (dentry && dentry->d_inode + && S_ISDIR(dentry->d_inode->i_mode)) { + return 0; + } + if (iattr && iattr->ia_valid & ATTR_MODE) if (iattr->ia_mode & S_ISUID || iattr->ia_mode & S_ISGID) { seclvl_printk(1, KERN_WARNING, "Attempt to " @@ -596,6 +600,34 @@ } /** + * Prevent an end-run around the inode_setattr control. + */ +static int seclvl_inode_mknod(struct inode *inode, struct dentry *dentry, + int mode, dev_t dev) +{ + if (seclvl > 0 && (mode & 02000 || mode & 04000)) { + seclvl_printk(1, KERN_WARNING, "Attempt to mknod with suid " + "or guid bit set in seclvl [%d]\n", seclvl); + return -EPERM; + } + return 0; +} + +/** + * Prevent an end-run around the inode_setattr control. + */ +static int +seclvl_inode_create(struct inode *inode, struct dentry *dentry, int mask) +{ + if (seclvl > 0 && (mask & 02000 || mask & 04000)) { + seclvl_printk(1, KERN_WARNING, "Attempt to create inode with " + "suid or guid bit set in seclvl [%d]\n", seclvl); + return -EPERM; + } + return 0; +} + +/** * Release busied block devices. */ static void seclvl_file_free_security(struct file *filp) @@ -630,6 +662,8 @@ .file_permission = seclvl_file_permission, .file_mmap = seclvl_file_mmap, .inode_setattr = seclvl_inode_setattr, + .inode_mknod = seclvl_inode_mknod, + .inode_create = seclvl_inode_create, .file_free_security = seclvl_file_free_security, .settime = seclvl_settime, .sb_umount = seclvl_umount, - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/