From patchwork Mon May 30 08:57:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Gruenbacher X-Patchwork-Id: 9140611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E322960757 for ; Mon, 30 May 2016 08:59:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D18A027BEF for ; Mon, 30 May 2016 08:59:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C23F228212; Mon, 30 May 2016 08:59:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 675FF27BEF for ; Mon, 30 May 2016 08:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754233AbcE3I7J (ORCPT ); Mon, 30 May 2016 04:59:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47847 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161262AbcE3I7G (ORCPT ); Mon, 30 May 2016 04:59:06 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34E0C8113B; Mon, 30 May 2016 08:59:06 +0000 (UTC) Received: from nux.redhat.com (vpn1-6-85.ams2.redhat.com [10.36.6.85]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4U8vYAo026102; Mon, 30 May 2016 04:58:59 -0400 From: Andreas Gruenbacher To: Alexander Viro Cc: Andreas Gruenbacher , linux-fsdevel@vger.kernel.org, Tyler Hicks , ecryptfs@vger.kernel.org, Miklos Szeredi , linux-unionfs@vger.kernel.org, Mimi Zohar , linux-ima-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, David Howells , Serge Hallyn , Dmitry Kasatkin , Paul Moore , Stephen Smalley , Eric Paris , Casey Schaufler , Oleg Drokin , Andreas Dilger Subject: [PATCH v3 11/17] vfs: Add IOP_XATTR inode operations flag Date: Mon, 30 May 2016 10:57:27 +0200 Message-Id: <1464598653-3656-12-git-send-email-agruenba@redhat.com> In-Reply-To: <1464598653-3656-1-git-send-email-agruenba@redhat.com> References: <1464598653-3656-1-git-send-email-agruenba@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 30 May 2016 08:59:06 +0000 (UTC) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The IOP_XATTR inode operations flag in inode->i_opflags indicates that the inode has xattr support. The flag is automatically set by new_inode() on filesystems with xattr support (where sb->s_xattr is defined), and cleared otherwise. Filesystems can explicitly clear it for inodes that should not have xattr support. Signed-off-by: Andreas Gruenbacher --- fs/inode.c | 2 ++ fs/xattr.c | 12 ++++++++---- include/linux/fs.h | 1 + 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/fs/inode.c b/fs/inode.c index 4ccbc21..aaad9b2 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -140,6 +140,8 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_fop = &no_open_fops; inode->__i_nlink = 1; inode->i_opflags = 0; + if (sb->s_xattr) + inode->i_opflags |= IOP_XATTR; i_uid_write(inode, 0); i_gid_write(inode, 0); atomic_set(&inode->i_writecount, 0); diff --git a/fs/xattr.c b/fs/xattr.c index 09df3c1..bc3cb69 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -53,10 +53,13 @@ strcmp_prefix(const char *a, const char *a_prefix) * Find the xattr_handler with the matching prefix. */ static const struct xattr_handler * -xattr_resolve_name(const struct xattr_handler **handlers, const char **name) +xattr_resolve_name(struct inode *inode, const char **name) { + const struct xattr_handler **handlers = inode->i_sb->s_xattr; const struct xattr_handler *handler; + if (!(inode->i_opflags & IOP_XATTR)) + return ERR_PTR(-EOPNOTSUPP); for_each_xattr_handler(handlers, handler) { const char *n; @@ -291,6 +294,7 @@ nolsm: error = -EOPNOTSUPP; return error; + } EXPORT_SYMBOL_GPL(vfs_getxattr); @@ -693,7 +697,7 @@ generic_getxattr(struct dentry *dentry, struct inode *inode, { const struct xattr_handler *handler; - handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); + handler = xattr_resolve_name(inode, &name); if (IS_ERR(handler)) return PTR_ERR(handler); return handler->get(handler, dentry, inode, @@ -748,7 +752,7 @@ generic_setxattr(struct dentry *dentry, struct inode *inode, const char *name, if (size == 0) value = ""; /* empty EA, do not remove */ - handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); + handler = xattr_resolve_name(inode, &name); if (IS_ERR(handler)) return PTR_ERR(handler); return handler->set(handler, dentry, inode, name, value, size, flags); @@ -763,7 +767,7 @@ generic_removexattr(struct dentry *dentry, const char *name) { const struct xattr_handler *handler; - handler = xattr_resolve_name(dentry->d_sb->s_xattr, &name); + handler = xattr_resolve_name(d_inode(dentry), &name); if (IS_ERR(handler)) return PTR_ERR(handler); return handler->set(handler, dentry, d_inode(dentry), name, NULL, diff --git a/include/linux/fs.h b/include/linux/fs.h index a1f69bd..365e212 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -593,6 +593,7 @@ is_uncached_acl(struct posix_acl *acl) #define IOP_FASTPERM 0x0001 #define IOP_LOOKUP 0x0002 #define IOP_NOFOLLOW 0x0004 +#define IOP_XATTR 0x0008 /* * Keep mostly read-only and often accessed (especially for