From patchwork Tue Aug 4 11:53:01 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: 6938191 Return-Path: X-Original-To: patchwork-linux-nfs@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 D933DC05AC for ; Tue, 4 Aug 2015 12:11:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0215220398 for ; Tue, 4 Aug 2015 12:11:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 18BCF20395 for ; Tue, 4 Aug 2015 12:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933535AbbHDLyi (ORCPT ); Tue, 4 Aug 2015 07:54:38 -0400 Received: from mail-wi0-f171.google.com ([209.85.212.171]:32781 "EHLO mail-wi0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932776AbbHDLyd (ORCPT ); Tue, 4 Aug 2015 07:54:33 -0400 Received: by wijp15 with SMTP id p15so2344251wij.0; Tue, 04 Aug 2015 04:54:31 -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=fIDetu/yZn3ptjdCDNFn5CLXiq1lcYNsDfQX3yhCDYw=; b=vfqLY1zaztCXZnOvCtYlOUZl2nSOoqa2/4O4C1dmT+iPXX43o+VDBowLHm1W4cfY4n lheWMrbUr+pTc3J5QajDt42l3egnwjRFtkPzRpcUnJzVofR1Rj7k1z8OP9Rp1y5k8Xjz sw3lAmPD2KersusGQDOUw94QmedFWhgMSZ+ouApa5CKftt1U5F3ReYfyz7S9Q6CcKzS8 /+BXdSMKN8veFSdBdm7+vUqYjPxZEHVU5M2SKmqw4UfRk2rkc2mmDAiRACCXfRTSOkLn s5jZt+mD4wh7m/8eErZOweeo3rFEzbolLgycW0j4sKygL6QSX9stMtnnGK3EoTtGH0os nHzw== X-Received: by 10.194.121.131 with SMTP id lk3mr7028446wjb.77.1438689271638; Tue, 04 Aug 2015 04:54:31 -0700 (PDT) Received: from schleppi.home.com (p54980F84.dip0.t-ipconnect.de. [84.152.15.132]) by smtp.gmail.com with ESMTPSA id u7sm2018458wif.3.2015.08.04.04.54.29 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Aug 2015 04:54:30 -0700 (PDT) From: Andreas Gruenbacher X-Google-Original-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, linux-cifs@vger.kernel.org, linux-security-module@vger.kernel.org, Andreas Gruenbacher Subject: [RFC v6 03/40] vfs: Add MAY_DELETE_SELF and MAY_DELETE_CHILD permission flags Date: Tue, 4 Aug 2015 13:53:01 +0200 Message-Id: <1438689218-6921-4-git-send-email-agruenba@redhat.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438689218-6921-1-git-send-email-agruenba@redhat.com> References: <1438689218-6921-1-git-send-email-agruenba@redhat.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SUSPICIOUS_RECIPS, 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 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. It probably should. 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 3504d36..2ac759c 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -454,7 +454,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) { @@ -2527,7 +2527,7 @@ static int may_delete(struct inode *dir, struct dentry *victim, bool isdir, bool replace) { struct inode *inode = d_backing_inode(victim); - int error, mask = MAY_WRITE | MAY_EXEC; + int error, mask = MAY_EXEC; if (d_is_negative(victim)) return -ENOENT; @@ -2537,8 +2537,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 9c44f27..abf5b0e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -83,6 +83,8 @@ typedef void (dax_iodone_t)(struct buffer_head *bh_map, int uptodate); #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