Discussion:
[PATCH] osdep/linux: convert partition start to disk sector length.
(too old to reply)
Mihai Moldovan
2018-07-23 06:52:50 UTC
Permalink
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(-)

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
Daniel Kiper
2018-09-06 13:40:09 UTC
Permalink
Post by 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
Mihai Moldovan
2018-09-06 14:16:39 UTC
Permalink
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.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
Daniel Kiper
2018-09-06 14:53:38 UTC
Permalink
Post by 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.
Reviewed-by: Daniel Kiper <***@oracle.com>

Daniel
Vladimir 'phcoder' Serbinenko
2018-09-06 17:36:51 UTC
Permalink
Grub partition get start returns in 512B blocks. Can I have more details
like which partmap you use?
Post by 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.
---
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
_______________________________________________
Grub-devel mailing list
https://lists.gnu.org/mailman/listinfo/grub-devel
Mihai Moldovan
2018-09-06 18:02:02 UTC
Permalink
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
Daniel Kiper
2018-09-19 13:58:56 UTC
Permalink
Post by Mihai Moldovan
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.
If there are no more questions or objections I will push this patch next week.

Daniel
Daniel Kiper
2018-09-19 14:00:58 UTC
Permalink
Post by Daniel Kiper
Post by Mihai Moldovan
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.
If there are no more questions or objections I will push this patch next week.
Err... Of course v2.

Daniel

Loading...