From patchwork Wed Jul 22 13:03:17 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: 6843111 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 6682EC05AC for ; Wed, 22 Jul 2015 13:11:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8C6A0206CC for ; Wed, 22 Jul 2015 13:11:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A31A4206B6 for ; Wed, 22 Jul 2015 13:11:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933402AbbGVNL3 (ORCPT ); Wed, 22 Jul 2015 09:11:29 -0400 Received: from mail-wi0-f179.google.com ([209.85.212.179]:37065 "EHLO mail-wi0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756692AbbGVNEi (ORCPT ); Wed, 22 Jul 2015 09:04:38 -0400 Received: by wibud3 with SMTP id ud3so171499085wib.0; Wed, 22 Jul 2015 06:04:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nDQSoNvdfFdHQPuFhu85DOrQx24oRUaC0Q17aiBvHD8=; b=e9DNDldKJo4eDqBb/sh0RgxggUrQjElLVt2NT8K6juk58A58RJOKe8WNPhrUIfjtGv AtNSya4w1pQZ6VCVa8pMidBXDeSCuD1sBHFP7CWhBL2gGXA+F52uGsioACX0x1aIOnBA nSeYmO1JoilXJauShlAve6uV+rt5Wet/3exaQNN5vDbQiLD1zCU+IwL6Xt9Xr8/TBiCn EQ5ixviOe4/CKX8mTm3IBOrBKpI1T5tDYYx3ZMgBBnQsNIkccuf4JVKRRKutcoQ3vyrd Erek7FKtVk8aYoI80MqYw/ySY3i1MoAtOkMPtMRCthuMk+qm9Y7QGXHITo63e3XYmNra zsJg== X-Received: by 10.194.121.131 with SMTP id lk3mr4790795wjb.77.1437570276975; Wed, 22 Jul 2015 06:04:36 -0700 (PDT) Received: from schleppi.home.com ([149.14.88.26]) by smtp.gmail.com with ESMTPSA id u7sm21992628wif.3.2015.07.22.06.04.35 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Jul 2015 06:04:36 -0700 (PDT) From: Andreas Gruenbacher To: linux-kernel@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-api@vger.kernel.org, samba-technical@lists.samba.org, linux-security-module@vger.kernel.org, Andreas Gruenbacher Subject: [PATCH v5 27/39] richacl: Create richacl from mode values Date: Wed, 22 Jul 2015 15:03:17 +0200 Message-Id: <1437570209-29832-28-git-send-email-andreas.gruenbacher@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1437570209-29832-1-git-send-email-andreas.gruenbacher@gmail.com> References: <1437570209-29832-1-git-send-email-andreas.gruenbacher@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-8.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 From: Andreas Gruenbacher Signed-off-by: Andreas Gruenbacher --- fs/richacl_compat.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 89 insertions(+) diff --git a/fs/richacl_compat.c b/fs/richacl_compat.c index 05219ce..b7d3990 100644 --- a/fs/richacl_compat.c +++ b/fs/richacl_compat.c @@ -813,3 +813,91 @@ richacl_apply_masks(struct richacl **acl, kuid_t owner) return 0; } EXPORT_SYMBOL_GPL(richacl_apply_masks); + +/** + * richacl_from_mode - create an acl which corresponds to @mode + * + * The resulting acl doesn't have the RICHACL_MASKED flag set. + * + * @mode: file mode including the file type + */ +struct richacl * +richacl_from_mode(mode_t mode) +{ + unsigned int owner_mask = richacl_mode_to_mask(mode >> 6); + 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; + + /* 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; + } + + denied = ~owner_mask & (group_mask | other_mask); + if (denied) + entries++; /* owner@ deny entry needed */ + if (owner_mask & ~(group_mask & other_mask)) + entries++; /* owner@ allow entry needed */ + denied = ~group_mask & other_mask; + if (denied) + entries++; /* group@ deny entry needed */ + if (group_mask & ~other_mask) + entries++; /* group@ allow entry needed */ + if (other_mask) + entries++; /* everyone@ allow entry needed */ + + acl = richacl_alloc(entries, GFP_KERNEL); + if (!acl) + return NULL; + acl->a_owner_mask = owner_mask; + acl->a_group_mask = group_mask; + acl->a_other_mask = other_mask; + ace = acl->a_entries; + + 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 (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 = ~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 (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++; + } + 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); diff --git a/include/linux/richacl.h b/include/linux/richacl.h index ef23581..eeb5bd9 100644 --- a/include/linux/richacl.h +++ b/include/linux/richacl.h @@ -338,5 +338,6 @@ extern struct richacl *richacl_create(struct inode *, struct inode *); /* richacl_compat.c */ extern int richacl_apply_masks(struct richacl **, kuid_t); +extern struct richacl *richacl_from_mode(mode_t); #endif /* __RICHACL_H */