Skip to content

Commit

Permalink
btrfs: sysfs: fix direct super block member reads
Browse files Browse the repository at this point in the history
commit fca432e upstream.

The following sysfs entries are reading super block member directly,
which can have a different endian and cause wrong values:

- sys/fs/btrfs/<uuid>/nodesize
- sys/fs/btrfs/<uuid>/sectorsize
- sys/fs/btrfs/<uuid>/clone_alignment

Thankfully those values (nodesize and sectorsize) are always aligned
inside the btrfs_super_block, so it won't trigger unaligned read errors,
just endian problems.

Fix them by using the native cached members instead.

Fixes: df93589 ("btrfs: export more from FS_INFO to sysfs")
CC: stable@vger.kernel.org
Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Qu Wenruo authored and Greg Kroah-Hartman committed Jan 2, 2025
1 parent b87c9b9 commit dbebb0c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions fs/btrfs/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ static ssize_t btrfs_nodesize_show(struct kobject *kobj,
{
struct btrfs_fs_info *fs_info = to_fs_info(kobj);

return sysfs_emit(buf, "%u\n", fs_info->super_copy->nodesize);
return sysfs_emit(buf, "%u\n", fs_info->nodesize);
}

BTRFS_ATTR(, nodesize, btrfs_nodesize_show);
Expand All @@ -1128,7 +1128,7 @@ static ssize_t btrfs_sectorsize_show(struct kobject *kobj,
{
struct btrfs_fs_info *fs_info = to_fs_info(kobj);

return sysfs_emit(buf, "%u\n", fs_info->super_copy->sectorsize);
return sysfs_emit(buf, "%u\n", fs_info->sectorsize);
}

BTRFS_ATTR(, sectorsize, btrfs_sectorsize_show);
Expand Down Expand Up @@ -1180,7 +1180,7 @@ static ssize_t btrfs_clone_alignment_show(struct kobject *kobj,
{
struct btrfs_fs_info *fs_info = to_fs_info(kobj);

return sysfs_emit(buf, "%u\n", fs_info->super_copy->sectorsize);
return sysfs_emit(buf, "%u\n", fs_info->sectorsize);
}

BTRFS_ATTR(, clone_alignment, btrfs_clone_alignment_show);
Expand Down

0 comments on commit dbebb0c

Please sign in to comment.