From ab295b1159cd8f2df860d54f82c793312af4d7f2 Mon Sep 17 00:00:00 2001 From: Ondrej Kozina Date: Thu, 26 Aug 2021 15:47:41 +0200 Subject: [PATCH] Do not resume device when not suspended. Abort action luksResume early if device is not suspended. We would needlesly ask for passphrase or load cryptsetup plugins only to fail later in crypt_resume_by_* API. --- src/cryptsetup.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cryptsetup.c b/src/cryptsetup.c index edbb1881..de4439d8 100644 --- a/src/cryptsetup.c +++ b/src/cryptsetup.c @@ -2189,6 +2189,7 @@ static int action_luksResume(void) char *password = NULL; size_t passwordLen; int r, tries; + struct crypt_active_device cad; const char *req_type = luksType(device_type); if (req_type && !isLUKS(req_type)) @@ -2208,6 +2209,16 @@ static int action_luksResume(void) goto out; } + r = crypt_get_active_device(cd, action_argv[0], &cad); + if (r < 0) + goto out; + + if (!(cad.flags & CRYPT_ACTIVATE_SUSPENDED)) { + log_err(_("Volume %s is not suspended."), action_argv[0]); + r = -EINVAL; + goto out; + } + /* try to resume LUKS2 device by token first */ r = crypt_resume_by_token_pin(cd, action_argv[0], ARG_STR(OPT_TOKEN_TYPE_ID), ARG_INT32(OPT_TOKEN_ID_ID), NULL, 0, NULL);