From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1klEeO-0007kE-Oz for mharc-grub-devel@gnu.org; Fri, 04 Dec 2020 12:13:55 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klEcg-0007T5-1E for grub-devel@gnu.org; Fri, 04 Dec 2020 12:11:58 -0500 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:40493) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1klEbJ-0006ia-HX for grub-devel@gnu.org; Fri, 04 Dec 2020 12:11:48 -0500 Received: by mail-pf1-x443.google.com with SMTP id t7so4148306pfh.7 for ; Fri, 04 Dec 2020 09:10:06 -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=Ojlf44hi9177jMzCmmDUKtGG/tDFUMa56P31mXXtWIs=; b=L+HCWsgChpT0S2sg1Njgqfo2ktIVP9dBn3DZ6UwoS91d3DhgFpHZtyI5MzYPvbgeBL 3/h7vW/EmYaM0eH3qzNaY5QtS+3P4EY5vUgB0iFfiLcF43+3CSj1X2otAmISRoSdprkS 0c0mf5/MVs+iVAkTwB4bQrAvKawqq3FrUvfD0rbThmRgvgrzCI4wBD5D+QliKbNLMWzc rR/JUqyVywl8acy0rqbtpxgPQ9gnlgYNuLtuJygBqWUfcOgr82Au+oKCv3w8b52Gm5n6 66gasEVGcCTRUY7qutwwZ2Xg0XNvxEHWeR24vF5SkTSqGHW+ghxfMp5U7qg4XzCK9H8r CNvg== 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=Ojlf44hi9177jMzCmmDUKtGG/tDFUMa56P31mXXtWIs=; b=KGViljuhriLMEUIxAnppz7bgMqHLrLlAw5uGduEHp4rJwp+OmTufxbXZwXAz9Hjsth an9S8ioAGzeNqeE2KhIMCVXYJFtfbtz0OAtEPcs3J81oQx1C+7vXj1iMgDJtsMxMo1/L VvDBTJ3qSOfG8G6eUi/ngsB+5dDWuuc5uZpRwaoQCUn0x3uwWHMbOBgCMxGXg0IjSaMj zDrje1V8R2d0yCRHi7alOi6YfCnHJMOczAoboO+khNwvlfznvGVOgVqrgK0+hIUrekGR oqcNyusiUD6FvEn/R+eQDWRSs6mHJyXuxp2u8xT6Qk9jU8B5CvyNjB0pKgcrmZCVUOKl RP7g== X-Gm-Message-State: AOAM530eYOWwV91KBbenlR8pwgRVNCQsOyXRmCbbDuZei8V6OYCVJ2Mr P7RmhzvPmE1+tyNpJX8c1u2R3vNLS80tAQ== X-Google-Smtp-Source: ABdhPJzLBjlbXaHRyxE6F3VGNeaQeyVbDP8lww/np+9nTbI65cEFN/c/RZ/9Hag7VZPvfOv4ZRMVwA== X-Received: by 2002:a92:9509:: with SMTP id y9mr7405294ilh.103.1607100264230; Fri, 04 Dec 2020 08:44:24 -0800 (PST) Received: from localhost.localdomain ([136.49.211.192]) by smtp.gmail.com with ESMTPSA id w3sm1754909iol.9.2020.12.04.08.44.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 08:44:23 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn , Daniel Kiper Subject: [PATCH v7 10/17] luks2: grub_cryptodisk_t->total_sectors is the max number of device native sectors Date: Fri, 4 Dec 2020 10:43:39 -0600 Message-Id: <7e8f242d12ba35fb70656e8f44650726e69143f8.1607098915.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::443; envelope-from=development@efficientek.com; helo=mail-pf1-x443.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=unavailable 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, 04 Dec 2020 17:11:59 -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. Also, removed an empty statement. Reviewed-by: Daniel Kiper 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 4be40b22b..bdf40768b 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -429,7 +429,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; @@ -615,9 +615,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