From patchwork Thu Jan 5 22:03:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Graziano X-Patchwork-Id: 9499745 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 33E67606B5 for ; Thu, 5 Jan 2017 22:33:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 251E42845A for ; Thu, 5 Jan 2017 22:33:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19CA42846F; Thu, 5 Jan 2017 22:33:05 +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 BB2212845A for ; Thu, 5 Jan 2017 22:33:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161980AbdAEWNA (ORCPT ); Thu, 5 Jan 2017 17:13:00 -0500 Received: from da1vs02.rockwellcollins.com ([205.175.227.29]:18981 "EHLO da1vs02.rockwellcollins.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932970AbdAEWMM (ORCPT ); Thu, 5 Jan 2017 17:12:12 -0500 X-Greylist: delayed 487 seconds by postgrey-1.27 at vger.kernel.org; Thu, 05 Jan 2017 17:12:12 EST 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 6DBAB62676; 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 1/3] xattr: add simple initxattrs function Date: Thu, 5 Jan 2017 16:03:41 -0600 Message-Id: <1483653823-22018-2-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 Adds new simple_xattr_initxattrs() initialization function for initializing the extended attributes via LSM callback. Based on callback function used by tmpfs/shmem. This is allows for consolidation and avoiding code duplication when other filesystem need to implement a simple initxattrs LSM callback function. Signed-off-by: David Graziano --- fs/xattr.c | 39 +++++++++++++++++++++++++++++++++++++++ include/linux/xattr.h | 3 +++ 2 files changed, 42 insertions(+) diff --git a/fs/xattr.c b/fs/xattr.c index c243905..69dd142 100644 --- a/fs/xattr.c +++ b/fs/xattr.c @@ -994,3 +994,42 @@ void simple_xattr_list_add(struct simple_xattrs *xattrs, list_add(&new_xattr->list, &xattrs->head); spin_unlock(&xattrs->lock); } + +/* + * Callback for security_inode_init_security() for acquiring xattrs. + */ +int simple_xattr_initxattrs(struct inode *inode, + const struct xattr *xattr_array, + void *fs_info) +{ + struct simple_xattrs *xattrs; + const struct xattr *xattr; + struct simple_xattr *new_xattr; + size_t len; + + if (!fs_info) + return -ENOMEM; + xattrs = (struct simple_xattrs *) fs_info; + + 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(xattrs, new_xattr); + } + + return 0; +} diff --git a/include/linux/xattr.h b/include/linux/xattr.h index 94079ba..a787d1a 100644 --- a/include/linux/xattr.h +++ b/include/linux/xattr.h @@ -108,5 +108,8 @@ ssize_t simple_xattr_list(struct inode *inode, struct simple_xattrs *xattrs, cha size_t size); void simple_xattr_list_add(struct simple_xattrs *xattrs, struct simple_xattr *new_xattr); +int simple_xattr_initxattrs(struct inode *inode, + const struct xattr *xattr_array, + void *fs_info); #endif /* _LINUX_XATTR_H */