From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kiZgG-0004qv-Oe for mharc-grub-devel@gnu.org; Fri, 27 Nov 2020 04:04:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:32938) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kiZgE-0004nh-6M for grub-devel@gnu.org; Fri, 27 Nov 2020 04:04:38 -0500 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]:40372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kiZgC-0005Tf-IH for grub-devel@gnu.org; Fri, 27 Nov 2020 04:04:37 -0500 Received: by mail-lj1-x244.google.com with SMTP id y10so5129307ljc.7 for ; Fri, 27 Nov 2020 01:04:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JHcYEuZnOouBaVyUYiocsaf4O/jlMaPAyrnwDerUWvg=; b=o6fzbSO6j7a+EeQIf+4FhEGP9bICnH1ArIr1ownxRrAe0/WXWesZckBFoaAx3eSkC2 Q5AkTIdYYbD+PVXPZeU3+cNMsgyt8vSBuuoslTBMt4LF/AXIKYJ4Z4EVQUzmqxCjCYgW bWronNL4YKW8D4THFeqoYQlwXO5vGx5MsIqwnASwNaqrWG7y5XiudOWAI8tayvAgXRJ/ NuX9NAydin1/cTHjLnDmayCUTgzPsoTNXtouW5RLARb9LtnUYKLI0cLPUqN26I79FkdI UtPpcP9z/4XyTvah99FZNZE0eRJXgi395Qc2M/+nxNhEVLYMMUW/sPaHWjT7wSEFg8L6 EUNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JHcYEuZnOouBaVyUYiocsaf4O/jlMaPAyrnwDerUWvg=; b=aGlsPa7IJjn23B8YwEcE4xqF8nMhgeyGe+bSPY/mzKBB+wVSqis4ZfFiDKJ8vYCDs5 3xA/gWPiGlwIsy6XccANFRbpl69nf1tf6LKANf3sR+8EevEqruKxCRcSqda/0qFpz82M 8lke431TMk/ppGHKbJ4IoM4KnIsLWOGKxHz5/cfjFo9boVtCZn+bGII8yn7KiAp7TF7T tSa2+d5nOHJ6KIyKWOKVBEUt0NFWpeUK5ATAv7leZjQ6ULgkgRgTgYchZdIn/v6dJO0Y CMBbdcQku5NQnENzV9kg5oUkqyBWMk+BCeqIH3ScEpW2qiTfPM6N1IexbdruJXm+4oLn iDsw== X-Gm-Message-State: AOAM530Hla/Ds6My0zrM+aGFCf0iIjH7T6PCxBGyQ+oAcWTyLTVDOxIi X6ibbB4vUTBnvAJdKpN7EUEHEckunwhEBg== X-Google-Smtp-Source: ABdhPJzqP3qrfiNjHi2nqT7XaEd1aK43XuBIu5pxVPvDfRSiw6dUOKoYlc4Zwry6mJyRQuk+QwQ18g== X-Received: by 2002:a2e:7407:: with SMTP id p7mr2837436ljc.430.1606467874719; Fri, 27 Nov 2020 01:04:34 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id g2sm880675lja.87.2020.11.27.01.04.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Nov 2020 01:04:34 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v6 05/12] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors Date: Fri, 27 Nov 2020 03:03:37 -0600 Message-Id: <45f5d644f4ba7ce635c49528aac7282acbe74081.1606467382.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=2a00:1450:4864:20::244; envelope-from=development@efficientek.com; helo=mail-lj1-x244.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: Fri, 27 Nov 2020 09:04:38 -0000 We need to convert the sectors from the size of the underlying device to the cryptodisk sector size; segment.size is in bytes which need to be converted to cryptodisk sectors as well. And counter-intuitively, grub_disk_get_size returns the total number of device native sectors. Also, removed an empty statement. Signed-off-by: Glenn Washburn --- grub-core/disk/luks2.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c index 619e57aad..0c814bd7c 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -426,7 +426,7 @@ luks2_decrypt_key (grub_uint8_t *out_key, grub_uint8_t salt[GRUB_CRYPTODISK_MAX_KEYLEN]; grub_uint8_t *split_key = NULL; grub_size_t saltlen = sizeof (salt); - char cipher[32], *p;; + char cipher[32], *p; const gcry_md_spec_t *hash; gcry_err_code_t gcry_ret; grub_err_t ret; @@ -612,9 +612,10 @@ luks2_recover_key (grub_disk_t source, crypt->log_sector_size = sizeof (unsigned int) * 8 - __builtin_clz ((unsigned int) segment.sector_size) - 1; if (grub_strcmp (segment.size, "dynamic") == 0) - crypt->total_sectors = grub_disk_get_size (source) - crypt->offset_sectors; + crypt->total_sectors = (grub_disk_get_size (source) >> (crypt->log_sector_size - source->log_sector_size)) + - crypt->offset_sectors; else - crypt->total_sectors = grub_strtoull (segment.size, NULL, 10); + crypt->total_sectors = grub_strtoull (segment.size, NULL, 10) >> crypt->log_sector_size; ret = luks2_decrypt_key (candidate_key, source, crypt, &keyslot, (const grub_uint8_t *) passphrase, grub_strlen (passphrase)); -- 2.27.0