* [PATCH 0/5] Some more xattr cleanups
@ 2016-04-29 14:18 Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 1/5] jffs2: Remove jffs2_{get,set,remove}xattr macros Andreas Gruenbacher
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Andreas Gruenbacher @ 2016-04-29 14:18 UTC (permalink / raw)
To: Alexander Viro; +Cc: Andreas Gruenbacher, linux-fsdevel
Al,
here are some more cleanups for the work.xattr branch.
Thanks,
Andreas
Andreas Gruenbacher (5):
jffs2: Remove jffs2_{get,set,remove}xattr macros
hfs: Switch to generic xattr handlers
kernfs: Switch to generic xattr handlers
sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names
sockfs: Get rid of getxattr iop
arch/ia64/kernel/perfmon.c | 4 +-
drivers/gpu/drm/drm_drv.c | 1 +
fs/aio.c | 2 +-
fs/anon_inodes.c | 2 +-
fs/block_dev.c | 2 +-
fs/btrfs/tests/btrfs-tests.c | 2 +-
fs/hfs/attr.c | 82 +++++++++++++++--------
fs/hfs/hfs_fs.h | 6 +-
fs/hfs/inode.c | 7 +-
fs/hfs/super.c | 1 +
fs/jffs2/dir.c | 6 +-
fs/jffs2/file.c | 6 +-
fs/jffs2/symlink.c | 6 +-
fs/jffs2/xattr.h | 6 --
fs/kernfs/dir.c | 6 +-
fs/kernfs/inode.c | 150 ++++++++++++++++++++++++-------------------
fs/kernfs/kernfs-internal.h | 6 +-
fs/kernfs/mount.c | 1 +
fs/kernfs/symlink.c | 6 +-
fs/libfs.c | 3 +-
fs/nsfs.c | 2 +-
fs/pipe.c | 2 +-
include/linux/fs.h | 1 +
net/socket.c | 60 +++++++++--------
24 files changed, 203 insertions(+), 167 deletions(-)
--
2.5.5
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/5] jffs2: Remove jffs2_{get,set,remove}xattr macros
2016-04-29 14:18 [PATCH 0/5] Some more xattr cleanups Andreas Gruenbacher
@ 2016-04-29 14:18 ` Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 2/5] hfs: Switch to generic xattr handlers Andreas Gruenbacher
` (3 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Andreas Gruenbacher @ 2016-04-29 14:18 UTC (permalink / raw)
To: Alexander Viro; +Cc: Andreas Gruenbacher, linux-fsdevel
When sb->s_xattr is NULL, the generic_{get,set,remove}xattr functions
produce the same result that setting the {get,set,remove}xattr inode
operations to NULL produces; there is no need for these macros.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/jffs2/dir.c | 6 +++---
fs/jffs2/file.c | 6 +++---
fs/jffs2/symlink.c | 6 +++---
fs/jffs2/xattr.h | 6 ------
4 files changed, 9 insertions(+), 15 deletions(-)
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index 7a9579e..9130c7a 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -61,10 +61,10 @@ const struct inode_operations jffs2_dir_inode_operations =
.get_acl = jffs2_get_acl,
.set_acl = jffs2_set_acl,
.setattr = jffs2_setattr,
- .setxattr = jffs2_setxattr,
- .getxattr = jffs2_getxattr,
+ .setxattr = generic_setxattr,
+ .getxattr = generic_getxattr,
.listxattr = jffs2_listxattr,
- .removexattr = jffs2_removexattr
+ .removexattr = generic_removexattr
};
/***********************************************************************/
diff --git a/fs/jffs2/file.c b/fs/jffs2/file.c
index cad86ba..bf543cb 100644
--- a/fs/jffs2/file.c
+++ b/fs/jffs2/file.c
@@ -66,10 +66,10 @@ const struct inode_operations jffs2_file_inode_operations =
.get_acl = jffs2_get_acl,
.set_acl = jffs2_set_acl,
.setattr = jffs2_setattr,
- .setxattr = jffs2_setxattr,
- .getxattr = jffs2_getxattr,
+ .setxattr = generic_setxattr,
+ .getxattr = generic_getxattr,
.listxattr = jffs2_listxattr,
- .removexattr = jffs2_removexattr
+ .removexattr = generic_removexattr
};
const struct address_space_operations jffs2_file_address_operations =
diff --git a/fs/jffs2/symlink.c b/fs/jffs2/symlink.c
index 2cabd64..afe2d75 100644
--- a/fs/jffs2/symlink.c
+++ b/fs/jffs2/symlink.c
@@ -16,8 +16,8 @@ const struct inode_operations jffs2_symlink_inode_operations =
.readlink = generic_readlink,
.get_link = simple_get_link,
.setattr = jffs2_setattr,
- .setxattr = jffs2_setxattr,
- .getxattr = jffs2_getxattr,
+ .setxattr = generic_setxattr,
+ .getxattr = generic_getxattr,
.listxattr = jffs2_listxattr,
- .removexattr = jffs2_removexattr
+ .removexattr = generic_removexattr
};
diff --git a/fs/jffs2/xattr.h b/fs/jffs2/xattr.h
index 467ff37..720007b 100644
--- a/fs/jffs2/xattr.h
+++ b/fs/jffs2/xattr.h
@@ -99,9 +99,6 @@ extern const struct xattr_handler jffs2_user_xattr_handler;
extern const struct xattr_handler jffs2_trusted_xattr_handler;
extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t);
-#define jffs2_getxattr generic_getxattr
-#define jffs2_setxattr generic_setxattr
-#define jffs2_removexattr generic_removexattr
#else
@@ -116,9 +113,6 @@ extern ssize_t jffs2_listxattr(struct dentry *, char *, size_t);
#define jffs2_xattr_handlers NULL
#define jffs2_listxattr NULL
-#define jffs2_getxattr NULL
-#define jffs2_setxattr NULL
-#define jffs2_removexattr NULL
#endif /* CONFIG_JFFS2_FS_XATTR */
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/5] hfs: Switch to generic xattr handlers
2016-04-29 14:18 [PATCH 0/5] Some more xattr cleanups Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 1/5] jffs2: Remove jffs2_{get,set,remove}xattr macros Andreas Gruenbacher
@ 2016-04-29 14:18 ` Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 3/5] kernfs: " Andreas Gruenbacher
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Andreas Gruenbacher @ 2016-04-29 14:18 UTC (permalink / raw)
To: Alexander Viro; +Cc: Andreas Gruenbacher, linux-fsdevel
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
fs/hfs/attr.c | 82 +++++++++++++++++++++++++++++++++++++++------------------
fs/hfs/hfs_fs.h | 6 +----
fs/hfs/inode.c | 7 ++---
fs/hfs/super.c | 1 +
4 files changed, 62 insertions(+), 34 deletions(-)
diff --git a/fs/hfs/attr.c b/fs/hfs/attr.c
index 064f92f..8adcf33 100644
--- a/fs/hfs/attr.c
+++ b/fs/hfs/attr.c
@@ -13,10 +13,14 @@
#include "hfs_fs.h"
#include "btree.h"
-int hfs_setxattr(struct dentry *dentry, const char *name,
- const void *value, size_t size, int flags)
+enum hfs_xattr_type {
+ HFS_TYPE,
+ HFS_CREATOR,
+};
+
+static int __hfs_setxattr(struct inode *inode, enum hfs_xattr_type type,
+ const void *value, size_t size, int flags)
{
- struct inode *inode = d_inode(dentry);
struct hfs_find_data fd;
hfs_cat_rec rec;
struct hfs_cat_file *file;
@@ -36,18 +40,22 @@ int hfs_setxattr(struct dentry *dentry, const char *name,
sizeof(struct hfs_cat_file));
file = &rec.file;
- if (!strcmp(name, "hfs.type")) {
+ switch(type) {
+ case HFS_TYPE:
if (size == 4)
memcpy(&file->UsrWds.fdType, value, 4);
else
res = -ERANGE;
- } else if (!strcmp(name, "hfs.creator")) {
+ break;
+
+ case HFS_CREATOR:
if (size == 4)
memcpy(&file->UsrWds.fdCreator, value, 4);
else
res = -ERANGE;
- } else
- res = -EOPNOTSUPP;
+ break;
+ }
+
if (!res)
hfs_bnode_write(fd.bnode, &rec, fd.entryoffset,
sizeof(struct hfs_cat_file));
@@ -56,8 +64,8 @@ out:
return res;
}
-ssize_t hfs_getxattr(struct dentry *unused, struct inode *inode,
- const char *name, void *value, size_t size)
+static ssize_t __hfs_getxattr(struct inode *inode, enum hfs_xattr_type type,
+ void *value, size_t size)
{
struct hfs_find_data fd;
hfs_cat_rec rec;
@@ -80,41 +88,63 @@ ssize_t hfs_getxattr(struct dentry *unused, struct inode *inode,
}
file = &rec.file;
- if (!strcmp(name, "hfs.type")) {
+ switch(type) {
+ case HFS_TYPE:
if (size >= 4) {
memcpy(value, &file->UsrWds.fdType, 4);
res = 4;
} else
res = size ? -ERANGE : 4;
- } else if (!strcmp(name, "hfs.creator")) {
+ break;
+
+ case HFS_CREATOR:
if (size >= 4) {
memcpy(value, &file->UsrWds.fdCreator, 4);
res = 4;
} else
res = size ? -ERANGE : 4;
- } else
- res = -ENODATA;
+ break;
+ }
+
out:
if (size)
hfs_find_exit(&fd);
return res;
}
-#define HFS_ATTRLIST_SIZE (sizeof("hfs.creator")+sizeof("hfs.type"))
-
-ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
+static int hfs_xattr_get(const struct xattr_handler *handler,
+ struct dentry *unused, struct inode *inode,
+ const char *name, void *value, size_t size)
{
- struct inode *inode = d_inode(dentry);
+ return __hfs_getxattr(inode, handler->flags, value, size);
+}
- if (!S_ISREG(inode->i_mode) || HFS_IS_RSRC(inode))
+static int hfs_xattr_set(const struct xattr_handler *handler,
+ struct dentry *dentry, const char *name,
+ const void *value, size_t size, int flags)
+{
+ if (!value)
return -EOPNOTSUPP;
- if (!buffer || !size)
- return HFS_ATTRLIST_SIZE;
- if (size < HFS_ATTRLIST_SIZE)
- return -ERANGE;
- strcpy(buffer, "hfs.type");
- strcpy(buffer + sizeof("hfs.type"), "hfs.creator");
-
- return HFS_ATTRLIST_SIZE;
+ return __hfs_setxattr(d_inode(dentry), handler->flags, value, size, flags);
}
+
+static const struct xattr_handler hfs_creator_handler = {
+ .name = "hfs.creator",
+ .flags = HFS_CREATOR,
+ .get = hfs_xattr_get,
+ .set = hfs_xattr_set,
+};
+
+static const struct xattr_handler hfs_type_handler = {
+ .name = "hfs.type",
+ .flags = HFS_TYPE,
+ .get = hfs_xattr_get,
+ .set = hfs_xattr_set,
+};
+
+const struct xattr_handler *hfs_xattr_handlers[] = {
+ &hfs_creator_handler,
+ &hfs_type_handler,
+ NULL
+};
diff --git a/fs/hfs/hfs_fs.h b/fs/hfs/hfs_fs.h
index 79daa09..771dcfe 100644
--- a/fs/hfs/hfs_fs.h
+++ b/fs/hfs/hfs_fs.h
@@ -211,11 +211,7 @@ extern void hfs_evict_inode(struct inode *);
extern void hfs_delete_inode(struct inode *);
/* attr.c */
-extern int hfs_setxattr(struct dentry *dentry, const char *name,
- const void *value, size_t size, int flags);
-extern ssize_t hfs_getxattr(struct dentry *dentry, struct inode *inode,
- const char *name, void *value, size_t size);
-extern ssize_t hfs_listxattr(struct dentry *dentry, char *buffer, size_t size);
+extern const struct xattr_handler *hfs_xattr_handlers[];
/* mdb.c */
extern int hfs_mdb_get(struct super_block *);
diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c
index 6686bf3..bb9549b 100644
--- a/fs/hfs/inode.c
+++ b/fs/hfs/inode.c
@@ -15,6 +15,7 @@
#include <linux/mpage.h>
#include <linux/sched.h>
#include <linux/uio.h>
+#include <linux/xattr.h>
#include "hfs_fs.h"
#include "btree.h"
@@ -686,7 +687,7 @@ static const struct file_operations hfs_file_operations = {
static const struct inode_operations hfs_file_inode_operations = {
.lookup = hfs_file_lookup,
.setattr = hfs_inode_setattr,
- .setxattr = hfs_setxattr,
- .getxattr = hfs_getxattr,
- .listxattr = hfs_listxattr,
+ .setxattr = generic_setxattr,
+ .getxattr = generic_getxattr,
+ .listxattr = generic_listxattr,
};
diff --git a/fs/hfs/super.c b/fs/hfs/super.c
index 1ca95c2..bf6304a 100644
--- a/fs/hfs/super.c
+++ b/fs/hfs/super.c
@@ -406,6 +406,7 @@ static int hfs_fill_super(struct super_block *sb, void *data, int silent)
}
sb->s_op = &hfs_super_operations;
+ sb->s_xattr = hfs_xattr_handlers;
sb->s_flags |= MS_NODIRATIME;
mutex_init(&sbi->bitmap_lock);
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/5] kernfs: Switch to generic xattr handlers
2016-04-29 14:18 [PATCH 0/5] Some more xattr cleanups Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 1/5] jffs2: Remove jffs2_{get,set,remove}xattr macros Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 2/5] hfs: Switch to generic xattr handlers Andreas Gruenbacher
@ 2016-04-29 14:18 ` Andreas Gruenbacher
2016-04-30 17:02 ` Greg Kroah-Hartman
2016-04-29 14:18 ` [PATCH 4/5] sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 5/5] sockfs: Get rid of getxattr iop Andreas Gruenbacher
4 siblings, 1 reply; 10+ messages in thread
From: Andreas Gruenbacher @ 2016-04-29 14:18 UTC (permalink / raw)
To: Alexander Viro; +Cc: Andreas Gruenbacher, linux-fsdevel, Greg Kroah-Hartman
Unlike with most other filesystems, xattrs in kernfs are attached to the
dentries (dentry->d_fsdata). Once security modules start calling get
xattr handlers with a NULL dentry (because of an unknown dentry), we'll
have to start check for that in kernfs_xattr_get.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/kernfs/dir.c | 6 +-
fs/kernfs/inode.c | 150 ++++++++++++++++++++++++--------------------
fs/kernfs/kernfs-internal.h | 6 +-
fs/kernfs/mount.c | 1 +
fs/kernfs/symlink.c | 6 +-
5 files changed, 91 insertions(+), 78 deletions(-)
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index 03b688d..f67d896 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -1125,9 +1125,9 @@ const struct inode_operations kernfs_dir_iops = {
.permission = kernfs_iop_permission,
.setattr = kernfs_iop_setattr,
.getattr = kernfs_iop_getattr,
- .setxattr = kernfs_iop_setxattr,
- .removexattr = kernfs_iop_removexattr,
- .getxattr = kernfs_iop_getxattr,
+ .setxattr = generic_setxattr,
+ .removexattr = generic_removexattr,
+ .getxattr = generic_getxattr,
.listxattr = kernfs_iop_listxattr,
.mkdir = kernfs_iop_mkdir,
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index b524722..1dfb44a 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -28,9 +28,9 @@ static const struct inode_operations kernfs_iops = {
.permission = kernfs_iop_permission,
.setattr = kernfs_iop_setattr,
.getattr = kernfs_iop_getattr,
- .setxattr = kernfs_iop_setxattr,
- .removexattr = kernfs_iop_removexattr,
- .getxattr = kernfs_iop_getxattr,
+ .setxattr = generic_setxattr,
+ .removexattr = generic_removexattr,
+ .getxattr = generic_getxattr,
.listxattr = kernfs_iop_listxattr,
};
@@ -157,70 +157,6 @@ static int kernfs_node_setsecdata(struct kernfs_node *kn, void **secdata,
return 0;
}
-int kernfs_iop_setxattr(struct dentry *dentry, const char *name,
- const void *value, size_t size, int flags)
-{
- struct kernfs_node *kn = dentry->d_fsdata;
- struct kernfs_iattrs *attrs;
- void *secdata;
- int error;
- u32 secdata_len = 0;
-
- attrs = kernfs_iattrs(kn);
- if (!attrs)
- return -ENOMEM;
-
- if (!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN)) {
- const char *suffix = name + XATTR_SECURITY_PREFIX_LEN;
- error = security_inode_setsecurity(d_inode(dentry), suffix,
- value, size, flags);
- if (error)
- return error;
- error = security_inode_getsecctx(d_inode(dentry),
- &secdata, &secdata_len);
- if (error)
- return error;
-
- mutex_lock(&kernfs_mutex);
- error = kernfs_node_setsecdata(kn, &secdata, &secdata_len);
- mutex_unlock(&kernfs_mutex);
-
- if (secdata)
- security_release_secctx(secdata, secdata_len);
- return error;
- } else if (!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) {
- return simple_xattr_set(&attrs->xattrs, name, value, size,
- flags);
- }
-
- return -EINVAL;
-}
-
-int kernfs_iop_removexattr(struct dentry *dentry, const char *name)
-{
- struct kernfs_node *kn = dentry->d_fsdata;
- struct kernfs_iattrs *attrs;
-
- attrs = kernfs_iattrs(kn);
- if (!attrs)
- return -ENOMEM;
-
- return simple_xattr_set(&attrs->xattrs, name, NULL, 0, XATTR_REPLACE);
-}
-
-ssize_t kernfs_iop_getxattr(struct dentry *unused, struct inode *inode,
- const char *name, void *buf, size_t size)
-{
- struct kernfs_node *kn = inode->i_private;
- struct kernfs_iattrs *attrs;
-
- attrs = kernfs_iattrs(kn);
- if (!attrs)
- return -ENOMEM;
-
- return simple_xattr_get(&attrs->xattrs, name, buf, size);
-}
-
ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size)
{
struct kernfs_node *kn = dentry->d_fsdata;
@@ -370,3 +306,83 @@ int kernfs_iop_permission(struct inode *inode, int mask)
return generic_permission(inode, mask);
}
+
+static int kernfs_xattr_get(const struct xattr_handler *handler,
+ struct dentry *dentry, struct inode *inode,
+ const char *suffix, void *value, size_t size)
+{
+ const char *name = xattr_full_name(handler, suffix);
+ struct kernfs_node *kn;
+ struct kernfs_iattrs *attrs;
+
+ kn = dentry->d_fsdata;
+ attrs = kernfs_iattrs(kn);
+ if (!attrs)
+ return -ENOMEM;
+
+ return simple_xattr_get(&attrs->xattrs, name, value, size);
+}
+
+static int kernfs_xattr_set(const struct xattr_handler *handler,
+ struct dentry *dentry, const char *suffix,
+ const void *value, size_t size, int flags)
+{
+ const char *name = xattr_full_name(handler, suffix);
+ struct kernfs_node *kn = dentry->d_fsdata;
+ struct kernfs_iattrs *attrs;
+
+ attrs = kernfs_iattrs(kn);
+ if (!attrs)
+ return -ENOMEM;
+
+ return simple_xattr_set(&attrs->xattrs, name, value, size, flags);
+}
+
+const struct xattr_handler kernfs_trusted_xattr_handler = {
+ .prefix = XATTR_TRUSTED_PREFIX,
+ .get = kernfs_xattr_get,
+ .set = kernfs_xattr_set,
+};
+
+static int kernfs_security_xattr_set(const struct xattr_handler *handler,
+ struct dentry *dentry, const char *suffix,
+ const void *value, size_t size, int flags)
+{
+ struct kernfs_node *kn = dentry->d_fsdata;
+ struct inode *inode = d_inode(dentry);
+ struct kernfs_iattrs *attrs;
+ void *secdata;
+ u32 secdata_len = 0;
+ int error;
+
+ attrs = kernfs_iattrs(kn);
+ if (!attrs)
+ return -ENOMEM;
+
+ error = security_inode_setsecurity(inode, suffix, value, size, flags);
+ if (error)
+ return error;
+ error = security_inode_getsecctx(inode, &secdata, &secdata_len);
+ if (error)
+ return error;
+
+ mutex_lock(&kernfs_mutex);
+ error = kernfs_node_setsecdata(kn, &secdata, &secdata_len);
+ mutex_unlock(&kernfs_mutex);
+
+ if (secdata)
+ security_release_secctx(secdata, secdata_len);
+ return error;
+}
+
+const struct xattr_handler kernfs_security_xattr_handler = {
+ .prefix = XATTR_SECURITY_PREFIX,
+ .get = kernfs_xattr_get,
+ .set = kernfs_security_xattr_set,
+};
+
+const struct xattr_handler *kernfs_xattr_handlers[] = {
+ &kernfs_trusted_xattr_handler,
+ &kernfs_security_xattr_handler,
+ NULL
+};
diff --git a/fs/kernfs/kernfs-internal.h b/fs/kernfs/kernfs-internal.h
index 45c9192..bfd551b 100644
--- a/fs/kernfs/kernfs-internal.h
+++ b/fs/kernfs/kernfs-internal.h
@@ -76,16 +76,12 @@ extern struct kmem_cache *kernfs_node_cache;
/*
* inode.c
*/
+extern const struct xattr_handler *kernfs_xattr_handlers[];
void kernfs_evict_inode(struct inode *inode);
int kernfs_iop_permission(struct inode *inode, int mask);
int kernfs_iop_setattr(struct dentry *dentry, struct iattr *iattr);
int kernfs_iop_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat);
-int kernfs_iop_setxattr(struct dentry *dentry, const char *name, const void *value,
- size_t size, int flags);
-int kernfs_iop_removexattr(struct dentry *dentry, const char *name);
-ssize_t kernfs_iop_getxattr(struct dentry *dentry, struct inode *inode,
- const char *name, void *buf, size_t size);
ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size);
/*
diff --git a/fs/kernfs/mount.c b/fs/kernfs/mount.c
index b67dbcc..5446c3b 100644
--- a/fs/kernfs/mount.c
+++ b/fs/kernfs/mount.c
@@ -142,6 +142,7 @@ static int kernfs_fill_super(struct super_block *sb, unsigned long magic)
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
sb->s_magic = magic;
sb->s_op = &kernfs_sops;
+ sb->s_xattr = kernfs_xattr_handlers;
sb->s_time_gran = 1;
/* get root inode, initialize and unlock it */
diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
index 117b8b3..549a14c7 100644
--- a/fs/kernfs/symlink.c
+++ b/fs/kernfs/symlink.c
@@ -134,9 +134,9 @@ static const char *kernfs_iop_get_link(struct dentry *dentry,
}
const struct inode_operations kernfs_symlink_iops = {
- .setxattr = kernfs_iop_setxattr,
- .removexattr = kernfs_iop_removexattr,
- .getxattr = kernfs_iop_getxattr,
+ .setxattr = generic_setxattr,
+ .removexattr = generic_removexattr,
+ .getxattr = generic_getxattr,
.listxattr = kernfs_iop_listxattr,
.readlink = generic_readlink,
.get_link = kernfs_iop_get_link,
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/5] sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names
2016-04-29 14:18 [PATCH 0/5] Some more xattr cleanups Andreas Gruenbacher
` (2 preceding siblings ...)
2016-04-29 14:18 ` [PATCH 3/5] kernfs: " Andreas Gruenbacher
@ 2016-04-29 14:18 ` Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 5/5] sockfs: Get rid of getxattr iop Andreas Gruenbacher
4 siblings, 0 replies; 10+ messages in thread
From: Andreas Gruenbacher @ 2016-04-29 14:18 UTC (permalink / raw)
To: Alexander Viro; +Cc: Andreas Gruenbacher, linux-fsdevel
The standard return value for unsupported attribute names is
-EOPNOTSUPP, as opposed to undefined but supported attributes
(-ENODATA). Also, fail for attribute names like
"system.sockprotonameXXX" and simplify the code a bit.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
net/socket.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)
diff --git a/net/socket.c b/net/socket.c
index 35e4523..23fdd83 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -469,27 +469,15 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode,
const char *name, void *value, size_t size)
{
- const char *proto_name;
- size_t proto_size;
- int error;
-
- error = -ENODATA;
- if (!strncmp(name, XATTR_NAME_SOCKPROTONAME, XATTR_NAME_SOCKPROTONAME_LEN)) {
- proto_name = dentry->d_name.name;
- proto_size = strlen(proto_name);
-
+ if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
if (value) {
- error = -ERANGE;
- if (proto_size + 1 > size)
- goto out;
-
- strncpy(value, proto_name, proto_size + 1);
+ if (dentry->d_name.len + 1 > size)
+ return -ERANGE;
+ memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
}
- error = proto_size + 1;
+ return dentry->d_name.len + 1;
}
-
-out:
- return error;
+ return -EOPNOTSUPP;
}
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/5] sockfs: Get rid of getxattr iop
2016-04-29 14:18 [PATCH 0/5] Some more xattr cleanups Andreas Gruenbacher
` (3 preceding siblings ...)
2016-04-29 14:18 ` [PATCH 4/5] sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names Andreas Gruenbacher
@ 2016-04-29 14:18 ` Andreas Gruenbacher
4 siblings, 0 replies; 10+ messages in thread
From: Andreas Gruenbacher @ 2016-04-29 14:18 UTC (permalink / raw)
To: Alexander Viro; +Cc: Andreas Gruenbacher, linux-fsdevel
If we allow pseudo-filesystems created with mount_pseudo to have xattr
handlers, we can replace sockfs_getxattr with a sockfs_xattr_get handler
to use the xattr handler name parsing. In this case, the improvement is
only a small one, though.
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
---
arch/ia64/kernel/perfmon.c | 4 ++--
drivers/gpu/drm/drm_drv.c | 1 +
fs/aio.c | 2 +-
fs/anon_inodes.c | 2 +-
fs/block_dev.c | 2 +-
fs/btrfs/tests/btrfs-tests.c | 2 +-
fs/libfs.c | 3 ++-
fs/nsfs.c | 2 +-
fs/pipe.c | 2 +-
include/linux/fs.h | 1 +
net/socket.c | 48 ++++++++++++++++++++++++++------------------
11 files changed, 41 insertions(+), 28 deletions(-)
diff --git a/arch/ia64/kernel/perfmon.c b/arch/ia64/kernel/perfmon.c
index 9cd607b..782cddb 100644
--- a/arch/ia64/kernel/perfmon.c
+++ b/arch/ia64/kernel/perfmon.c
@@ -611,8 +611,8 @@ static const struct dentry_operations pfmfs_dentry_operations;
static struct dentry *
pfmfs_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data)
{
- return mount_pseudo(fs_type, "pfm:", NULL, &pfmfs_dentry_operations,
- PFMFS_MAGIC);
+ return mount_pseudo(fs_type, "pfm:", NULL, NULL,
+ &pfmfs_dentry_operations, PFMFS_MAGIC);
}
static struct file_system_type pfm_fs_type = {
diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index 167c8d3..3512bb8 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -509,6 +509,7 @@ static struct dentry *drm_fs_mount(struct file_system_type *fs_type, int flags,
return mount_pseudo(fs_type,
"drm:",
&drm_fs_sops,
+ NULL,
&drm_fs_dops,
0x010203ff);
}
diff --git a/fs/aio.c b/fs/aio.c
index 155f842..6f1387f 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -239,7 +239,7 @@ static struct dentry *aio_mount(struct file_system_type *fs_type,
static const struct dentry_operations ops = {
.d_dname = simple_dname,
};
- return mount_pseudo(fs_type, "aio:", NULL, &ops, AIO_RING_MAGIC);
+ return mount_pseudo(fs_type, "aio:", NULL, NULL, &ops, AIO_RING_MAGIC);
}
/* aio_setup
diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
index 80ef38c..5e1aeea1 100644
--- a/fs/anon_inodes.c
+++ b/fs/anon_inodes.c
@@ -41,7 +41,7 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
- return mount_pseudo(fs_type, "anon_inode:", NULL,
+ return mount_pseudo(fs_type, "anon_inode:", NULL, NULL,
&anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
}
diff --git a/fs/block_dev.c b/fs/block_dev.c
index 3172c4e..8c605ff 100644
--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -576,7 +576,7 @@ static struct dentry *bd_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
struct dentry *dent;
- dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, BDEVFS_MAGIC);
+ dent = mount_pseudo(fs_type, "bdev:", &bdev_sops, NULL, NULL, BDEVFS_MAGIC);
if (dent)
dent->d_sb->s_iflags |= SB_I_CGROUPWB;
return dent;
diff --git a/fs/btrfs/tests/btrfs-tests.c b/fs/btrfs/tests/btrfs-tests.c
index f54bf45..ebecf33 100644
--- a/fs/btrfs/tests/btrfs-tests.c
+++ b/fs/btrfs/tests/btrfs-tests.c
@@ -40,7 +40,7 @@ static struct dentry *btrfs_test_mount(struct file_system_type *fs_type,
void *data)
{
return mount_pseudo(fs_type, "btrfs_test:", &btrfs_test_super_ops,
- NULL, BTRFS_TEST_MAGIC);
+ NULL, NULL, BTRFS_TEST_MAGIC);
}
static struct file_system_type test_type = {
diff --git a/fs/libfs.c b/fs/libfs.c
index 03332f4..2a820bb 100644
--- a/fs/libfs.c
+++ b/fs/libfs.c
@@ -209,7 +209,7 @@ static const struct super_operations simple_super_operations = {
* will never be mountable)
*/
struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
- const struct super_operations *ops,
+ const struct super_operations *ops, const struct xattr_handler **xattr,
const struct dentry_operations *dops, unsigned long magic)
{
struct super_block *s;
@@ -226,6 +226,7 @@ struct dentry *mount_pseudo(struct file_system_type *fs_type, char *name,
s->s_blocksize_bits = PAGE_SHIFT;
s->s_magic = magic;
s->s_op = ops ? ops : &simple_super_operations;
+ s->s_xattr = xattr;
s->s_time_gran = 1;
root = new_inode(s);
if (!root)
diff --git a/fs/nsfs.c b/fs/nsfs.c
index 8f20d60..e151cc3 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -154,7 +154,7 @@ static const struct super_operations nsfs_ops = {
static struct dentry *nsfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
- return mount_pseudo(fs_type, "nsfs:", &nsfs_ops,
+ return mount_pseudo(fs_type, "nsfs:", &nsfs_ops, NULL,
&ns_dentry_operations, NSFS_MAGIC);
}
static struct file_system_type nsfs = {
diff --git a/fs/pipe.c b/fs/pipe.c
index ab8dad3..60a9180 100644
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1143,7 +1143,7 @@ static const struct super_operations pipefs_ops = {
static struct dentry *pipefs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
- return mount_pseudo(fs_type, "pipe:", &pipefs_ops,
+ return mount_pseudo(fs_type, "pipe:", &pipefs_ops, NULL,
&pipefs_dentry_operations, PIPEFS_MAGIC);
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 1b5fcae..3489609 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2030,6 +2030,7 @@ struct super_block *sget(struct file_system_type *type,
int flags, void *data);
extern struct dentry *mount_pseudo(struct file_system_type *, char *,
const struct super_operations *ops,
+ const struct xattr_handler **xattr,
const struct dentry_operations *dops,
unsigned long);
diff --git a/net/socket.c b/net/socket.c
index 23fdd83..3ef77ab 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -320,11 +320,38 @@ static const struct dentry_operations sockfs_dentry_operations = {
.d_dname = sockfs_dname,
};
+static int sockfs_xattr_get(const struct xattr_handler *handler,
+ struct dentry *dentry, struct inode *inode,
+ const char *suffix, void *value, size_t size)
+{
+ if (value) {
+ if (dentry->d_name.len + 1 > size)
+ return -ERANGE;
+ memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
+ }
+ return dentry->d_name.len + 1;
+}
+
+#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
+#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
+#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
+
+static const struct xattr_handler sockfs_xattr_handler = {
+ .name = XATTR_NAME_SOCKPROTONAME,
+ .get = sockfs_xattr_get,
+};
+
+static const struct xattr_handler *sockfs_xattr_handlers[] = {
+ &sockfs_xattr_handler,
+ NULL
+};
+
static struct dentry *sockfs_mount(struct file_system_type *fs_type,
int flags, const char *dev_name, void *data)
{
return mount_pseudo(fs_type, "socket:", &sockfs_ops,
- &sockfs_dentry_operations, SOCKFS_MAGIC);
+ sockfs_xattr_handlers,
+ &sockfs_dentry_operations, SOCKFS_MAGIC);
}
static struct vfsmount *sock_mnt __read_mostly;
@@ -463,23 +490,6 @@ static struct socket *sockfd_lookup_light(int fd, int *err, int *fput_needed)
return NULL;
}
-#define XATTR_SOCKPROTONAME_SUFFIX "sockprotoname"
-#define XATTR_NAME_SOCKPROTONAME (XATTR_SYSTEM_PREFIX XATTR_SOCKPROTONAME_SUFFIX)
-#define XATTR_NAME_SOCKPROTONAME_LEN (sizeof(XATTR_NAME_SOCKPROTONAME)-1)
-static ssize_t sockfs_getxattr(struct dentry *dentry, struct inode *inode,
- const char *name, void *value, size_t size)
-{
- if (!strcmp(name, XATTR_NAME_SOCKPROTONAME)) {
- if (value) {
- if (dentry->d_name.len + 1 > size)
- return -ERANGE;
- memcpy(value, dentry->d_name.name, dentry->d_name.len + 1);
- }
- return dentry->d_name.len + 1;
- }
- return -EOPNOTSUPP;
-}
-
static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
size_t size)
{
@@ -509,7 +519,7 @@ static ssize_t sockfs_listxattr(struct dentry *dentry, char *buffer,
}
static const struct inode_operations sockfs_inode_ops = {
- .getxattr = sockfs_getxattr,
+ .getxattr = generic_getxattr,
.listxattr = sockfs_listxattr,
};
--
2.5.5
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 3/5] kernfs: Switch to generic xattr handlers
2016-04-29 14:18 ` [PATCH 3/5] kernfs: " Andreas Gruenbacher
@ 2016-04-30 17:02 ` Greg Kroah-Hartman
2016-04-30 17:25 ` Al Viro
2016-05-01 10:45 ` Andreas Grünbacher
0 siblings, 2 replies; 10+ messages in thread
From: Greg Kroah-Hartman @ 2016-04-30 17:02 UTC (permalink / raw)
To: Andreas Gruenbacher; +Cc: Alexander Viro, linux-fsdevel
On Fri, Apr 29, 2016 at 04:18:35PM +0200, Andreas Gruenbacher wrote:
> Unlike with most other filesystems, xattrs in kernfs are attached to the
> dentries (dentry->d_fsdata). Once security modules start calling get
> xattr handlers with a NULL dentry (because of an unknown dentry), we'll
> have to start check for that in kernfs_xattr_get.
>
> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Note, I'm not the only maintainer of kernfs...
Anyway:
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/5] kernfs: Switch to generic xattr handlers
2016-04-30 17:02 ` Greg Kroah-Hartman
@ 2016-04-30 17:25 ` Al Viro
2016-05-01 10:45 ` Andreas Grünbacher
1 sibling, 0 replies; 10+ messages in thread
From: Al Viro @ 2016-04-30 17:25 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: Andreas Gruenbacher, linux-fsdevel
On Sat, Apr 30, 2016 at 10:02:31AM -0700, Greg Kroah-Hartman wrote:
> On Fri, Apr 29, 2016 at 04:18:35PM +0200, Andreas Gruenbacher wrote:
> > Unlike with most other filesystems, xattrs in kernfs are attached to the
> > dentries (dentry->d_fsdata). Once security modules start calling get
> > xattr handlers with a NULL dentry (because of an unknown dentry), we'll
> > have to start check for that in kernfs_xattr_get.
> >
> > Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
> Note, I'm not the only maintainer of kernfs...
>
> Anyway:
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Guys, kernfs uses ->d_fsdata to get to them, but note
static void kernfs_init_inode(struct kernfs_node *kn, struct inode *inode)
{
kernfs_get(kn);
inode->i_private = kn;
IOW, inode->i_private would work just as well - it points to the same thing.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/5] kernfs: Switch to generic xattr handlers
2016-04-30 17:02 ` Greg Kroah-Hartman
2016-04-30 17:25 ` Al Viro
@ 2016-05-01 10:45 ` Andreas Grünbacher
2016-05-01 16:27 ` Greg Kroah-Hartman
1 sibling, 1 reply; 10+ messages in thread
From: Andreas Grünbacher @ 2016-05-01 10:45 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Andreas Gruenbacher, Alexander Viro, Linux FS-devel Mailing List
2016-04-30 19:02 GMT+02:00 Greg Kroah-Hartman <gregkh@linuxfoundation.org>:
> On Fri, Apr 29, 2016 at 04:18:35PM +0200, Andreas Gruenbacher wrote:
>> Unlike with most other filesystems, xattrs in kernfs are attached to the
>> dentries (dentry->d_fsdata). Once security modules start calling get
>> xattr handlers with a NULL dentry (because of an unknown dentry), we'll
>> have to start check for that in kernfs_xattr_get.
>>
>> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
>> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
>
> Note, I'm not the only maintainer of kernfs...
Hmm, that isn't clear from the MAINTAINERS file:
DRIVER CORE, KOBJECTS, DEBUGFS, KERNFS AND SYSFS
M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
S: Supported
F: Documentation/kobject.txt
F: drivers/base/
F: fs/debugfs/
F: fs/kernfs/
F: fs/sysfs/
F: include/linux/debugfs.h
F: include/linux/kobj*
F: lib/kobj*
> Anyway:
> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Thanks,
Andreas
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 3/5] kernfs: Switch to generic xattr handlers
2016-05-01 10:45 ` Andreas Grünbacher
@ 2016-05-01 16:27 ` Greg Kroah-Hartman
0 siblings, 0 replies; 10+ messages in thread
From: Greg Kroah-Hartman @ 2016-05-01 16:27 UTC (permalink / raw)
To: Andreas Grünbacher
Cc: Andreas Gruenbacher, Alexander Viro, Linux FS-devel Mailing List
On Sun, May 01, 2016 at 12:45:53PM +0200, Andreas Gr�nbacher wrote:
> 2016-04-30 19:02 GMT+02:00 Greg Kroah-Hartman <gregkh@linuxfoundation.org>:
> > On Fri, Apr 29, 2016 at 04:18:35PM +0200, Andreas Gruenbacher wrote:
> >> Unlike with most other filesystems, xattrs in kernfs are attached to the
> >> dentries (dentry->d_fsdata). Once security modules start calling get
> >> xattr handlers with a NULL dentry (because of an unknown dentry), we'll
> >> have to start check for that in kernfs_xattr_get.
> >>
> >> Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
> >> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> >
> > Note, I'm not the only maintainer of kernfs...
>
> Hmm, that isn't clear from the MAINTAINERS file:
>
> DRIVER CORE, KOBJECTS, DEBUGFS, KERNFS AND SYSFS
> M: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> T: git git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core.git
> S: Supported
> F: Documentation/kobject.txt
> F: drivers/base/
> F: fs/debugfs/
> F: fs/kernfs/
> F: fs/sysfs/
> F: include/linux/debugfs.h
> F: include/linux/kobj*
> F: lib/kobj*
Ah, sneaky Tejun, he didn't put his name on it, but if you use
get_maintainer.pl he should show up :)
thanks,
greg k-h
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2016-05-01 16:27 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-29 14:18 [PATCH 0/5] Some more xattr cleanups Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 1/5] jffs2: Remove jffs2_{get,set,remove}xattr macros Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 2/5] hfs: Switch to generic xattr handlers Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 3/5] kernfs: " Andreas Gruenbacher
2016-04-30 17:02 ` Greg Kroah-Hartman
2016-04-30 17:25 ` Al Viro
2016-05-01 10:45 ` Andreas Grünbacher
2016-05-01 16:27 ` Greg Kroah-Hartman
2016-04-29 14:18 ` [PATCH 4/5] sockfs: getxattr: Fail with -EOPNOTSUPP for invalid attribute names Andreas Gruenbacher
2016-04-29 14:18 ` [PATCH 5/5] sockfs: Get rid of getxattr iop Andreas Gruenbacher
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.