From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nZ99D-0007Vq-LE for mharc-grub-devel@gnu.org; Tue, 29 Mar 2022 06:32:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZ998-0007I7-Gk for grub-devel@gnu.org; Tue, 29 Mar 2022 06:32:18 -0400 Received: from rateau.libregerbil.fr ([195.154.177.100]:35436 helo=mx.libregerbil.fr) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nZ996-0000Z2-1e for grub-devel@gnu.org; Tue, 29 Mar 2022 06:32:18 -0400 Received: from seau.ir5.eu (lfbn-idf1-1-2296-111.w92-151.abo.wanadoo.fr [92.151.91.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx.libregerbil.fr (Postfix) with ESMTPSA id 4KSQqK4MrTz33Hv for ; Tue, 29 Mar 2022 12:32:12 +0200 (CEST) From: Pierre-Louis Bonicoli To: grub-devel@gnu.org Subject: [PATCH v2 3/3] grub-core/kern/disk.c: handle LUKS2 devices Date: Tue, 29 Mar 2022 12:31:58 +0200 Message-Id: <20220329103158.4096409-4-pierre-louis.bonicoli@libregerbil.fr> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220329103158.4096409-1-pierre-louis.bonicoli@libregerbil.fr> References: <20220329103158.4096409-1-pierre-louis.bonicoli@libregerbil.fr> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=195.154.177.100; envelope-from=pierre-louis.bonicoli@libregerbil.fr; helo=mx.libregerbil.fr X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 29 Mar 2022 10:32:18 -0000 Unlike LUKS1, the sector size of LUKS2 devices isn't hardcoded. Regarding the probe command, the following values of --target switch are affected: abstraction, arc_hints, baremetal_hints, bios_hints, cryptodisk_uuid, drive, efi_hints, hints_string, ieee1275_hints, zero_check. For example using the --target=drive option: # dd if=/dev/zero of=data count=10 bs=1M # losetup --show -f data /dev/loop4 # echo -n pass | cryptsetup luksFormat -v --type luks2 /dev/loop4 Key slot 0 created. Command successful. # echo -n pass | cryptsetup -v open /dev/loop4 test No usable token is available. Key slot 0 unlocked. Command successful. # grub-probe --device /dev/mapper/test --target=cryptodisk_uuid grub-probe: error: disk `cryptouuid/f353c0f04a6a4c08bc53a0896130910f' not found. The updated output: # grub-probe --device /dev/mapper/test --target=cryptodisk_uuid f353c0f04a6a4c08bc53a0896130910f --- grub-core/kern/disk.c | 4 +++- grub-core/osdep/devmapper/getroot.c | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/grub-core/kern/disk.c b/grub-core/kern/disk.c index 3a42c007b..fa3177bf0 100644 --- a/grub-core/kern/disk.c +++ b/grub-core/kern/disk.c @@ -237,8 +237,10 @@ grub_disk_open (const char *name) name); goto fail; } - if (disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS + if ((disk->log_sector_size > GRUB_DISK_CACHE_BITS + GRUB_DISK_SECTOR_BITS || disk->log_sector_size < GRUB_DISK_SECTOR_BITS) + /* log_sector_size is unset for LUKS2 and that's ok */ + && !(disk->log_sector_size == 0 && dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID)) { grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, "sector sizes of %d bytes aren't supported yet", diff --git a/grub-core/osdep/devmapper/getroot.c b/grub-core/osdep/devmapper/getroot.c index 96781714c..4f51c113c 100644 --- a/grub-core/osdep/devmapper/getroot.c +++ b/grub-core/osdep/devmapper/getroot.c @@ -180,7 +180,8 @@ grub_util_pull_devmapper (const char *os_dev) grub_util_pull_device (subdev); } } - if (uuid && strncmp (uuid, "CRYPT-LUKS1-", sizeof ("CRYPT-LUKS1-") - 1) == 0 + if (uuid && (strncmp (uuid, "CRYPT-LUKS1-", sizeof ("CRYPT-LUKS1-") - 1) == 0 + || strncmp (uuid, "CRYPT-LUKS2-", sizeof ("CRYPT-LUKS2-") - 1) == 0) && lastsubdev) { char *grdev = grub_util_get_grub_dev (lastsubdev); -- 2.35.1