Commit 1c9668ce authored by Qu Wenruo's avatar Qu Wenruo Committed by Wen Zhiwei
Browse files

btrfs: sysfs: fix direct super block member reads

stable inclusion
from stable-v6.6.69
commit 1ce362065899ec7eb06518a04e1cb8b76fcaf8f8
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IBNEPJ

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=1ce362065899ec7eb06518a04e1cb8b76fcaf8f8



--------------------------------

commit fca432e73db2bec0fdbfbf6d98d3ebcd5388a977 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: df93589a ("btrfs: export more from FS_INFO to sysfs")
CC: stable@vger.kernel.org
Reviewed-by: default avatarNaohiro Aota <naohiro.aota@wdc.com>
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarQu Wenruo <wqu@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarWen Zhiwei <wenzhiwei@kylinos.cn>
parent 9b3df1d5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -1022,7 +1022,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);
@@ -1032,7 +1032,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);
@@ -1084,7 +1084,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);