Skip to content

Commit 21e7626

Browse files
kdavemasoncl
authored andcommitted
btrfs: use macro accessors in superblock validation checks
The initial patch c926093 (btrfs: add more superblock checks) did not properly use the macro accessors that wrap endianness and the code would not work correctly on big endian machines. Reported-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent d379730 commit 21e7626

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

fs/btrfs/disk-io.c

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,35 +3817,35 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
38173817
struct btrfs_super_block *sb = fs_info->super_copy;
38183818
int ret = 0;
38193819

3820-
if (sb->root_level > BTRFS_MAX_LEVEL) {
3821-
printk(KERN_ERR "BTRFS: tree_root level too big: %d > %d\n",
3822-
sb->root_level, BTRFS_MAX_LEVEL);
3820+
if (btrfs_super_root_level(sb) >= BTRFS_MAX_LEVEL) {
3821+
printk(KERN_ERR "BTRFS: tree_root level too big: %d >= %d\n",
3822+
btrfs_super_root_level(sb), BTRFS_MAX_LEVEL);
38233823
ret = -EINVAL;
38243824
}
3825-
if (sb->chunk_root_level > BTRFS_MAX_LEVEL) {
3826-
printk(KERN_ERR "BTRFS: chunk_root level too big: %d > %d\n",
3827-
sb->chunk_root_level, BTRFS_MAX_LEVEL);
3825+
if (btrfs_super_chunk_root_level(sb) >= BTRFS_MAX_LEVEL) {
3826+
printk(KERN_ERR "BTRFS: chunk_root level too big: %d >= %d\n",
3827+
btrfs_super_chunk_root_level(sb), BTRFS_MAX_LEVEL);
38283828
ret = -EINVAL;
38293829
}
3830-
if (sb->log_root_level > BTRFS_MAX_LEVEL) {
3831-
printk(KERN_ERR "BTRFS: log_root level too big: %d > %d\n",
3832-
sb->log_root_level, BTRFS_MAX_LEVEL);
3830+
if (btrfs_super_log_root_level(sb) >= BTRFS_MAX_LEVEL) {
3831+
printk(KERN_ERR "BTRFS: log_root level too big: %d >= %d\n",
3832+
btrfs_super_log_root_level(sb), BTRFS_MAX_LEVEL);
38333833
ret = -EINVAL;
38343834
}
38353835

38363836
/*
38373837
* The common minimum, we don't know if we can trust the nodesize/sectorsize
38383838
* items yet, they'll be verified later. Issue just a warning.
38393839
*/
3840-
if (!IS_ALIGNED(sb->root, 4096))
3840+
if (!IS_ALIGNED(btrfs_super_root(sb), 4096))
38413841
printk(KERN_WARNING "BTRFS: tree_root block unaligned: %llu\n",
38423842
sb->root);
3843-
if (!IS_ALIGNED(sb->chunk_root, 4096))
3843+
if (!IS_ALIGNED(btrfs_super_chunk_root(sb), 4096))
38443844
printk(KERN_WARNING "BTRFS: tree_root block unaligned: %llu\n",
38453845
sb->chunk_root);
3846-
if (!IS_ALIGNED(sb->log_root, 4096))
3846+
if (!IS_ALIGNED(btrfs_super_log_root(sb), 4096))
38473847
printk(KERN_WARNING "BTRFS: tree_root block unaligned: %llu\n",
3848-
sb->log_root);
3848+
btrfs_super_log_root(sb));
38493849

38503850
if (memcmp(fs_info->fsid, sb->dev_item.fsid, BTRFS_UUID_SIZE) != 0) {
38513851
printk(KERN_ERR "BTRFS: dev_item UUID does not match fsid: %pU != %pU\n",
@@ -3857,28 +3857,29 @@ static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info,
38573857
* Hint to catch really bogus numbers, bitflips or so, more exact checks are
38583858
* done later
38593859
*/
3860-
if (sb->num_devices > (1UL << 31))
3860+
if (btrfs_super_num_devices(sb) > (1UL << 31))
38613861
printk(KERN_WARNING "BTRFS: suspicious number of devices: %llu\n",
3862-
sb->num_devices);
3862+
btrfs_super_num_devices(sb));
38633863

3864-
if (sb->bytenr != BTRFS_SUPER_INFO_OFFSET) {
3864+
if (btrfs_super_bytenr(sb) != BTRFS_SUPER_INFO_OFFSET) {
38653865
printk(KERN_ERR "BTRFS: super offset mismatch %llu != %u\n",
3866-
sb->bytenr, BTRFS_SUPER_INFO_OFFSET);
3866+
btrfs_super_bytenr(sb), BTRFS_SUPER_INFO_OFFSET);
38673867
ret = -EINVAL;
38683868
}
38693869

38703870
/*
38713871
* The generation is a global counter, we'll trust it more than the others
38723872
* but it's still possible that it's the one that's wrong.
38733873
*/
3874-
if (sb->generation < sb->chunk_root_generation)
3874+
if (btrfs_super_generation(sb) < btrfs_super_chunk_root_generation(sb))
38753875
printk(KERN_WARNING
38763876
"BTRFS: suspicious: generation < chunk_root_generation: %llu < %llu\n",
3877-
sb->generation, sb->chunk_root_generation);
3878-
if (sb->generation < sb->cache_generation && sb->cache_generation != (u64)-1)
3877+
btrfs_super_generation(sb), btrfs_super_chunk_root_generation(sb));
3878+
if (btrfs_super_generation(sb) < btrfs_super_cache_generation(sb)
3879+
&& btrfs_super_cache_generation(sb) != (u64)-1)
38793880
printk(KERN_WARNING
38803881
"BTRFS: suspicious: generation < cache_generation: %llu < %llu\n",
3881-
sb->generation, sb->cache_generation);
3882+
btrfs_super_generation(sb), btrfs_super_cache_generation(sb));
38823883

38833884
return ret;
38843885
}

0 commit comments

Comments
 (0)