From 5af39ac850844511f673ce573efa0cf84b6589a7 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Jun 2020 14:18:09 +0200 Subject: [PATCH 1/2] cryptsetup: try to load bitlocker superblock only if requested let's do automatic discovery only for our native LUKS/LUKS2 headers, since they are Linux stuff, and let's require that BitLocker to be requested explicitly. This makes sure cryptsetup without either "luks" nor "bitlk" in the option string will work. Right now it would fail because we'd load the superblock once with luks and once with bitlk and one of them would necessarily fail. Follow-up for #15979 --- src/cryptsetup/cryptsetup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index c05e2d1351..a8d72fcf5a 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -957,7 +957,7 @@ static int run(int argc, char *argv[]) { /* since cryptsetup 2.3.0 (Feb 2020) */ #ifdef CRYPT_BITLK - if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_BITLK)) { + if (streq_ptr(arg_type, CRYPT_BITLK)) { r = crypt_load(cd, CRYPT_BITLK, NULL); if (r < 0) return log_error_errno(r, "Failed to load Bitlocker superblock on device %s: %m", crypt_get_device_name(cd)); From 6930d069a37a3b770c4e825fa8d7c937ec608e50 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 9 Jun 2020 14:21:32 +0200 Subject: [PATCH 2/2] cryptsetup: pass selected mode to crypt_load() when doing LUKS This doesn't fix anything IRL, but is a bit cleaner, since it makes sure that arg_type is properly passed to crypt_load() in all cases. We actually never set arg_type to CRYPT_LUKS2, which is why this wasn't noticed before, but theoretically this might change one day, and existing comments suggest it as possible value for arg_type, hence let's process it properly. --- src/cryptsetup/cryptsetup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index a8d72fcf5a..6d3f842dbe 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -932,8 +932,8 @@ static int run(int argc, char *argv[]) { log_warning("Key file %s is world-readable. This is not a good idea!", key_file); } - if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_LUKS1)) { - r = crypt_load(cd, CRYPT_LUKS, NULL); + if (!arg_type || STR_IN_SET(arg_type, ANY_LUKS, CRYPT_LUKS1, CRYPT_LUKS2)) { + r = crypt_load(cd, !arg_type || streq(arg_type, ANY_LUKS) ? CRYPT_LUKS : arg_type, NULL); if (r < 0) return log_error_errno(r, "Failed to load LUKS superblock on device %s: %m", crypt_get_device_name(cd));