From patchwork Tue Nov 3 15:17:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 7544601 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 29033BEEA4 for ; Tue, 3 Nov 2015 15:47:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 38D2720515 for ; Tue, 3 Nov 2015 15:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EF39204D2 for ; Tue, 3 Nov 2015 15:47:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964795AbbKCPUq (ORCPT ); Tue, 3 Nov 2015 10:20:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:45803 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932384AbbKCPUo (ORCPT ); Tue, 3 Nov 2015 10:20:44 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 4845EA4505; Tue, 3 Nov 2015 15:20:44 +0000 (UTC) Received: from nux.redhat.com (vpn1-5-101.ams2.redhat.com [10.36.5.101]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tA3FHRZr029477; Tue, 3 Nov 2015 10:20:38 -0500 From: Andreas Gruenbacher To: Alexander Viro , "Theodore Ts'o" , Andreas Dilger , "J. Bruce Fields" , Jeff Layton , Trond Myklebust , Anna Schumaker , Dave Chinner , linux-ext4@vger.kernel.org, xfs@oss.sgi.com, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org, linux-api@vger.kernel.org Cc: Andreas Gruenbacher Subject: [PATCH v13 27/51] xfs: Fix richacl access by ioctl Date: Tue, 3 Nov 2015 16:17:03 +0100 Message-Id: <1446563847-14005-28-git-send-email-agruenba@redhat.com> In-Reply-To: <1446563847-14005-1-git-send-email-agruenba@redhat.com> References: <1446563847-14005-1-git-send-email-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Make sure that the XFS_IOC_ATTRMULTI_BY_HANDLE ioctl exposes richacls in the same way as the xattr interface: check for mode-equivalent richacls, update the inode permission bits, and perform user namespace mapping. Signed-off-by: Andreas Gruenbacher --- fs/xfs/xfs_ioctl.c | 27 +++++++++++++++++++++++++++ fs/xfs/xfs_richacl.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- fs/xfs/xfs_richacl.h | 3 +++ 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index e939c20..deae7df 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -40,6 +40,7 @@ #include "xfs_symlink.h" #include "xfs_trans.h" #include "xfs_pnfs.h" +#include "xfs_richacl.h" #include #include @@ -48,6 +49,7 @@ #include #include #include +#include /* * xfs_find_handle maps from userspace xfs_fsop_handlereq structure to @@ -461,10 +463,20 @@ xfs_attrmulti_attr_get( if (!kbuf) return -ENOMEM; + if (flags & ATTR_ROOT) { + if (!strcmp(name, XATTR_RICHACL)) { + error = xfs_richacl_get_ioctl(inode, kbuf, (int *)len); + if (error) + goto out_kfree; + goto out_copy; + } + } + error = xfs_attr_get(XFS_I(inode), name, kbuf, (int *)len, flags); if (error) goto out_kfree; +out_copy: if (copy_to_user(ubuf, kbuf, *len)) error = -EFAULT; @@ -493,7 +505,16 @@ xfs_attrmulti_attr_set( if (IS_ERR(kbuf)) return PTR_ERR(kbuf); + if (flags & ATTR_ROOT) { + if (!strcmp(name, XATTR_RICHACL)) { + error = xfs_richacl_set_ioctl(inode, kbuf, len, flags); + goto out_kfree; + } + } + error = xfs_attr_set(XFS_I(inode), name, kbuf, len, flags); + +out_kfree: kfree(kbuf); return error; } @@ -506,6 +527,12 @@ xfs_attrmulti_attr_remove( { if (IS_IMMUTABLE(inode) || IS_APPEND(inode)) return -EPERM; + + if (flags & ATTR_ROOT) { + if (!strcmp(name, XATTR_RICHACL)) + return xfs_richacl_set_ioctl(inode, NULL, 0, flags); + } + return xfs_attr_remove(XFS_I(inode), name, flags); } diff --git a/fs/xfs/xfs_richacl.c b/fs/xfs/xfs_richacl.c index 92a036e..f8f5a62 100644 --- a/fs/xfs/xfs_richacl.c +++ b/fs/xfs/xfs_richacl.c @@ -67,8 +67,8 @@ xfs_remove_richacl(struct inode *inode) return error; } -int -xfs_set_richacl(struct inode *inode, struct richacl *acl) +static int +__xfs_set_richacl(struct inode *inode, struct richacl *acl, int xflags) { struct xfs_inode *ip = XFS_I(inode); umode_t mode = inode->i_mode; @@ -88,8 +88,7 @@ xfs_set_richacl(struct inode *inode, struct richacl *acl) if (!value) return -ENOMEM; richacl_to_xattr(&init_user_ns, acl, value, size); - error = xfs_attr_set(ip, XATTR_RICHACL, value, size, - ATTR_ROOT); + error = xfs_attr_set(ip, XATTR_RICHACL, value, size, xflags); kfree(value); if (error) return error; @@ -101,3 +100,48 @@ xfs_set_richacl(struct inode *inode, struct richacl *acl) return 0; } + +int +xfs_set_richacl(struct inode *inode, struct richacl *acl) +{ + return __xfs_set_richacl(inode, acl, ATTR_ROOT); +} + +int +xfs_richacl_get_ioctl(struct inode *inode, void *value, int *len) +{ + struct user_namespace *user_ns = current_user_ns(); + struct richacl *acl; + int error; + + acl = get_richacl(inode); + if (IS_ERR_OR_NULL(acl)) + return PTR_ERR(acl); + error = richacl_to_xattr(user_ns, acl, value, *len); + if (error > 0) { + *len = error; + error = 0; + } + richacl_put(acl); + return error; +} + +int +xfs_richacl_set_ioctl(struct inode *inode, void *value, unsigned int size, + int xflags) +{ + struct user_namespace *user_ns = current_user_ns(); + struct richacl *acl = NULL; + int error; + + if (!IS_RICHACL(inode)) + return -EOPNOTSUPP; + if (value) { + acl = richacl_from_xattr(user_ns, value, size); + if (IS_ERR(acl)) + return PTR_ERR(acl); + } + error = __xfs_set_richacl(inode, acl, xflags); + richacl_put(acl); + return error; +} diff --git a/fs/xfs/xfs_richacl.h b/fs/xfs/xfs_richacl.h index 431aa25..1fd1fc1 100644 --- a/fs/xfs/xfs_richacl.h +++ b/fs/xfs/xfs_richacl.h @@ -20,4 +20,7 @@ struct richacl; extern struct richacl *xfs_get_richacl(struct inode *); extern int xfs_set_richacl(struct inode *, struct richacl *); +extern int xfs_richacl_get_ioctl(struct inode *, void *, int *); +extern int xfs_richacl_set_ioctl(struct inode *, void *, int, int); + #endif /* __FS_XFS_RICHACL_H */