From 8e8ecd50de790b8cb84b27b20f8a97783e3bb3a4 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Tue, 23 Feb 2021 20:46:56 +0100 Subject: [PATCH] Fix luksResume when called on non-LUKS device. --- lib/setup.c | 2 +- src/cryptsetup.c | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/setup.c b/lib/setup.c index 3dbd2854..021b9d27 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -1200,7 +1200,7 @@ static int _init_by_name_crypt(struct crypt_device *cd, const char *name) } /* do not try to lookup LUKS2 header in detached header mode */ - if (!cd->metadata_device && !found) { + if (dmd.uuid && !cd->metadata_device && !found) { while (*dep && !found) { r = dm_query_device(cd, *dep, DM_ACTIVE_DEVICE, &dmdep); if (r < 0) diff --git a/src/cryptsetup.c b/src/cryptsetup.c index b326c4b5..2e26ac73 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -2247,12 +2247,24 @@ static int action_luksResume(void) char *password = NULL; size_t passwordLen; int r, tries; + const char *req_type = luksType(device_type); + + if (req_type && !isLUKS(req_type)) + return -EINVAL; if ((r = crypt_init_by_name_and_header(&cd, action_argv[0], uuid_or_device(ARG_STR(OPT_HEADER_ID))))) - goto out; + return r; - if ((r = crypt_load(cd, luksType(device_type), NULL))) + r = -EINVAL; + if (!isLUKS(crypt_get_type(cd))) { + log_err(_("%s is not active LUKS device name or header is missing."), action_argv[0]); goto out; + } + + if (req_type && strcmp(req_type, crypt_get_type(cd))) { + log_err(_("%s is not active %s device name."), action_argv[0], req_type); + goto out; + } tries = _set_tries_tty(); do {