From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZYnli-0000wB-2F for mharc-grub-devel@gnu.org; Mon, 07 Sep 2015 00:10:58 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37861) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYnlf-0000uz-8F for grub-devel@gnu.org; Mon, 07 Sep 2015 00:10:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZYnlb-0006oa-5d for grub-devel@gnu.org; Mon, 07 Sep 2015 00:10:55 -0400 Received: from yes.iam.tj ([109.74.197.121]:32808 helo=iam.tj) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZYnla-0006l1-TE for grub-devel@gnu.org; Mon, 07 Sep 2015 00:10:51 -0400 Received: by iam.tj (Postfix, from userid 1013) id 7E60134107; Mon, 7 Sep 2015 05:10:46 +0100 (BST) To: grub-devel@gnu.org Subject: cryptodisk: teach =?UTF-8?Q?grub=5Fcryptodisk=5Finsert=28=29=20ab?= =?UTF-8?Q?out=20partitions=20=28bug=20=23=34=35=38=38=39=29?= X-PHP-Originating-Script: 1013:rcmail.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 07 Sep 2015 05:10:46 +0100 From: TJ Message-ID: X-Sender: grub-devel@iam.tj User-Agent: Roundcube Webmail/RCMAIL_VERSION X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 109.74.197.121 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Sep 2015 04:10:56 -0000 https://savannah.gnu.org/bugs/index.php?45889 Boot disk with 3 LUKS/dm-crypt GPT partitions (hd0,gpt3) (hd0,gpt4) (hd0,gpt5) grub is in (hd0,gpt3). The others have a LVM VG each. Using GRUB_ENABLE_CRYPTODISK=y I deliberately fail the first pass-phrase entry to get the rescue environment. I then cryptomount hd0,gpt3 (crypto0) device is now present and prefix/root are set correctly. I insmod some other modules (exploring available functions) and set debug=cryptodisk I try to cryptomount hd0,gpt4 cryptomount hd0,gpt4 and see the message disk/cryptodisk.c:978: already mounted as crypto0 But ls shows only (crypto0) With the attached patch the mounts now work: Attempting to decrypt master key... Enter passphrase for hd0,gpt3 ( ...UUID...) Slot 0 opened <<<< next line comes from temporary grub_dprintf() not included in patch >>>> disk/cryptodisk.c:718: insert 0, source 'hd0,gpt3', id 128, dev_id 0 grub rescue> ls (hd0) (hd0,gpt5) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1) (crypto0) (proc) grub rescue> cryptomount hd0,gpt4 Attempting to decrypt master key... Enter passphrase for hd0,gpt4 (...UUID...) Slot 0 opened disk/cryptodisk.c:718: insert 1, source 'hd0,gpt4', id 128, dev_id 0 grub rescue> cryptomount hd0,gpt5 Attempting to decrypt master key... Enter passphrase for hd0,gpt5 (...UUID...) Slot 0 opened disk/cryptodisk.c:718: insert 2, source 'hd0,gpt4', id 128, dev_id 0 grub rescue> insmod lvm grub rescue> ls (lvm/VG_OS-x86_64.usr_local) (lvm/VG_OS-ubuntu_15.10_var) (lvm/VG_OS-ubuntu_15.10_rootfs) (lvm/VG_DATA-home) (hd0) (hd0,gpt5) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1) (crypto2) (crypto1) (crypto0) (proc) --- 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 82a3dcb..0e6bc3f 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_number = source->partition ? source->partition->number : 0; 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 && disk->partition->number == dev->partition_number) || + (!disk->partition && dev->partition_number == 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_number = source->partition ? source->partition->number : 0; 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 f2ad2a7..b638f2e 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; + int partition_number; }; typedef struct grub_cryptodisk *grub_cryptodisk_t; -- 2.5.0