grub-devel.gnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] msdos: Fix overflow in converting partition start and length into 512B blocks
@ 2018-09-13  8:08 Michael Chang
  2018-09-19 13:46 ` Daniel Kiper
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Chang @ 2018-09-13  8:08 UTC (permalink / raw)
  To: The development of GNU GRUB

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 <mchang@suse.com>
---
 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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] msdos: Fix overflow in converting partition start and length into 512B blocks
  2018-09-13  8:08 [PATCH] msdos: Fix overflow in converting partition start and length into 512B blocks Michael Chang
@ 2018-09-19 13:46 ` Daniel Kiper
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Kiper @ 2018-09-19 13:46 UTC (permalink / raw)
  To: mchang; +Cc: grub-devel

On Thu, Sep 13, 2018 at 04:08:20PM +0800, Michael Chang wrote:
> 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 <mchang@suse.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-19 13:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-13  8:08 [PATCH] msdos: Fix overflow in converting partition start and length into 512B blocks Michael Chang
2018-09-19 13:46 ` Daniel Kiper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).