From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kh4Kp-0008Ip-V5 for mharc-grub-devel@gnu.org; Mon, 23 Nov 2020 00:24:19 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:40594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kh4Kj-0008FI-L5 for grub-devel@gnu.org; Mon, 23 Nov 2020 00:24:13 -0500 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:38418) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kh4Kg-0006Vm-GZ for grub-devel@gnu.org; Mon, 23 Nov 2020 00:24:11 -0500 Received: by mail-wr1-x444.google.com with SMTP id p8so17338946wrx.5 for ; Sun, 22 Nov 2020 21:24:10 -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=SIFuIAQfa9sg1BW9M8qWHSvuQcPK3aup5QTh6ZjeIpg=; b=WXqlcxl13bixxIehEE5/XeEDtPicz9lUW3cpZp82CwgpPNWSszuwzzoiGC4mT+9ews pfhJgV+HyhZ4Ge7jGRvcxDUEYpoiJzclEmKwT+oQ9+8NX0xMDiv1j/wBuCwQiHAR9Xtn AamTxyjOWFWquv7kmIgz6QhAR/2fGwnHPSUwXuGfqU7PNUoT47EbEqDorEBw0WRt+Iod sp9woPBVvzEvHTgIKwETTdRu8XDxTedcK/kRVVcg9JU0/Q8D3bCytbM0nUydEW6rngnl X9oGM0y8xnj21eNxab91UC+LDMPFv+jiWWE7GbOUO1VTFbAzHNuBLQWIH7fKxkxuX1Sl sDOg== 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=SIFuIAQfa9sg1BW9M8qWHSvuQcPK3aup5QTh6ZjeIpg=; b=CsyzH7iOFIaiai7bxB9QJKnD5mO+7Kl0u7lqR0oD1OUdknfrFBEAkZeCyMq0K6T/CV FZqr9fia3PF3UUgoxoNwdO8rtkK7PiRj9VqY5sankYmKfnVJMYbZUpq/1Sc9aD44HEgf I8QXqdjZ1EQY77m8cOTPqFbjSWEP5ZL3I/IjurQPp3rKolwBsx9JTtHhe5qiPUT/G/vL nMpPdP6zYmeR8bDs087KaozHAIEaoy87ZaQtSJEfqgocRsKlFfX28RhyZg1/8SVcE4Km LKVDEB+8/JRuw55k017JD5ErJ4GWaQNnc7l2w/Gned+I0eUhWYz0HXZC3fLh/rOSoFvd PToA== X-Gm-Message-State: AOAM5327Z+7YuPGb+iLO9vqBhXPD6NaFSKc1Id0Mw7hJ4RlXDdUjBh04 zO4B1mlMcZ3VB/zNSqAnoCbal/oTzvSR1w== X-Google-Smtp-Source: ABdhPJz82I3u63/5FFQGCqFkDxDZd414KOHnWVvM/LSvN0PlNEyqtellcNwCRBe8EYRDiSN7fU4xow== X-Received: by 2002:adf:e5cb:: with SMTP id a11mr28596780wrn.15.1606109049019; Sun, 22 Nov 2020 21:24:09 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id f16sm11631780wmh.7.2020.11.22.21.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2020 21:24:08 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v5 04/11] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors Date: Sun, 22 Nov 2020 23:23:17 -0600 Message-Id: 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::444; envelope-from=development@efficientek.com; helo=mail-wr1-x444.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: Mon, 23 Nov 2020 05:24:13 -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 c390ea3e6..e33df9803 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