From patchwork Fri Mar 27 16:50:27 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: 6110001 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 04A39BF90F for ; Fri, 27 Mar 2015 16:56:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0D2C7203F3 for ; Fri, 27 Mar 2015 16:56:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10414203DA for ; Fri, 27 Mar 2015 16:56:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754259AbbC0Q4d (ORCPT ); Fri, 27 Mar 2015 12:56:33 -0400 Received: from mail-wg0-f41.google.com ([74.125.82.41]:33205 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754026AbbC0QwU (ORCPT ); Fri, 27 Mar 2015 12:52:20 -0400 Received: by wgbgs4 with SMTP id gs4so14563772wgb.0; Fri, 27 Mar 2015 09:52:19 -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=p8aAUX9TyRfAbl0ZmRseXLkjWoSylXoJxkeMkQTO+mw=; b=O5C0akODldmahQhaDdPWlDUDlyN6tLYcFhkkg6AtI1DOmt0QewTHmjkLwegwx9A0pZ tu1UgEy/Hm1UmkCBBE+oNvb2aIUWvAI3rB+XCNWSCjKbFIiZ+Yeafrz9Q4qnJsqNGLRD EzOV/D7P1zbA0ODYIhLHaCo14FepTPEco+SC8XEeUQ/uLCKex9/IY1fDckGwsVG/Kqmg x2XDUurld/RP9HpEglHLgrWZZbWWAmEkor5wIA/5Nn+4uCVnPCNLd8k8u7ohvn+ATCzm vW0CnCHnP4oQExA+yr1QSt0q+qkWookoNBV3954NQ3FrSpMZTuvYGcRr3/CPi0teTOXj Aj2A== X-Received: by 10.194.85.46 with SMTP id e14mr38295485wjz.110.1427475139221; Fri, 27 Mar 2015 09:52:19 -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.17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 09:52:18 -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 29/39] richacl: Create acl with masks applied in richacl_from_mode() Date: Fri, 27 Mar 2015 17:50:27 +0100 Message-Id: <77629072ba55ba8e9044bf0775e54fec61dd5a98.1427471526.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 When creating a richacl that represents a particular file mode, one approach is to create one everyone@ allow entry and set the richacl masks according to the file mode; when those masks are applied with richacl_apply_masks(), that everyone@ allow entry gets transformed as needed. The other approach is to compute the result after richacl_apply_masks() directly; this commit does that. Signed-off-by: Andreas Gruenbacher --- fs/richacl_compat.c | 85 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 68 insertions(+), 17 deletions(-) diff --git a/fs/richacl_compat.c b/fs/richacl_compat.c index 8454621..9f99e21 100644 --- a/fs/richacl_compat.c +++ b/fs/richacl_compat.c @@ -755,30 +755,81 @@ EXPORT_SYMBOL_GPL(richacl_apply_masks); struct richacl * richacl_from_mode(mode_t mode) { + unsigned int owner_mask = richacl_mode_to_mask(mode >> 6) | + RICHACE_POSIX_OWNER_ALLOWED; + unsigned int group_mask = richacl_mode_to_mask(mode >> 3); + unsigned int other_mask = richacl_mode_to_mask(mode); + unsigned int denied; + unsigned int entries = 0; struct richacl *acl; struct richace *ace; - acl = richacl_alloc(1, GFP_KERNEL); + /* RICHACE_DELETE_CHILD is meaningless for non-directories. */ + if (!S_ISDIR(mode)) { + owner_mask &= ~RICHACE_DELETE_CHILD; + group_mask &= ~RICHACE_DELETE_CHILD; + other_mask &= ~RICHACE_DELETE_CHILD; + } + + if (owner_mask & ~(group_mask & other_mask)) + entries++; /* OWNER@ ALLOW entry needed */ + denied = ~owner_mask & (group_mask | other_mask); + if (denied) + entries++; /* OWNER@ DENY entry needed */ + if (group_mask & ~other_mask) + entries++; /* GROUP@ ALLOW entry needed */ + denied = ~group_mask & other_mask; + if (denied) + entries++; /* GROUP@ DENY entry needed */ + if (other_mask) + entries++; /* EVERYONE@ ALLOW entry needed */ + + acl = richacl_alloc(entries, GFP_KERNEL); if (!acl) return NULL; - acl->a_flags = RICHACL_MASKED; - acl->a_owner_mask = richacl_mode_to_mask(mode >> 6) | - RICHACE_POSIX_OWNER_ALLOWED; - acl->a_group_mask = richacl_mode_to_mask(mode >> 3); - acl->a_other_mask = richacl_mode_to_mask(mode); - + acl->a_owner_mask = owner_mask; + acl->a_group_mask = group_mask; + acl->a_other_mask = other_mask; ace = acl->a_entries; - ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; - ace->e_flags = RICHACE_SPECIAL_WHO; - ace->e_mask = RICHACE_POSIX_ALWAYS_ALLOWED | - RICHACE_POSIX_MODE_ALL | - RICHACE_POSIX_OWNER_ALLOWED; - /* RICHACE_DELETE_CHILD is meaningless for non-directories. */ - if (!S_ISDIR(mode)) - ace->e_mask &= ~RICHACE_DELETE_CHILD; - ace->e_id.special = RICHACE_EVERYONE_SPECIAL_ID; - return acl; + if (owner_mask & ~(group_mask & other_mask)) { + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = owner_mask; + ace->e_id.special = RICHACE_OWNER_SPECIAL_ID; + ace++; + } + denied = ~owner_mask & (group_mask | other_mask); + if (denied) { + ace->e_type = RICHACE_ACCESS_DENIED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = denied; + ace->e_id.special = RICHACE_OWNER_SPECIAL_ID; + ace++; + } + if (group_mask & ~other_mask) { + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = group_mask; + ace->e_id.special = RICHACE_GROUP_SPECIAL_ID; + ace++; + } + denied = ~group_mask & other_mask; + if (denied) { + ace->e_type = RICHACE_ACCESS_DENIED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = denied; + ace->e_id.special = RICHACE_GROUP_SPECIAL_ID; + ace++; + } + if (other_mask) { + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = other_mask; + ace->e_id.special = RICHACE_EVERYONE_SPECIAL_ID; + ace++; + } + return acl; } EXPORT_SYMBOL_GPL(richacl_from_mode);