All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
	Christoph Hellwig <hch@infradead.org>,
	Eric Paris <eparis@redhat.com>,
	"Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>,
	linux-fsdevel@vger.kernel.org,
	David Quigley <dpquigl@davequigley.com>,
	"J. Bruce Fields" <bfields@fieldses.org>
Cc: linux-security-module@vger.kernel.org, cluster-devel@redhat.com
Subject: [RFC 03/11] 9p: Simplify the xattr handlers
Date: Thu, 20 Aug 2015 20:19:50 +0200	[thread overview]
Message-ID: <1440094798-1411-4-git-send-email-agruenba@redhat.com> (raw)
In-Reply-To: <1440094798-1411-1-git-send-email-agruenba@redhat.com>

The generic_{get,set,remove}xattr inode operations use the xattr name prefix to
decide which of the defined xattr handlers to call, then call the appropriate
handler's get or set operation.  The name suffix is passed to the get or set
operations, the prefix is still "there" in the name before the suffix though.
There is no need to recompose the name in a temporary buffer.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/9p/xattr_security.c | 34 ++++------------------------------
 fs/9p/xattr_trusted.c  | 34 ++++------------------------------
 fs/9p/xattr_user.c     | 34 ++++------------------------------
 3 files changed, 12 insertions(+), 90 deletions(-)

diff --git a/fs/9p/xattr_security.c b/fs/9p/xattr_security.c
index cb247a1..2c9b394 100644
--- a/fs/9p/xattr_security.c
+++ b/fs/9p/xattr_security.c
@@ -22,10 +22,7 @@
 static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@ static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@ static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_security_handler = {
diff --git a/fs/9p/xattr_trusted.c b/fs/9p/xattr_trusted.c
index e30d33b..ee470b6 100644
--- a/fs/9p/xattr_trusted.c
+++ b/fs/9p/xattr_trusted.c
@@ -22,10 +22,7 @@
 static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
+	const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@ static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
+	const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@ static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_trusted_handler = {
diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c
index d0b701b..4432604 100644
--- a/fs/9p/xattr_user.c
+++ b/fs/9p/xattr_user.c
@@ -22,10 +22,7 @@
 static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_USER_PREFIX_LEN;
+	const char *full_name = name - XATTR_USER_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@ static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_USER_PREFIX_LEN;
+	const char *full_name = name - XATTR_USER_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@ static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_user_handler = {
-- 
2.4.3


WARNING: multiple messages have this Message-ID (diff)
From: Andreas Gruenbacher <andreas.gruenbacher@gmail.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [RFC 03/11] 9p: Simplify the xattr handlers
Date: Thu, 20 Aug 2015 20:19:50 +0200	[thread overview]
Message-ID: <1440094798-1411-4-git-send-email-agruenba@redhat.com> (raw)
In-Reply-To: <1440094798-1411-1-git-send-email-agruenba@redhat.com>

The generic_{get,set,remove}xattr inode operations use the xattr name prefix to
decide which of the defined xattr handlers to call, then call the appropriate
handler's get or set operation.  The name suffix is passed to the get or set
operations, the prefix is still "there" in the name before the suffix though.
There is no need to recompose the name in a temporary buffer.

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
 fs/9p/xattr_security.c | 34 ++++------------------------------
 fs/9p/xattr_trusted.c  | 34 ++++------------------------------
 fs/9p/xattr_user.c     | 34 ++++------------------------------
 3 files changed, 12 insertions(+), 90 deletions(-)

diff --git a/fs/9p/xattr_security.c b/fs/9p/xattr_security.c
index cb247a1..2c9b394 100644
--- a/fs/9p/xattr_security.c
+++ b/fs/9p/xattr_security.c
@@ -22,10 +22,7 @@
 static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@ static int v9fs_xattr_security_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_SECURITY_PREFIX_LEN;
+	const char *full_name = name - XATTR_SECURITY_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@ static int v9fs_xattr_security_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_SECURITY_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_security_handler = {
diff --git a/fs/9p/xattr_trusted.c b/fs/9p/xattr_trusted.c
index e30d33b..ee470b6 100644
--- a/fs/9p/xattr_trusted.c
+++ b/fs/9p/xattr_trusted.c
@@ -22,10 +22,7 @@
 static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
+	const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@ static int v9fs_xattr_trusted_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_TRUSTED_PREFIX_LEN;
+	const char *full_name = name - XATTR_TRUSTED_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@ static int v9fs_xattr_trusted_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_TRUSTED_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_trusted_handler = {
diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c
index d0b701b..4432604 100644
--- a/fs/9p/xattr_user.c
+++ b/fs/9p/xattr_user.c
@@ -22,10 +22,7 @@
 static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
 			void *buffer, size_t size, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_USER_PREFIX_LEN;
+	const char *full_name = name - XATTR_USER_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -33,26 +30,13 @@ static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
-	memcpy(full_name+prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_get(dentry, full_name, buffer, size);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_get(dentry, full_name, buffer, size);
 }
 
 static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
 			const void *value, size_t size, int flags, int type)
 {
-	int retval;
-	char *full_name;
-	size_t name_len;
-	size_t prefix_len = XATTR_USER_PREFIX_LEN;
+	const char *full_name = name - XATTR_USER_PREFIX_LEN;
 
 	if (name == NULL)
 		return -EINVAL;
@@ -60,17 +44,7 @@ static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
 	if (strcmp(name, "") == 0)
 		return -EINVAL;
 
-	name_len = strlen(name);
-	full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
-	if (!full_name)
-		return -ENOMEM;
-	memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
-	memcpy(full_name + prefix_len, name, name_len);
-	full_name[prefix_len + name_len] = '\0';
-
-	retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
-	kfree(full_name);
-	return retval;
+	return v9fs_xattr_set(dentry, full_name, value, size, flags);
 }
 
 struct xattr_handler v9fs_xattr_user_handler = {
-- 
2.4.3



  parent reply	other threads:[~2015-08-20 18:20 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-20 18:19 [RFC 00/11] Inode security label invalidation Andreas Gruenbacher
2015-08-20 18:19 ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 01/11] ubifs: Remove unused "security.*" xattr handler Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 02/11] hfsplus: Remove unused xattr handler list operations Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` Andreas Gruenbacher [this message]
2015-08-20 18:19   ` [Cluster-devel] [RFC 03/11] 9p: Simplify the xattr handlers Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 04/11] xattr handlers: Pass handler to operations instead of flags Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 05/11] xattr handlers: Some simplifications Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 06/11] lib: Move strcmp_prefix into string.c Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 07/11] 9p: Stop using the generic xattr_handler infrastructure Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-21  6:46   ` Christoph Hellwig
2015-08-21  6:46     ` [Cluster-devel] " Christoph Hellwig
2015-08-21  8:35     ` Steven Whitehouse
2015-08-21  8:35       ` Steven Whitehouse
2015-08-20 18:19 ` [RFC 08/11] xattr: Pass inodes to xattr handlers instead of dentries Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 09/11] vfs: Add igetxattr inode operation Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-21  6:48   ` Christoph Hellwig
2015-08-21  6:48     ` [Cluster-devel] " Christoph Hellwig
2015-08-20 18:19 ` [RFC 10/11] selinux: Allow to invalidate an inode's security label Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-20 18:19 ` [RFC 11/11] gfs2: Invalide security labels of inodes that go invalid Andreas Gruenbacher
2015-08-20 18:19   ` [Cluster-devel] " Andreas Gruenbacher
2015-08-21  6:49   ` Christoph Hellwig
2015-08-21  6:49     ` [Cluster-devel] " Christoph Hellwig
2015-08-21  9:25     ` Andreas Gruenbacher
2015-08-21  9:25       ` Andreas Gruenbacher
2015-08-24 17:42 ` [RFC 00/11] Inode security label invalidation Stephen Smalley
2015-08-24 17:42   ` [Cluster-devel] " Stephen Smalley
2015-08-24 19:13   ` Andreas Grünbacher
2015-08-24 19:13     ` [Cluster-devel] " Andreas Grünbacher
2015-08-24 20:47   ` Eric Paris
2015-08-24 20:47     ` [Cluster-devel] " Eric Paris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440094798-1411-4-git-send-email-agruenba@redhat.com \
    --to=andreas.gruenbacher@gmail.com \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=bfields@fieldses.org \
    --cc=cluster-devel@redhat.com \
    --cc=dpquigl@davequigley.com \
    --cc=eparis@redhat.com \
    --cc=hch@infradead.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.