grub2/0095-Fix-a-btrfs-read-before-init-bug.patch

40 lines
1.4 KiB
Diff
Raw Normal View History

From de37bf80fed16a991a9218ca5fb73008f59cd689 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 26 Jun 2017 12:35:47 -0400
Subject: [PATCH 095/105] Fix a btrfs read-before-init bug
---
grub-core/fs/btrfs.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c
index 9cffa91fa..cb25b9ddd 100644
--- a/grub-core/fs/btrfs.c
+++ b/grub-core/fs/btrfs.c
@@ -232,10 +232,6 @@ 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)
@@ -247,6 +243,11 @@ read_sblock (grub_disk_t disk, struct grub_btrfs_superblock *sb)
if (i == 0 || grub_le_to_cpu64 (sblock.generation)
> grub_le_to_cpu64 (sb->generation))
grub_memcpy (sb, &sblock, sizeof (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;
}
if ((err == GRUB_ERR_OUT_OF_RANGE || !err) && i == 0)
--
2.13.0