Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1552368

[PATCH v4 1/3] xattr: add simple initxattrs function

Path csiph.com!eternal-september.org!feeder.eternal-september.org!aioe.org!bofh.it!news.nic.it!robomod
From David Graziano <david.graziano@rockwellcollins.com>
Newsgroups linux.kernel
Subject [PATCH v4 1/3] xattr: add simple initxattrs function
Date Thu, 05 Jan 2017 23:20:01 +0100
Message-ID <sWoy5-G2-5@gated-at.bofh.it> (permalink)
References <sWooq-BR-25@gated-at.bofh.it>
X-Greylist delayed 487 seconds by postgrey-1.27 at vger.kernel.org; Thu, 05 Jan 2017 17:12:12 EST
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)
X-Mailer git-send-email 1.9.1
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 74
Organization linux.* mail to news gateway
X-Original-Cc agruenba@redhat.com, hch@infradead.org, linux-mm@kvack.org, sds@tycho.nsa.gov, linux-kernel@vger.kernel.org, David Graziano <david.graziano@rockwellcollins.com>
X-Original-Date Thu, 5 Jan 2017 16:03:41 -0600
X-Original-Message-ID <1483653823-22018-2-git-send-email-david.graziano@rockwellcollins.com>
X-Original-References <1483653823-22018-1-git-send-email-david.graziano@rockwellcollins.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1552368

Show key headers only | View raw


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 <david.graziano@rockwellcollins.com>
---
 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 */
-- 
1.9.1

Back to linux.kernel | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 1/3] xattr: add simple initxattrs function David Graziano <david.graziano@rockwellcollins.com> - 2017-01-05 23:20 +0100
  Re: [PATCH v4 1/3] xattr: add simple initxattrs function Christoph Hellwig <hch@infradead.org> - 2017-01-08 11:00 +0100
    Re: [PATCH v4 1/3] xattr: add simple initxattrs function David Graziano <david.graziano@rockwellcollins.com> - 2017-01-09 16:50 +0100

csiph-web