aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs/mount.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-09-11 22:29:07 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-09-26 18:30:22 -0400
commitcb26a311578e67769e92a39a0a63476533cb7e12 (patch)
tree13a1c59bdf23abdb063d1bc4a8cc1679e36dcd38 /fs/sysfs/mount.c
parent4b30ee58ee64c64f59fd876e4afa6ed82caef3a4 (diff)
sysfs: drop kobj_ns_type handling
The way namespace tags are implemented in sysfs is more complicated than necessary. As each tag is a pointer value and required to be non-NULL under a namespace enabled parent, there's no need to record separately what type each tag is or where namespace is enabled. If multiple namespace types are needed, which currently aren't, we can simply compare the tag to a set of allowed tags in the superblock assuming that the tags, being pointers, won't have the same value across multiple types. Also, whether to filter by namespace tag or not can be trivially determined by whether the node has any tagged children or not. This patch rips out kobj_ns_type handling from sysfs. sysfs no longer cares whether specific type of namespace is enabled or not. If a sysfs_dirent has a non-NULL tag, the parent is marked as needing namespace filtering and the value is tested against the allowed set of tags for the superblock (currently only one but increasing this number isn't difficult) and the sysfs_dirent is ignored if it doesn't match. This removes most kobject namespace knowledge from sysfs proper which will enable proper separation and layering of sysfs. The namespace sanity checks in fs/sysfs/dir.c are replaced by the new sanity check in kobject_namespace(). As this is the only place ktype->namespace() is called for sysfs, this doesn't weaken the sanity check significantly. I omitted converting the sanity check in sysfs_do_create_link_sd(). While the check can be shifted to upper layer, mistakes there are well contained and should be easily visible anyway. Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Eric W. Biederman <ebiederm@xmission.com> Cc: Kay Sievers <kay@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/mount.c')
-rw-r--r--fs/sysfs/mount.c24
1 files changed, 6 insertions, 18 deletions
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 834ec2cdb7a3..8c24bce2f4ae 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -36,7 +36,7 @@ static const struct super_operations sysfs_ops = {
36struct sysfs_dirent sysfs_root = { 36struct sysfs_dirent sysfs_root = {
37 .s_name = "", 37 .s_name = "",
38 .s_count = ATOMIC_INIT(1), 38 .s_count = ATOMIC_INIT(1),
39 .s_flags = SYSFS_DIR | (KOBJ_NS_TYPE_NONE << SYSFS_NS_TYPE_SHIFT), 39 .s_flags = SYSFS_DIR,
40 .s_mode = S_IFDIR | S_IRUGO | S_IXUGO, 40 .s_mode = S_IFDIR | S_IRUGO | S_IXUGO,
41 .s_ino = 1, 41 .s_ino = 1,
42}; 42};
@@ -77,14 +77,8 @@ static int sysfs_test_super(struct super_block *sb, void *data)
77{ 77{
78 struct sysfs_super_info *sb_info = sysfs_info(sb); 78 struct sysfs_super_info *sb_info = sysfs_info(sb);
79 struct sysfs_super_info *info = data; 79 struct sysfs_super_info *info = data;
80 enum kobj_ns_type type;
81 int found = 1;
82 80
83 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++) { 81 return sb_info->ns == info->ns;
84 if (sb_info->ns[type] != info->ns[type])
85 found = 0;
86 }
87 return found;
88} 82}
89 83
90static int sysfs_set_super(struct super_block *sb, void *data) 84static int sysfs_set_super(struct super_block *sb, void *data)
@@ -98,9 +92,7 @@ static int sysfs_set_super(struct super_block *sb, void *data)
98 92
99static void free_sysfs_super_info(struct sysfs_super_info *info) 93static void free_sysfs_super_info(struct sysfs_super_info *info)
100{ 94{
101 int type; 95 kobj_ns_drop(KOBJ_NS_TYPE_NET, info->ns);
102 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++)
103 kobj_ns_drop(type, info->ns[type]);
104 kfree(info); 96 kfree(info);
105} 97}
106 98
@@ -108,7 +100,6 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
108 int flags, const char *dev_name, void *data) 100 int flags, const char *dev_name, void *data)
109{ 101{
110 struct sysfs_super_info *info; 102 struct sysfs_super_info *info;
111 enum kobj_ns_type type;
112 struct super_block *sb; 103 struct super_block *sb;
113 int error; 104 int error;
114 105
@@ -116,18 +107,15 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type,
116 if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type)) 107 if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
117 return ERR_PTR(-EPERM); 108 return ERR_PTR(-EPERM);
118 109
119 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++) { 110 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
120 if (!kobj_ns_current_may_mount(type)) 111 return ERR_PTR(-EPERM);
121 return ERR_PTR(-EPERM);
122 }
123 } 112 }
124 113
125 info = kzalloc(sizeof(*info), GFP_KERNEL); 114 info = kzalloc(sizeof(*info), GFP_KERNEL);
126 if (!info) 115 if (!info)
127 return ERR_PTR(-ENOMEM); 116 return ERR_PTR(-ENOMEM);
128 117
129 for (type = KOBJ_NS_TYPE_NONE; type < KOBJ_NS_TYPES; type++) 118 info->ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
130 info->ns[type] = kobj_ns_grab_current(type);
131 119
132 sb = sget(fs_type, sysfs_test_super, sysfs_set_super, flags, info); 120 sb = sget(fs_type, sysfs_test_super, sysfs_set_super, flags, info);
133 if (IS_ERR(sb) || sb->s_fs_info != info) 121 if (IS_ERR(sb) || sb->s_fs_info != info)