From c7f93a20c47f712d45cd97fdfd43e0715ae855e3 Mon Sep 17 00:00:00 2001 From: "grub-devel@iam.tj" Date: Sat, 7 Nov 2015 18:52:59 +0300 Subject: [PATCH] cryptodisk: teach grub_cryptodisk_insert() about partitions (bug #45889) It is not possible to configure encrypted containers on multiple partitions of the same disk; after the first one all subsequent fail with disk/cryptodisk.c:978: already mounted as crypto0 Store partition offset in cryptomount descriptor to distinguish between them. --- grub-core/disk/cryptodisk.c | 7 ++++++- include/grub/cryptodisk.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) 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;