From patchwork Wed Feb 25 23:41:26 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: 5885801 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 4DC72BF440 for ; Wed, 25 Feb 2015 23:47:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83E8320109 for ; Wed, 25 Feb 2015 23:47:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8FB63200E9 for ; Wed, 25 Feb 2015 23:47:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932263AbbBYXrg (ORCPT ); Wed, 25 Feb 2015 18:47:36 -0500 Received: from mail-wi0-f171.google.com ([209.85.212.171]:48438 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753041AbbBYXmJ (ORCPT ); Wed, 25 Feb 2015 18:42:09 -0500 Received: by mail-wi0-f171.google.com with SMTP id ex7so16611242wid.4; Wed, 25 Feb 2015 15:42:07 -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=/sDX2Z2fkwRfXKpoFaMQbdJ72sTUWYbeNqnfyfyAnZg=; b=kOzBfVZwGrg7mla+78KNYT1eyQRJgM8Xw4txmag1jr8DZmuB64I7X+Dd1bGC88fg/v kGMTeFL7bjWsf62bzIZ19ZiYNu+wLi7hbS2df3LyeF/JbNnbja7PYEgQV8A7Qx/+0rGJ 9NG8DkQdmHeJt+F2CHS+tZ7Nz5Fd1W/NQNRcH/4puX0B3B4DoEvX23WEgwogxzH1dscM zRBGCWVSnBu5aChRB5IfHrdFiipVeO3ENht/6oXKLlF0cwAavMcOSktgpeqqPSvTAJoA k5U5gBT3T0H2H8Tlr8AagqI88L6Om+B3SobMaVzVE41FfMAsx9To0qGXshPhlQjn57JR JSBw== X-Received: by 10.194.216.138 with SMTP id oq10mr10963451wjc.133.1424907727825; Wed, 25 Feb 2015 15:42:07 -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.06 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 25 Feb 2015 15:42:07 -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 05/21] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD permission flags Date: Thu, 26 Feb 2015 00:41:26 +0100 Message-Id: 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 Normally, deleting a file requires write and execute access to the parent directory. With Richacls, a process with MAY_DELETE_SELF access to a file may delete the file even without write access to the parent directory. To support that, pass the MAY_DELETE_CHILD mask flag to inode_permission() when checking for delete access inside a directory, and MAY_DELETE_SELF when checking for delete access to a file itelf. The MAY_DELETE_SELF permission does not override the sticky directory check. Signed-off-by: Andreas Gruenbacher --- fs/namei.c | 15 +++++++++++---- include/linux/fs.h | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index a8bc030..a8d1674 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -455,7 +455,7 @@ static int sb_permission(struct super_block *sb, struct inode *inode, int mask) * changing the "normal" UIDs which are used for other things. * * When checking for MAY_APPEND, MAY_CREATE_FILE, MAY_CREATE_DIR, - * MAY_WRITE must also be set in @mask. + * MAY_DELETE_CHILD, MAY_DELETE_SELF, MAY_WRITE must also be set in @mask. */ int inode_permission(struct inode *inode, int mask) { @@ -2452,7 +2452,7 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir, bool replace) { struct inode *inode = victim->d_inode; - int error, mask = MAY_WRITE | MAY_EXEC; + int error, mask = MAY_EXEC; if (d_is_negative(victim)) return -ENOENT; @@ -2462,8 +2462,15 @@ static int may_delete(struct inode *dir, struct dentry *victim, audit_inode_child(dir, victim, AUDIT_TYPE_CHILD_DELETE); if (replace) - mask |= isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE; - error = inode_permission(dir, mask); + mask |= MAY_WRITE | (isdir ? MAY_CREATE_DIR : MAY_CREATE_FILE); + error = inode_permission(dir, mask | MAY_WRITE | MAY_DELETE_CHILD); + if (error && IS_RICHACL(inode)) { + /* Deleting is also permitted with MAY_EXEC on the directory + * and MAY_DELETE_SELF on the inode. */ + if (!inode_permission(inode, MAY_DELETE_SELF) && + !inode_permission(dir, mask)) + error = 0; + } if (error) return error; if (IS_APPEND(dir)) diff --git a/include/linux/fs.h b/include/linux/fs.h index bbe1d26..101abcf 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -82,6 +82,8 @@ typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define MAY_NOT_BLOCK 0x00000080 #define MAY_CREATE_FILE 0x00000100 #define MAY_CREATE_DIR 0x00000200 +#define MAY_DELETE_CHILD 0x00000400 +#define MAY_DELETE_SELF 0x00000800 /* * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond