Skip to contentSkip to conversation

osdep/linux: convert partition start to disk sector length.

PATCH Superseded Mihai Moldovan 3 participants 8 messages Jul 23, 2018 – Sep 19, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 osdep/linux: convert partition start to disk sector length.

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.

---
 grub-core/osdep/linux/hostdisk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/osdep/linux/hostdisk.c +2 -1
index 06179fca7..8b92f8528 100644
@@ -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';
Signature · 1 line
2.15.1
#1 lore raw
Quoted 11 lines · Mihai Moldovan

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.

Lack of SOB... May I ask you to add it? Otherwise LGTM.

Daniel

#2 lore raw

PATCH v2 1/1 osdep/linux: convert partition start to disk sector length.

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.

---
 grub-core/osdep/linux/hostdisk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/osdep/linux/hostdisk.c +2 -1
index 06179fca7..8b92f8528 100644
@@ -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';
Signature · 1 line
2.15.1
Reviewed-by on v2 1/1
#3 lore raw
Quoted 8 lines · Mihai Moldovan

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.

Quoted 5 lines

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.

Daniel

#4 lore raw
In reply to Mihai Moldovan

Grub partition get start returns in 512B blocks. Can I have more details like which partmap you use?

Quoted 40 lines · On Mon, 23 Jul 2018, 09:54 Mihai Moldovan, <[email protected]> wrote:

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.

---
 grub-core/osdep/linux/hostdisk.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/osdep/linux/hostdisk.c +0 -0
index 06179fca7..8b92f8528 100644
@@ -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;
grub-core/osdep/linux/hostdisk.c +2 -2
-    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

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw
Quoted 2 lines · * On 09/06/2018 07:36 PM, Vladimir 'phcoder' Serbinenko wrote:

Grub partition get start returns in 512B blocks. Can I have more details like which partmap you use?

Yes, but this is a low-level function that expects sector sizes in HW sector addressing mode.

Note that the whole sector conversion magic was already done by grub_disk_read() and friends which then calls the fd_open() function.

Encountered the issue with a GPT-partitioned, 4096-bytes-sector-size disk.

Mihai

#6 lore raw
Quoted 4 lines · Mihai Moldovan
Quoted 2 lines · * On 09/06/2018 07:36 PM, Vladimir 'phcoder' Serbinenko wrote:

Grub partition get start returns in 512B blocks. Can I have more details like which partmap you use?

Quoted 8 lines

Yes, but this is a low-level function that expects sector sizes in HW sector addressing mode.

Note that the whole sector conversion magic was already done by grub_disk_read() and friends which then calls the fd_open() function.

Encountered the issue with a GPT-partitioned, 4096-bytes-sector-size disk.

If there are no more questions or objections I will push this patch next week.

Daniel

#7 lore raw
Quoted 9 lines · Daniel Kiper
Quoted 8 lines · Mihai Moldovan
Quoted 2 lines · * On 09/06/2018 07:36 PM, Vladimir 'phcoder' Serbinenko wrote:

Grub partition get start returns in 512B blocks. Can I have more details like which partmap you use?

Yes, but this is a low-level function that expects sector sizes in HW sector addressing mode.

Quoted 6 lines
Quoted 4 lines

Note that the whole sector conversion magic was already done by grub_disk_read() and friends which then calls the fd_open() function.

Encountered the issue with a GPT-partitioned, 4096-bytes-sector-size disk.

If there are no more questions or objections I will push this patch next week.

Err... Of course v2.

Daniel