All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mihai Moldovan <ionic@ionic.de>
To: grub-devel@gnu.org
Cc: Mihai Moldovan <ionic@ionic.de>
Subject: [PATCH v2] osdep/linux: convert partition start to disk sector length.
Date: Thu,  6 Sep 2018 16:16:39 +0200	[thread overview]
Message-ID: <20180906141639.3050-1-ionic@ionic.de> (raw)
In-Reply-To: <20180906134009.GC29770@router-fw-old.i.net-space.pl>

When reading data off a disk, sector values are based on the disk sector
length.

Within grub_util_fd_open_device(), the start of the partition was taken
directly from grub's partition information structure, which uses the
internal sector length (currently 512b), but never transformed to the
disk's sector length.

Subsequent calculations were all wrong for devices that have a diverging
sector length and the functions eventually skipped to the wrong stream
location, reading invalid data.

Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
 grub-core/osdep/linux/hostdisk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/grub-core/osdep/linux/hostdisk.c b/grub-core/osdep/linux/hostdisk.c
index 06179fca7..8b92f8528 100644
--- a/grub-core/osdep/linux/hostdisk.c
+++ b/grub-core/osdep/linux/hostdisk.c
@@ -374,7 +374,8 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int f
     char dev[PATH_MAX];
     grub_disk_addr_t part_start = 0;
 
-    part_start = grub_partition_get_start (disk->partition);
+    part_start = grub_partition_get_start (disk->partition)
+                 >> (disk->log_sector_size - GRUB_DISK_SECTOR_BITS);
 
     strncpy (dev, grub_util_biosdisk_get_osdev (disk), sizeof (dev) - 1);
     dev[sizeof(dev) - 1] = '\0';
-- 
2.15.1



  reply	other threads:[~2018-09-06 14:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-23  6:52 [PATCH] osdep/linux: convert partition start to disk sector length Mihai Moldovan
2018-09-06 13:40 ` Daniel Kiper
2018-09-06 14:16   ` Mihai Moldovan [this message]
2018-09-06 14:53     ` [PATCH v2] " Daniel Kiper
2018-09-06 17:36 ` [PATCH] " Vladimir 'phcoder' Serbinenko
2018-09-06 18:02   ` Mihai Moldovan
2018-09-19 13:58     ` Daniel Kiper
2018-09-19 14:00       ` Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180906141639.3050-1-ionic@ionic.de \
    --to=ionic@ionic.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.