fs: take i_mutex during prepare_binprm for set[ug]id executables
[linux/fpc-iii.git] / fs / sysfs / mount.c
blob8a49486bf30c9859a5474f3cc5055bc7b9917de4
1 /*
2 * fs/sysfs/symlink.c - operations for initializing and mounting sysfs
4 * Copyright (c) 2001-3 Patrick Mochel
5 * Copyright (c) 2007 SUSE Linux Products GmbH
6 * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
8 * This file is released under the GPLv2.
10 * Please see Documentation/filesystems/sysfs.txt for more information.
13 #define DEBUG
15 #include <linux/fs.h>
16 #include <linux/magic.h>
17 #include <linux/mount.h>
18 #include <linux/init.h>
19 #include <linux/user_namespace.h>
21 #include "sysfs.h"
23 static struct kernfs_root *sysfs_root;
24 struct kernfs_node *sysfs_root_kn;
26 static struct dentry *sysfs_mount(struct file_system_type *fs_type,
27 int flags, const char *dev_name, void *data)
29 struct dentry *root;
30 void *ns;
31 bool new_sb;
33 if (!(flags & MS_KERNMOUNT)) {
34 if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
35 return ERR_PTR(-EPERM);
37 if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
38 return ERR_PTR(-EPERM);
41 ns = kobj_ns_grab_current(KOBJ_NS_TYPE_NET);
42 root = kernfs_mount_ns(fs_type, flags, sysfs_root,
43 SYSFS_MAGIC, &new_sb, ns);
44 if (IS_ERR(root) || !new_sb)
45 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
46 return root;
49 static void sysfs_kill_sb(struct super_block *sb)
51 void *ns = (void *)kernfs_super_ns(sb);
53 kernfs_kill_sb(sb);
54 kobj_ns_drop(KOBJ_NS_TYPE_NET, ns);
57 static struct file_system_type sysfs_fs_type = {
58 .name = "sysfs",
59 .mount = sysfs_mount,
60 .kill_sb = sysfs_kill_sb,
61 .fs_flags = FS_USERNS_MOUNT,
64 int __init sysfs_init(void)
66 int err;
68 sysfs_root = kernfs_create_root(NULL, KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK,
69 NULL);
70 if (IS_ERR(sysfs_root))
71 return PTR_ERR(sysfs_root);
73 sysfs_root_kn = sysfs_root->kn;
75 err = register_filesystem(&sysfs_fs_type);
76 if (err) {
77 kernfs_destroy_root(sysfs_root);
78 return err;
81 return 0;