diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 85d68e3b6..1e03a091c 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -25,6 +25,7 @@ #include #include #include +#include #ifdef GRUB_UTIL #include @@ -718,6 +719,7 @@ grub_cryptodisk_insert (grub_cryptodisk_t newdev, const char *name, newdev->id = last_cryptodisk_id++; newdev->source_id = source->id; newdev->source_dev_id = source->dev->id; + newdev->partition_start = grub_partition_get_start (source->partition); newdev->next = cryptodisk_list; cryptodisk_list = newdev; @@ -740,7 +742,9 @@ grub_cryptodisk_get_by_source_disk (grub_disk_t disk) grub_cryptodisk_t dev; for (dev = cryptodisk_list; dev != NULL; dev = dev->next) if (dev->source_id == disk->id && dev->source_dev_id == disk->dev->id) - return dev; + if ((disk->partition && grub_partition_get_start (disk->partition) == dev->partition_start) || + (!disk->partition && dev->partition_start == 0)) + return dev; return NULL; } @@ -761,6 +765,7 @@ grub_cryptodisk_cheat_insert (grub_cryptodisk_t newdev, const char *name, newdev->cheat_fd = GRUB_UTIL_FD_INVALID; newdev->source_id = source->id; newdev->source_dev_id = source->dev->id; + newdev->partition_start = grub_partition_get_start (source->partition); newdev->id = last_cryptodisk_id++; newdev->next = cryptodisk_list; cryptodisk_list = newdev; diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index f2ad2a79a..32f564ae0 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -97,6 +97,7 @@ struct grub_cryptodisk grub_uint8_t rekey_key[64]; grub_uint64_t last_rekey; int rekey_derived_size; + grub_disk_addr_t partition_start; }; typedef struct grub_cryptodisk *grub_cryptodisk_t;