All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] osdep/linux: convert partition start to disk sector length.
@ 2018-07-23  6:52 Mihai Moldovan
  2018-09-06 13:40 ` Daniel Kiper
  2018-09-06 17:36 ` [PATCH] " Vladimir 'phcoder' Serbinenko
  0 siblings, 2 replies; 8+ messages in thread
From: Mihai Moldovan @ 2018-07-23  6:52 UTC (permalink / raw)
  To: grub-devel; +Cc: 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



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

* Re: [PATCH] osdep/linux: convert partition start to disk sector length.
  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   ` [PATCH v2] " Mihai Moldovan
  2018-09-06 17:36 ` [PATCH] " Vladimir 'phcoder' Serbinenko
  1 sibling, 1 reply; 8+ messages in thread
From: Daniel Kiper @ 2018-09-06 13:40 UTC (permalink / raw)
  To: Mihai Moldovan; +Cc: grub-devel

On Mon, Jul 23, 2018 at 08:52:50AM +0200, Mihai Moldovan 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.

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

Daniel


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

* [PATCH v2] osdep/linux: convert partition start to disk sector length.
  2018-09-06 13:40 ` Daniel Kiper
@ 2018-09-06 14:16   ` Mihai Moldovan
  2018-09-06 14:53     ` Daniel Kiper
  0 siblings, 1 reply; 8+ messages in thread
From: Mihai Moldovan @ 2018-09-06 14:16 UTC (permalink / raw)
  To: grub-devel; +Cc: 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.

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



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

* Re: [PATCH v2] osdep/linux: convert partition start to disk sector length.
  2018-09-06 14:16   ` [PATCH v2] " Mihai Moldovan
@ 2018-09-06 14:53     ` Daniel Kiper
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Kiper @ 2018-09-06 14:53 UTC (permalink / raw)
  To: Mihai Moldovan; +Cc: grub-devel

On Thu, Sep 06, 2018 at 04:16:39PM +0200, Mihai Moldovan 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.
>
> Signed-off-by: Mihai Moldovan <ionic@ionic.de>

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

Daniel


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

* Re: [PATCH] osdep/linux: convert partition start to disk sector length.
  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 17:36 ` Vladimir 'phcoder' Serbinenko
  2018-09-06 18:02   ` Mihai Moldovan
  1 sibling, 1 reply; 8+ messages in thread
From: Vladimir 'phcoder' Serbinenko @ 2018-09-06 17:36 UTC (permalink / raw)
  To: The development of GNU GRUB; +Cc: Mihai Moldovan

[-- Attachment #1: Type: text/plain, Size: 1644 bytes --]

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

On Mon, 23 Jul 2018, 09:54 Mihai Moldovan, <ionic@ionic.de> 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(-)
>
> 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
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
>

[-- Attachment #2: Type: text/html, Size: 2187 bytes --]

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

* Re: [PATCH] osdep/linux: convert partition start to disk sector length.
  2018-09-06 17:36 ` [PATCH] " Vladimir 'phcoder' Serbinenko
@ 2018-09-06 18:02   ` Mihai Moldovan
  2018-09-19 13:58     ` Daniel Kiper
  0 siblings, 1 reply; 8+ messages in thread
From: Mihai Moldovan @ 2018-09-06 18:02 UTC (permalink / raw)
  To: Vladimir 'phcoder' Serbinenko, The development of GNU GRUB


[-- Attachment #1.1: Type: text/plain, Size: 502 bytes --]

* 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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 898 bytes --]

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

* Re: [PATCH] osdep/linux: convert partition start to disk sector length.
  2018-09-06 18:02   ` Mihai Moldovan
@ 2018-09-19 13:58     ` Daniel Kiper
  2018-09-19 14:00       ` Daniel Kiper
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Kiper @ 2018-09-19 13:58 UTC (permalink / raw)
  To: Mihai Moldovan
  Cc: Vladimir 'phcoder' Serbinenko, The development of GNU GRUB

On Thu, Sep 06, 2018 at 08:02:02PM +0200, Mihai Moldovan wrote:
> * 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.

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

Daniel


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

* Re: [PATCH] osdep/linux: convert partition start to disk sector length.
  2018-09-19 13:58     ` Daniel Kiper
@ 2018-09-19 14:00       ` Daniel Kiper
  0 siblings, 0 replies; 8+ messages in thread
From: Daniel Kiper @ 2018-09-19 14:00 UTC (permalink / raw)
  To: ionic; +Cc: Vladimir 'phcoder' Serbinenko, The development of GNU GRUB

On Wed, Sep 19, 2018 at 03:58:56PM +0200, Daniel Kiper wrote:
> On Thu, Sep 06, 2018 at 08:02:02PM +0200, Mihai Moldovan wrote:
> > * 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.
>
> If there are no more questions or objections I will push this patch next week.

Err... Of course v2.

Daniel


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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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   ` [PATCH v2] " Mihai Moldovan
2018-09-06 14:53     ` 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

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.