aboutsummaryrefslogtreecommitdiffstats
path: root/fs/sysfs
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-03-28 18:52:14 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-03-28 18:52:14 -0400
commit97f084b8e64fb69ad1ede987c98c443f440a8aa1 (patch)
tree9f7a3e1190da0e7297f163e72ab3735fbdefdf91 /fs/sysfs
parent1b6a4db220cf04114980694685b668bad4ca030d (diff)
parente5110f411d2ee35bf8d202ccca2e89c633060dca (diff)
Merge tag 'driver-core-3.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull sysfs fixes from Greg Kroah-Hartman: "Here are two fixes for sysfs that resolve issues that have been found by the Trinity fuzz tool, causing oopses in sysfs. They both have been in linux-next for a while to ensure that they do not cause any other problems." * tag 'driver-core-3.9-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: sysfs: handle failure path correctly for readdir() sysfs: fix race between readdir and lseek
Diffstat (limited to 'fs/sysfs')
-rw-r--r--fs/sysfs/dir.c17
1 files changed, 16 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
1065static 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
1062const struct file_operations sysfs_dir_operations = { 1077const 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};