]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
luks2: Convert to crypt sectors from GRUB native sectors
authorGlenn Washburn <development@efficientek.com>
Tue, 15 Dec 2020 23:31:06 +0000 (17:31 -0600)
committerDaniel Kiper <daniel.kiper@oracle.com>
Fri, 18 Dec 2020 13:49:56 +0000 (14:49 +0100)
The function grub_disk_native_sectors(source) returns the number of sectors
of source in GRUB native (512-byte) sectors, not source sized sectors. So
the conversion needs to use GRUB_DISK_SECTOR_BITS, the GRUB native sector
size.

Signed-off-by: Glenn Washburn <development@efficientek.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/disk/luks2.c

index 8d2457557aecffb993463806137eaae970223993..8c1156dd0451623132160be0d8c78ee53a0d0dc0 100644 (file)
@@ -631,7 +631,7 @@ luks2_recover_key (grub_disk_t source,
       crypt->log_sector_size = sizeof (unsigned int) * 8
                - __builtin_clz ((unsigned int) segment.sector_size) - 1;
       if (grub_strcmp (segment.size, "dynamic") == 0)
-       crypt->total_sectors = (grub_disk_native_sectors (source) >> (crypt->log_sector_size - source->log_sector_size))
+       crypt->total_sectors = (grub_disk_native_sectors (source) >> (crypt->log_sector_size - GRUB_DISK_SECTOR_BITS))
                               - crypt->offset_sectors;
       else
        crypt->total_sectors = grub_strtoull (segment.size, NULL, 10) >> crypt->log_sector_size;