Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1maRBH-00066d-KF for mharc-grub-devel@gnu.org; Tue, 12 Oct 2021 19:27:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1maRBD-00061G-S5 for grub-devel@gnu.org; Tue, 12 Oct 2021 19:27:31 -0400 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]:33653) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1maRBC-0005Eb-5n for grub-devel@gnu.org; Tue, 12 Oct 2021 19:27:31 -0400 Received: by mail-qk1-x72c.google.com with SMTP id l7so679927qkk.0 for ; Tue, 12 Oct 2021 16:27:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=YZ+qaybVw1dImrCXBdT8u19mJmvmCvVbKfLuYObiOiE=; b=AyKFr8z7PxJ3lbaiPPQISmth5FnI7H83cPKuZ2fvWIjLfLtt5yLM589IAQFTpumgwM 0gSPrI44xlhu7A7bBG/QojC3Z+NI31PnHpHg3Ttpr0daBltjkebxrVT/qsTUculZwYKT w6cvv9DrHJkkTGXVFZzM+Rr8ESB5JQy/8zvLkgxahu7O9ThSrjLUaJyKO0tkGExEq7cz xKtS8MZnmPUBYwcPn5RH4i+Ac/k1gfBiIISG0tcFtRxmPuAD6wBGIyE2wfwKpgUe01l3 eM7voF496scM4cCGuVAQYzip//qyOXGsD0THr56G1doe+cuATvoW+pLo4+vaoqDK8HhS dP4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YZ+qaybVw1dImrCXBdT8u19mJmvmCvVbKfLuYObiOiE=; b=DpmzA8gZuA6Pfp5/xmPbWvrWUVtLBHKmJn1aH6Gq0OpJJN7mxgIwWzr+yagF2Yo/Ls 4SRpoKPlnC0vCGAdemPiYXji+oQ8rusSx0zjGEIEGqdN5s+lKgG97/naV14jwHltjq9z ZBJ9JcuEC7Gpf7nXo9vLigCLE5fKmScfwGoldKp96a8uy5vOSUTIX1m8jwRhbyDJBwzx WSBUGJIAysZk732milDiUoD99650i3kJIk163lHdNGwh4Yc1Z951S+dqrDCPKHUOHH6m idE0kqetN0G8/eXtaIr6vpM03qRcc9ESyoDShurscpRXQDJyuIYHmWErf5iOzl6d5+dK rN+g== X-Gm-Message-State: AOAM533o8OP85B9WCFFdd6OXSEU2nB0sEyl4I64tstdwOx8xPPMURig9 9JL7aXAq3oguGtxM9r+gRawB3d9fVqyw6A== X-Google-Smtp-Source: ABdhPJyShKJX2tFTghmXUnwqPLuGggJudw/+znZ+wNftGqcOlcXNabgaucZ3MC3JFVSG4wXxqL0kMw== X-Received: by 2002:a37:9307:: with SMTP id v7mr21941107qkd.371.1634081249227; Tue, 12 Oct 2021 16:27:29 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id 33sm7121642qtc.18.2021.10.12.16.27.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Oct 2021 16:27:28 -0700 (PDT) From: Glenn Washburn To: Daniel Kiper , grub-devel@gnu.org Cc: Denis 'GNUtoo' Carikli , Patrick Steinhardt , James Bottomley , Glenn Washburn Subject: [PATCH v3 4/4] cryptodisk: Remove unneeded found_uuid from cryptomount args Date: Tue, 12 Oct 2021 18:26:29 -0500 Message-Id: <85470992977ad3ed88903e03f8c38b0ef9784106.1634081029.git.development@efficientek.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::72c; envelope-from=development@efficientek.com; helo=mail-qk1-x72c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Oct 2021 23:27:32 -0000 The member found_uuid was never used by the crypto-backends, but was used to determine if a crypto-backend successfully mounted a cryptodisk with a given uuid. This is not needed however, because grub_device_iterate will return 1 iff grub_cryptodisk_scan_device returns 1. And grub_cryptodisk_scan_device will only return 1 if a search_uuid has been specified and a cryptodisk was successfully setup by a crypto-backend. So the return value of grub_cryptodisk_scan_device is almost equivalent to found_uuid, with the exception of the case where a mount is requested or an already opened crypto device. With this change grub_device_iterate will return 1 when grub_cryptodisk_scan_device when a crypto device is successfully decrypted or when the source device has already been successfully opened. Prior to this change, trying to mount an already successfully opened device would trigger an error with the message "no such cryptodisk found", which is at best misleading. The mount should silently succeed in this case, which is what happens with this patch. Signed-off-by: Glenn Washburn --- grub-core/disk/cryptodisk.c | 9 ++++----- include/grub/cryptodisk.h | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 5b38606ed..8e5277314 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -1046,8 +1046,6 @@ grub_cryptodisk_scan_device_real (const char *name, grub_cryptodisk_insert (dev, name, source); - cargs->found_uuid = 1; - goto cleanup; } goto cleanup; @@ -1132,7 +1130,7 @@ grub_cryptodisk_scan_device (const char *name, if (err) grub_print_error (); - return (cargs->found_uuid && cargs->search_uuid) ? 1 : 0; + return (!err && cargs->search_uuid) ? 1 : 0; } static grub_err_t @@ -1152,6 +1150,7 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) if (state[0].set) /* uuid */ { + int found_uuid = 0; grub_cryptodisk_t dev; dev = grub_cryptodisk_get_by_uuid (args[0]); @@ -1164,9 +1163,9 @@ grub_cmd_cryptomount (grub_extcmd_context_t ctxt, int argc, char **args) cargs.check_boot = state[2].set; cargs.search_uuid = args[0]; - grub_device_iterate (&grub_cryptodisk_scan_device, &cargs); + found_uuid = grub_device_iterate (&grub_cryptodisk_scan_device, &cargs); - if (!cargs.found_uuid) + if (!found_uuid) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no such cryptodisk found"); return GRUB_ERR_NONE; } diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h index 2823fa80f..c6524c9ea 100644 --- a/include/grub/cryptodisk.h +++ b/include/grub/cryptodisk.h @@ -71,7 +71,6 @@ struct grub_cryptomount_args { /* scan: Flag to indicate that only bootable volumes should be decrypted */ grub_uint32_t check_boot : 1; - grub_uint32_t found_uuid : 1; /* scan: Only volumes matching this UUID should be decrpyted */ char *search_uuid; /* recover_key: Key data used to decrypt voume */ -- 2.27.0