osdep/linux: convert partition start to disk sector length.
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
@@ -374,7 +374,8 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int fchar 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
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
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
@@ -374,7 +374,8 @@ grub_util_fd_open_device (const grub_disk_t disk, grub_disk_addr_t sector, int fchar 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
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.
Signed-off-by Mihai Moldovan <[email protected]>
Daniel
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@@ -374,7 +374,8 @@ grub_util_fd_open_device (const grub_disk_t disk,
grub_disk_addr_tsector, int fchar 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
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
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 thefd_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
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 thefd_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