From patchwork Wed Feb 25 23:41:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_Gr=C3=BCnbacher?= X-Patchwork-Id: 5885531 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 17FC09F373 for ; Wed, 25 Feb 2015 23:44:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1ED6720374 for ; Wed, 25 Feb 2015 23:44:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0183320268 for ; Wed, 25 Feb 2015 23:44:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932242AbbBYXoc (ORCPT ); Wed, 25 Feb 2015 18:44:32 -0500 Received: from mail-we0-f175.google.com ([74.125.82.175]:35494 "EHLO mail-we0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753851AbbBYXm3 (ORCPT ); Wed, 25 Feb 2015 18:42:29 -0500 Received: by wevl61 with SMTP id l61so6811257wev.2; Wed, 25 Feb 2015 15:42:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id:in-reply-to:references:in-reply-to :references; bh=38JnQVEd+s6tgveCeueclgRHwE3utjlkfaAYQqQIr9M=; b=Os2Woo3PwsyrMupWscuF+Tc2kcov2uHucniKyGmSjl18vZifIUM/OmewQBxnblKOQB iLIncyza9/o4imSdb9NyXgqq1NA2mQaRFyWROXYTUyN9VajC5JF8Ju+3m1kF5m6rei/G gMYCgfAaSldBhYZ1iyicgdM1RBMERKvZJrwD2/qxm0I8IeHPyWnauAXzaOcm6iNywdeH Vi19qP5j2KdrClUcrLMasYe05bUyylasfO040a5ckvzfYgtMetq+drGrQjeoOpZfb06g rKWMaWwmV7TpqJtBpt0frcKd4f47RjHit+yVFNPMUtySg6k1w+VC4gei2UMFrqJl1w0t 7E5Q== X-Received: by 10.180.189.203 with SMTP id gk11mr11073411wic.32.1424907747852; Wed, 25 Feb 2015 15:42:27 -0800 (PST) Received: from nuc.home.com (80-110-112-196.cgn.dynamic.surfer.at. [80.110.112.196]) by mx.google.com with ESMTPSA id vh8sm66946337wjc.12.2015.02.25.15.42.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 15:42:27 -0800 (PST) From: Andreas Gruenbacher X-Google-Original-From: Andreas Gruenbacher To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Subject: [RFC 15/21] richacl: Automatic Inheritance Date: Thu, 26 Feb 2015 00:41:36 +0100 Message-Id: <39c338514faf1b135b8515db11c58720f6897e9d.1424907511.git.agruenba@redhat.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Automatic Inheritance (AI) allows changes to the acl of a directory to recursively propagate down to files and directories in the directory. To implement this, the kernel keeps track of which permissions have been inherited, and makes sure that permission propagation is turned off when the file permission bits of a file are changed (upon create or chmod). The actual permission propagation is implemented in user space. Automatic Inheritance works as follows: - When the ACL4_AUTO_INHERIT flag in the acl of a file is not set, the file is not affected by AI. - When the ACL4_AUTO_INHERIT flag in the acl of a directory is set and a file or subdirectory is created in that directory, files created in the directory will have the ACL4_AUTO_INHERIT flag set, and all inherited aces will have the ACE4_INHERITED_ACE flag set. This allows user space to distinguish between aces which have been inherited and aces which have been explicitly added. - When the ACL4_PROTECTED acl flag in the acl of a file is set, AI will not modify the acl of the file. This does not affect propagation of permissions from the file to its children (if the file is a directory). Linux does not have a way of creating files without setting the file permission bits, so all files created inside a directory with ACL4_AUTO_INHERIT set will also have the ACL4_PROTECTED flag set. This effectively disables Automatic Inheritance. Protocols which support creating files without specifying permissions can explicitly clear the ACL4_PROTECTED flag after creating a file and reset the file masks to "undo" applying the create mode; see richacl_compute_max_masks(). This is a workaround; a mechanism that would allow a process to indicate to the kernel to ignore the create mode when there are inherited permissions would fix this problem. Signed-off-by: Andreas Gruenbacher --- fs/richacl_base.c | 10 +++++++++- fs/richacl_inode.c | 7 ++++++- include/linux/richacl.h | 24 +++++++++++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/fs/richacl_base.c b/fs/richacl_base.c index c853f7e..ec570ef 100644 --- a/fs/richacl_base.c +++ b/fs/richacl_base.c @@ -324,7 +324,8 @@ richacl_chmod(struct richacl *acl, mode_t mode) if (acl->a_owner_mask == owner_mask && acl->a_group_mask == group_mask && acl->a_other_mask == other_mask && - (acl->a_flags & ACL4_MASKED)) + (acl->a_flags & ACL4_MASKED) && + (!richacl_is_auto_inherit(acl) || richacl_is_protected(acl))) return acl; clone = richacl_clone(acl); @@ -336,6 +337,8 @@ richacl_chmod(struct richacl *acl, mode_t mode) clone->a_owner_mask = owner_mask; clone->a_group_mask = group_mask; clone->a_other_mask = other_mask; + if (richacl_is_auto_inherit(clone)) + clone->a_flags |= ACL4_PROTECTED; return clone; } @@ -518,6 +521,11 @@ richacl_inherit(const struct richacl *dir_acl, int isdir) ace++; } } + if (richacl_is_auto_inherit(dir_acl)) { + acl->a_flags = ACL4_AUTO_INHERIT; + richacl_for_each_entry(ace, acl) + ace->e_flags |= ACE4_INHERITED_ACE; + } return acl; } diff --git a/fs/richacl_inode.c b/fs/richacl_inode.c index b95a584..9f96564 100644 --- a/fs/richacl_inode.c +++ b/fs/richacl_inode.c @@ -40,9 +40,14 @@ richacl_inherit_inode(const struct richacl *dir_acl, struct inode *inode) acl = richacl_inherit(dir_acl, S_ISDIR(inode->i_mode)); if (acl) { + /* + * We need to set ACL4_PROTECTED because we are + * doing an implicit chmod + */ + if (richacl_is_auto_inherit(acl)) + acl->a_flags |= ACL4_PROTECTED; richacl_compute_max_masks(acl); - /* * Ensure that the acl will not grant any permissions beyond * the create mode. diff --git a/include/linux/richacl.h b/include/linux/richacl.h index 39072a0..a607d6f 100644 --- a/include/linux/richacl.h +++ b/include/linux/richacl.h @@ -49,10 +49,17 @@ struct richacl { _ace != (_acl)->a_entries - 1; \ _ace--) +/* a_flags values */ +#define ACL4_AUTO_INHERIT 0x01 +#define ACL4_PROTECTED 0x02 +#define ACL4_DEFAULTED 0x04 /* Flag values defined by richacls */ #define ACL4_MASKED 0x80 #define ACL4_VALID_FLAGS ( \ + ACL4_AUTO_INHERIT | \ + ACL4_PROTECTED | \ + ACL4_DEFAULTED | \ ACL4_MASKED) /* e_type values */ @@ -69,6 +76,7 @@ struct richacl { /*#define ACE4_SUCCESSFUL_ACCESS_ACE_FLAG 0x0010*/ /*#define ACE4_FAILED_ACCESS_ACE_FLAG 0x0020*/ #define ACE4_IDENTIFIER_GROUP 0x0040 +#define ACE4_INHERITED_ACE 0x0080 /* richacl specific flag values */ #define ACE4_SPECIAL_WHO 0x4000 @@ -78,6 +86,7 @@ struct richacl { ACE4_NO_PROPAGATE_INHERIT_ACE | \ ACE4_INHERIT_ONLY_ACE | \ ACE4_IDENTIFIER_GROUP | \ + ACE4_INHERITED_ACE | \ ACE4_SPECIAL_WHO) /* e_mask bitflags */ @@ -184,6 +193,18 @@ richacl_put(struct richacl *acl) kfree(acl); } +static inline int +richacl_is_auto_inherit(const struct richacl *acl) +{ + return acl->a_flags & ACL4_AUTO_INHERIT; +} + +static inline int +richacl_is_protected(const struct richacl *acl) +{ + return acl->a_flags & ACL4_PROTECTED; +} + /** * richace_is_owner - check if @ace is an OWNER@ entry */ @@ -254,7 +275,8 @@ richace_clear_inheritance_flags(struct richace *ace) ace->e_flags &= ~(ACE4_FILE_INHERIT_ACE | ACE4_DIRECTORY_INHERIT_ACE | ACE4_NO_PROPAGATE_INHERIT_ACE | - ACE4_INHERIT_ONLY_ACE); + ACE4_INHERIT_ONLY_ACE | + ACE4_INHERITED_ACE); } /**