From patchwork Thu Jan 5 22:03:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Graziano X-Patchwork-Id: 9499747 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 7B5BF606B5 for ; Thu, 5 Jan 2017 22:33:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CDF02845A for ; Thu, 5 Jan 2017 22:33:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 618AB2846C; Thu, 5 Jan 2017 22:33:14 +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 0CEAE2845A for ; Thu, 5 Jan 2017 22:33:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S936716AbdAEWM7 (ORCPT ); Thu, 5 Jan 2017 17:12:59 -0500 Received: from da1vs02.rockwellcollins.com ([205.175.227.29]:38299 "EHLO da1vs02.rockwellcollins.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936598AbdAEWMM (ORCPT ); Thu, 5 Jan 2017 17:12:12 -0500 Received: from ofwda1n02.rockwellcollins.com (HELO dtulimr01.rockwellcollins.com) ([205.175.227.14]) by da1vs02.rockwellcollins.com with ESMTP; 05 Jan 2017 16:04:05 -0600 X-Received: from thehammer.rockwellcollins.com (unknown [192.168.141.197]) by dtulimr01.rockwellcollins.com (Postfix) with ESMTP id BCE8962674; Thu, 5 Jan 2017 16:04:03 -0600 (CST) From: David Graziano To: linux-security-module@vger.kernel.org, paul@paul-moore.com Cc: agruenba@redhat.com, hch@infradead.org, linux-mm@kvack.org, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org, David Graziano Subject: [PATCH v4 2/3] shmem: use simple initxattrs callback Date: Thu, 5 Jan 2017 16:03:42 -0600 Message-Id: <1483653823-22018-3-git-send-email-david.graziano@rockwellcollins.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483653823-22018-1-git-send-email-david.graziano@rockwellcollins.com> References: <1483653823-22018-1-git-send-email-david.graziano@rockwellcollins.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Updates shmem to use the newly created simple_xattr_initxattrs() function to minimize code duplication with other LSM callback functions. Signed-off-by: David Graziano --- mm/shmem.c | 53 ++++++++++++----------------------------------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 971fc83..ef4bd52 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -33,6 +33,7 @@ #include #include #include +#include static struct vfsmount *shm_mnt; @@ -2140,7 +2141,7 @@ static const struct inode_operations shmem_symlink_inode_operations; static const struct inode_operations shmem_short_symlink_operations; #ifdef CONFIG_TMPFS_XATTR -static int shmem_initxattrs(struct inode *, const struct xattr *, void *); +#define shmem_initxattrs simple_xattr_initxattrs #else #define shmem_initxattrs NULL #endif @@ -2892,6 +2893,7 @@ static int shmem_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) { struct inode *inode; + struct shmem_inode_info *info; int error = -ENOSPC; inode = shmem_get_inode(dir->i_sb, dir, mode, dev, VM_NORESERVE); @@ -2899,9 +2901,11 @@ shmem_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev) error = simple_acl_create(dir, inode); if (error) goto out_iput; + info = SHMEM_I(inode); error = security_inode_init_security(inode, dir, &dentry->d_name, - shmem_initxattrs, NULL); + shmem_initxattrs, + &info->xattrs); if (error && error != -EOPNOTSUPP) goto out_iput; @@ -2921,13 +2925,16 @@ static int shmem_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) { struct inode *inode; + struct shmem_inode_info *info; int error = -ENOSPC; inode = shmem_get_inode(dir->i_sb, dir, mode, 0, VM_NORESERVE); if (inode) { + info = SHMEM_I(inode); error = security_inode_init_security(inode, dir, NULL, - shmem_initxattrs, NULL); + shmem_initxattrs, + &info->xattrs); if (error && error != -EOPNOTSUPP) goto out_iput; error = simple_acl_create(dir, inode); @@ -3119,8 +3126,9 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s if (!inode) return -ENOSPC; + info = SHMEM_I(inode); error = security_inode_init_security(inode, dir, &dentry->d_name, - shmem_initxattrs, NULL); + shmem_initxattrs, &info->xattrs); if (error) { if (error != -EOPNOTSUPP) { iput(inode); @@ -3129,7 +3137,6 @@ static int shmem_symlink(struct inode *dir, struct dentry *dentry, const char *s error = 0; } - info = SHMEM_I(inode); inode->i_size = len-1; if (len <= SHORT_SYMLINK_LEN) { inode->i_link = kmemdup(symname, len, GFP_KERNEL); @@ -3198,42 +3205,6 @@ static const char *shmem_get_link(struct dentry *dentry, * filesystem level, though. */ -/* - * Callback for security_inode_init_security() for acquiring xattrs. - */ -static int shmem_initxattrs(struct inode *inode, - const struct xattr *xattr_array, - void *fs_info) -{ - struct shmem_inode_info *info = SHMEM_I(inode); - const struct xattr *xattr; - struct simple_xattr *new_xattr; - size_t len; - - for (xattr = xattr_array; xattr->name != NULL; xattr++) { - new_xattr = simple_xattr_alloc(xattr->value, xattr->value_len); - if (!new_xattr) - return -ENOMEM; - - len = strlen(xattr->name) + 1; - new_xattr->name = kmalloc(XATTR_SECURITY_PREFIX_LEN + len, - GFP_KERNEL); - if (!new_xattr->name) { - kfree(new_xattr); - return -ENOMEM; - } - - memcpy(new_xattr->name, XATTR_SECURITY_PREFIX, - XATTR_SECURITY_PREFIX_LEN); - memcpy(new_xattr->name + XATTR_SECURITY_PREFIX_LEN, - xattr->name, len); - - simple_xattr_list_add(&info->xattrs, new_xattr); - } - - return 0; -} - static int shmem_xattr_handler_get(const struct xattr_handler *handler, struct dentry *unused, struct inode *inode, const char *name, void *buffer, size_t size)