Received: from list by lists.gnu.org with archive (Exim 4.71) id 1g0Mg0-00021L-77 for mharc-grub-devel@gnu.org; Thu, 13 Sep 2018 04:08:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34474) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g0Mfy-00021C-9j for grub-devel@gnu.org; Thu, 13 Sep 2018 04:08:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g0Mfs-0003VV-Fe for grub-devel@gnu.org; Thu, 13 Sep 2018 04:08:34 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:32893) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g0Mfs-0003UT-6h for grub-devel@gnu.org; Thu, 13 Sep 2018 04:08:28 -0400 Received: from mazu (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Thu, 13 Sep 2018 02:08:24 -0600 Date: Thu, 13 Sep 2018 16:08:20 +0800 From: Michael Chang To: The development of GNU GRUB Subject: [PATCH] msdos: Fix overflow in converting partition start and length into 512B blocks Message-ID: <20180913080820.z5mic4tz55a6xtkx@mazu> Mail-Followup-To: The development of GNU GRUB MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: NeoMutt/20170421 (1.8.2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 137.65.250.81 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Sep 2018 08:08:35 -0000 When booting from NVME SSD with 4k sector size, it fails with the message. error: attempt to read or write outside of partition. This patch fixes the problem by fixing overflow in converting partition start and length into 512B blocks. Signed-off-by: Michael Chang --- grub-core/partmap/msdos.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c index 6d4b455a1..7b8e45076 100644 --- a/grub-core/partmap/msdos.c +++ b/grub-core/partmap/msdos.c @@ -175,9 +175,9 @@ grub_partition_msdos_iterate (grub_disk_t disk, e = mbr.entries + p.index; p.start = p.offset - + (grub_le_to_cpu32 (e->start) + + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)) - delta; - p.len = grub_le_to_cpu32 (e->length) + p.len = (grub_uint64_t)grub_le_to_cpu32 (e->length) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); p.msdostype = e->type; @@ -210,7 +210,7 @@ grub_partition_msdos_iterate (grub_disk_t disk, if (grub_msdos_partition_is_extended (e->type)) { p.offset = ext_offset - + (grub_le_to_cpu32 (e->start) + + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); if (! ext_offset) ext_offset = p.offset; @@ -294,9 +294,9 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (!grub_msdos_partition_is_empty (e->type) && end > offset - + (grub_le_to_cpu32 (e->start) + + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS))) - end = offset + (grub_le_to_cpu32 (e->start) + end = offset + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); /* If this is a GPT partition, this MBR is just a dummy. */ @@ -312,7 +312,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, if (grub_msdos_partition_is_extended (e->type)) { offset = ext_offset - + (grub_le_to_cpu32 (e->start) + + ((grub_disk_addr_t)grub_le_to_cpu32 (e->start) << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS)); if (! ext_offset) ext_offset = offset; -- 2.13.6