From patchwork Fri Mar 27 16:50:15 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: 6110411 Return-Path: X-Original-To: patchwork-linux-nfs@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 B72DB9F39E for ; Fri, 27 Mar 2015 17:01:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA7632035E for ; Fri, 27 Mar 2015 17:01:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C2134203DA for ; Fri, 27 Mar 2015 17:01:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754577AbbC0RBV (ORCPT ); Fri, 27 Mar 2015 13:01:21 -0400 Received: from mail-wi0-f178.google.com ([209.85.212.178]:35799 "EHLO mail-wi0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753947AbbC0QwC (ORCPT ); Fri, 27 Mar 2015 12:52:02 -0400 Received: by wibbg6 with SMTP id bg6so33638867wib.0; Fri, 27 Mar 2015 09:52:01 -0700 (PDT) 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=e3vMIlSiceUN1Pg4AsS+hKhSVIsYXQZ8yNXKkRcP1Fo=; b=TPSZet/9lSYd5X0LQRfDZDGZue0ri1JGv5FbX+D3T7xENAVzMXahAX/4toXD5viA9t 0sZYLUxazVlStCmTZ0vmGxoQaMySy+rs6+oLo4dozj6imjDgAyD5RB6rZPa5Tn5qR0nt Ne6R2HuV1sbx10suI9ojiSp1wqZ5orP4JnD6EzHtE5VDh5Srdiq25jMAhzFfIbfezIcp YE1Ge4/UehhzO4f8p+PhuRb6/+rlV40WCATdzBNNx51JDYjAZYmmwNvFTdMHBsf3TyG5 dLgeDHAKdFImmo8jVwJ6DmTJs26p/+7biQN2JVAKQQO9eKwc05wFeXewXF6QWdZa3zlC xVMQ== X-Received: by 10.195.12.35 with SMTP id en3mr37896725wjd.129.1427475121511; Fri, 27 Mar 2015 09:52:01 -0700 (PDT) Received: from nuc.home.com (80-110-94-70.cgn.dynamic.surfer.at. [80.110.94.70]) by mx.google.com with ESMTPSA id j7sm3592306wix.4.2015.03.27.09.52.00 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 09:52:00 -0700 (PDT) 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 17/39] richacl: Check if an acl is equivalent to a file mode Date: Fri, 27 Mar 2015 17:50:15 +0100 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@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 This function is used to avoid storing richacls if the acl can be computed from the file permission bits. Signed-off-by: Andreas Gruenbacher --- fs/richacl_base.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 55 insertions(+) diff --git a/fs/richacl_base.c b/fs/richacl_base.c index d3a5e9b..2e3a2c9 100644 --- a/fs/richacl_base.c +++ b/fs/richacl_base.c @@ -485,3 +485,57 @@ richacl_inherit(const struct richacl *dir_acl, int isdir) return acl; } + +/** + * richacl_equiv_mode - check if @acl is equivalent to file permission bits + * @mode_p: the file mode (including the file type) + * + * If @acl can be fully represented by file permission bits, this function + * returns 0, and the file permission bits in @mode_p are set to the equivalent + * of @acl. + * + * This function is used to avoid storing richacls on disk if the acl can be + * computed from the file permission bits. It allows user-space to make sure + * that a file has no explicit richacl set. + */ +int +richacl_equiv_mode(const struct richacl *acl, mode_t *mode_p) +{ + const struct richace *ace = acl->a_entries; + unsigned int x; + mode_t mode; + + if (acl->a_count != 1 || + acl->a_flags != RICHACL_MASKED || + !richace_is_everyone(ace) || + !richace_is_allow(ace) || + ace->e_flags & ~RICHACE_SPECIAL_WHO) + return -1; + + /* + * Figure out the permissions we care about: RICHACE_DELETE_CHILD is + * meaningless for non-directories, so we ignore it. + */ + x = ~RICHACE_POSIX_ALWAYS_ALLOWED; + if (!S_ISDIR(*mode_p)) + x &= ~RICHACE_DELETE_CHILD; + + mode = richacl_masks_to_mode(acl); + if ((acl->a_group_mask & x) != (richacl_mode_to_mask(mode >> 3) & x) || + (acl->a_other_mask & x) != (richacl_mode_to_mask(mode) & x)) + return -1; + + /* + * Ignore permissions which the owner is always allowed. + */ + x &= ~RICHACE_POSIX_OWNER_ALLOWED; + if ((acl->a_owner_mask & x) != (richacl_mode_to_mask(mode >> 6) & x)) + return -1; + + if ((ace->e_mask & x) != (RICHACE_POSIX_MODE_ALL & x)) + return -1; + + *mode_p = (*mode_p & ~S_IRWXUGO) | mode; + return 0; +} +EXPORT_SYMBOL_GPL(richacl_equiv_mode); diff --git a/include/linux/richacl.h b/include/linux/richacl.h index 63c787b..4db73aa 100644 --- a/include/linux/richacl.h +++ b/include/linux/richacl.h @@ -296,6 +296,7 @@ extern unsigned int richacl_want_to_mask(unsigned int); extern void richacl_compute_max_masks(struct richacl *); extern struct richacl *richacl_chmod(struct richacl *, mode_t); extern struct richacl *richacl_inherit(const struct richacl *, int); +extern int richacl_equiv_mode(const struct richacl *, mode_t *); /* richacl_inode.c */ extern int richacl_permission(struct inode *, const struct richacl *, int);