From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161988AbdAEWNA (ORCPT ); Thu, 5 Jan 2017 17:13:00 -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 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: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 1.9.1