diff options
Diffstat (limited to 'fs/sysfs')
-rw-r--r-- | fs/sysfs/dir.c | 17 | ||||
-rw-r--r-- | fs/sysfs/mount.c | 4 |
2 files changed, 20 insertions, 1 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c index 2fbdff6be25c..e14512678c9b 100644 --- a/fs/sysfs/dir.c +++ b/fs/sysfs/dir.c | |||
@@ -1020,6 +1020,8 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
1020 | ino = parent_sd->s_ino; | 1020 | ino = parent_sd->s_ino; |
1021 | if (filldir(dirent, ".", 1, filp->f_pos, ino, DT_DIR) == 0) | 1021 | if (filldir(dirent, ".", 1, filp->f_pos, ino, DT_DIR) == 0) |
1022 | filp->f_pos++; | 1022 | filp->f_pos++; |
1023 | else | ||
1024 | return 0; | ||
1023 | } | 1025 | } |
1024 | if (filp->f_pos == 1) { | 1026 | if (filp->f_pos == 1) { |
1025 | if (parent_sd->s_parent) | 1027 | if (parent_sd->s_parent) |
@@ -1028,6 +1030,8 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
1028 | ino = parent_sd->s_ino; | 1030 | ino = parent_sd->s_ino; |
1029 | if (filldir(dirent, "..", 2, filp->f_pos, ino, DT_DIR) == 0) | 1031 | if (filldir(dirent, "..", 2, filp->f_pos, ino, DT_DIR) == 0) |
1030 | filp->f_pos++; | 1032 | filp->f_pos++; |
1033 | else | ||
1034 | return 0; | ||
1031 | } | 1035 | } |
1032 | mutex_lock(&sysfs_mutex); | 1036 | mutex_lock(&sysfs_mutex); |
1033 | for (pos = sysfs_dir_pos(ns, parent_sd, filp->f_pos, pos); | 1037 | for (pos = sysfs_dir_pos(ns, parent_sd, filp->f_pos, pos); |
@@ -1058,10 +1062,21 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir) | |||
1058 | return 0; | 1062 | return 0; |
1059 | } | 1063 | } |
1060 | 1064 | ||
1065 | static loff_t sysfs_dir_llseek(struct file *file, loff_t offset, int whence) | ||
1066 | { | ||
1067 | struct inode *inode = file_inode(file); | ||
1068 | loff_t ret; | ||
1069 | |||
1070 | mutex_lock(&inode->i_mutex); | ||
1071 | ret = generic_file_llseek(file, offset, whence); | ||
1072 | mutex_unlock(&inode->i_mutex); | ||
1073 | |||
1074 | return ret; | ||
1075 | } | ||
1061 | 1076 | ||
1062 | const struct file_operations sysfs_dir_operations = { | 1077 | const struct file_operations sysfs_dir_operations = { |
1063 | .read = generic_read_dir, | 1078 | .read = generic_read_dir, |
1064 | .readdir = sysfs_readdir, | 1079 | .readdir = sysfs_readdir, |
1065 | .release = sysfs_dir_release, | 1080 | .release = sysfs_dir_release, |
1066 | .llseek = generic_file_llseek, | 1081 | .llseek = sysfs_dir_llseek, |
1067 | }; | 1082 | }; |
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index 8d924b5ec733..afd83273e6ce 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/magic.h> | 20 | #include <linux/magic.h> |
21 | #include <linux/slab.h> | 21 | #include <linux/slab.h> |
22 | #include <linux/user_namespace.h> | ||
22 | 23 | ||
23 | #include "sysfs.h" | 24 | #include "sysfs.h" |
24 | 25 | ||
@@ -111,6 +112,9 @@ static struct dentry *sysfs_mount(struct file_system_type *fs_type, | |||
111 | struct super_block *sb; | 112 | struct super_block *sb; |
112 | int error; | 113 | int error; |
113 | 114 | ||
115 | if (!(flags & MS_KERNMOUNT) && !current_user_ns()->may_mount_sysfs) | ||
116 | return ERR_PTR(-EPERM); | ||
117 | |||
114 | info = kzalloc(sizeof(*info), GFP_KERNEL); | 118 | info = kzalloc(sizeof(*info), GFP_KERNEL); |
115 | if (!info) | 119 | if (!info) |
116 | return ERR_PTR(-ENOMEM); | 120 | return ERR_PTR(-ENOMEM); |