Minor updates to sysfs
David Sterba
maintainercover Minor updates to sysfs
Hi,
a less-than-handful set of fixes to sysfs, two sanity checks and one additional locking preventing a pretty rare race.
David Sterba (3):
btrfs: add read-only check to sysfs handler of features
btrfs: add check to sysfs handler of label
btrfs: sysfs: protect reading label by lock
fs/btrfs/sysfs.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 1/3 btrfs: add read-only check to sysfs handler of features
From: David Sterba <[email protected]>
We don't want to trigger the change on a read-only filesystem, similar to what the label handler does.
--- fs/btrfs/sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/sysfs.c +3 -0
@@ -120,6 +120,9 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,if (!fs_info)return -EPERM ; +if (fs_info->sb->s_flags &MS_RDONLY ) +return -EROFS ; + ret =kstrtoul (skip_spaces (buf),0 , &val);if (ret)return ret;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 2/3 btrfs: add check to sysfs handler of label
In reply to David SterbaAdd a sanity check for the fs_info as we will dereference it, similar to what the 'store features' handler does.
--- fs/btrfs/sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/sysfs.c +3 -0
@@ -377,6 +377,9 @@ static ssize_t btrfs_label_store(struct kobject *kobj,struct btrfs_fs_info *fs_info =to_fs_info (kobj);size_t p_len; +if (!fs_info) +return -EPERM ; +if (fs_info->sb->s_flags &MS_RDONLY )return -EROFS ;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 3/3 btrfs: sysfs: protect reading label by lock
In reply to David SterbaIf the label setting ioctl races with sysfs label handler, we could get mixed result in the output, part old part new. We should either get the old or new label. The chances to hit this race are low.
--- fs/btrfs/sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
fs/btrfs/sysfs.c +6 -1
@@ -367,7 +367,12 @@ static ssize_t btrfs_label_show(struct kobject *kobj, {struct btrfs_fs_info *fs_info =to_fs_info (kobj);char *label = fs_info->super_copy->label; -return snprintf (buf,PAGE_SIZE , label[0 ] ?"%s\n" :"%s" , label); + +spin_lock (&fs_info->super_lock); +snprintf (buf,PAGE_SIZE , label[0 ] ?"%s\n" :"%s" , label); +spin_unlock (&fs_info->super_lock); + +return buf; } static ssize_t btrfs_label_store(struct kobject *kobj,
Signature · 1 line
2.7.1
Re: [PATCH 3/3] btrfs: sysfs: protect reading label by lock
Quoted 14 lines · David Sterba
If the label setting ioctl races with sysfs label handler, we could get mixed result in the output, part old part new. We should either get the old or new label. The chances to hit this race are low.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)fs/btrfs/sysfs.c +0
-0
fs/btrfs/sysfs.c static ssize_t btrfs_label_show(struct kobject *kobj, · line 375
Quoted 10 lines
fs/btrfs/sysfs.c +6
-1@@ -367,7 +367,12 @@ static ssize_t btrfs_label_show(struct kobject *kobj, {struct btrfs_fs_info *fs_info =to_fs_info (kobj);char *label = fs_info->super_copy->label; -return snprintf (buf,PAGE_SIZE , label[0 ] ?"%s\n" :"%s" , label); + +spin_lock (&fs_info->super_lock); +snprintf (buf,PAGE_SIZE , label[0 ] ?"%s\n" :"%s" , label); +spin_unlock (&fs_info->super_lock); + +return buf;
We should return a ssize_t value, not a char *. I.e. return what snprintf returns. This should make gcc emit a warning.
Quoted 10 lines
fs/btrfs/sysfs.c +0
-1} static ssize_t btrfs_label_store(struct kobject *kobj, --2.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Filipe David Manana, "Reasonable men adapt themselves to the world. Unreasonable men adapt the world to themselves. That's why all progress depends on unreasonable men."
Re: [PATCH 3/3] btrfs: sysfs: protect reading label by lock
Quoted 20 lines · Filipe Manana
Quoted 19 lines · David Sterba
If the label setting ioctl races with sysfs label handler, we could get mixed result in the output, part old part new. We should either get the old or new label. The chances to hit this race are low.
Signed-off-by David Sterba <[email protected]>--- fs/btrfs/sysfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)fs/btrfs/sysfs.c +1
-1@@ -367,7 +367,12 @@ static ssize_t btrfs_label_show(struct kobject *kobj, {struct btrfs_fs_info *fs_info =to_fs_info (kobj);char *label = fs_info->super_copy->label; -return snprintf (buf,PAGE_SIZE , label[0 ] ?"%s\n" :"%s" , label); +
Quoted 8 lines
fs/btrfs/sysfs.c static ssize_t btrfs_label_show(struct kobject *kobj, · line 375
Quoted 5 lines
fs/btrfs/sysfs.c +5
-0+spin_lock (&fs_info->super_lock); +snprintf (buf,PAGE_SIZE , label[0 ] ?"%s\n" :"%s" , label); +spin_unlock (&fs_info->super_lock); + +return buf;We should return a
ssize_tvalue, not a char *. I.e. return what snprintf returns. This should make gcc emit a warning.
Indeed the warning was there and I overlooked it, last minute patches before leaving. Thanks for catching it.