From e06c2e7abc5ac6b1b0ce0c96451b70d637e35cac Mon Sep 17 00:00:00 2001 From: Vladimir 'phcoder' Serbinenko Date: Wed, 25 Jan 2012 15:10:56 +0100 Subject: [PATCH] * grub-core/fs/btrfs.c (grub_btrfs_device): New field size. (read_sblock): Don't attempt to read superblocks outside the disk size. --- ChangeLog | 5 +++++ grub-core/fs/btrfs.c | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a497910a0..f4b5606fe 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2012-01-25 Vladimir Serbinenko + + * grub-core/fs/btrfs.c (grub_btrfs_device): New field size. + (read_sblock): Don't attempt to read superblocks outside the disk size. + 2012-01-25 Vladimir Serbinenko * grub-core/fs/nilfs2.c (grub_nilfs2_load_sb): Use device size from diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c index b877cab63..3660b60ac 100644 --- a/grub-core/fs/btrfs.c +++ b/grub-core/fs/btrfs.c @@ -49,7 +49,8 @@ typedef grub_uint16_t grub_btrfs_uuid_t[8]; struct grub_btrfs_device { grub_uint64_t device_id; - grub_uint8_t dummy[0x62 - 8]; + grub_uint64_t size; + grub_uint8_t dummy[0x62 - 0x10]; } __attribute__ ((packed)); struct grub_btrfs_superblock @@ -248,6 +249,10 @@ read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb) for (i = 0; i < ARRAY_SIZE (superblock_sectors); i++) { struct grub_btrfs_superblock sblock; + /* Don't try additional superblocks beyond device size. */ + if (i && (grub_le_to_cpu64 (sblock.this_device.size) + >> GRUB_DISK_SECTOR_BITS) <= superblock_sectors[i]) + break; err = grub_disk_read (disk, superblock_sectors[i], 0, sizeof (sblock), &sblock); if (err == GRUB_ERR_OUT_OF_RANGE)