From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kUeKg-0000fT-VD for mharc-grub-devel@gnu.org; Mon, 19 Oct 2020 19:12:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40740) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUeKd-0000XA-3r for grub-devel@gnu.org; Mon, 19 Oct 2020 19:12:47 -0400 Received: from mail-oi1-x243.google.com ([2607:f8b0:4864:20::243]:46491) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kUeKT-0007Uh-36 for grub-devel@gnu.org; Mon, 19 Oct 2020 19:12:46 -0400 Received: by mail-oi1-x243.google.com with SMTP id l4so1899595oii.13 for ; Mon, 19 Oct 2020 16:12:36 -0700 (PDT) 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=mRUZPp+PI38AE6IHapn+xNyapPGVm0vorPKZYa5Z7hI=; b=dHIDixZ1JLpCaX0BRGS33nNGjpizGoSH2q8LNU//LTfZg5j5IdW4ll76UI3UrZm1sy vjQtEXJAQDAmujdPnVXtrbcdTupdOPA86wQUW10zBxbqfhi0wLLaqHxTM3dj0gzKPEbg 1P/ssgbU5ZlM/tD5SJYKbCYL5I5F+3KdnLO45JwwuY6rTQsK3kqV3gYUh2Nf52dzUBI5 K9vo7s/jFRfmFBqnxuvC93es8a3w7y/tMZH45sb7tzPGJi3kf7xib6MmYBzAEA7TR53D G5VZb6invVq7eKEv3uS+/iQYSQVZV/wCsq50UUgxXww2hLwEm0ZrvkuEWxXRVGgC5LVg RV3g== 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=mRUZPp+PI38AE6IHapn+xNyapPGVm0vorPKZYa5Z7hI=; b=ip4VH+Ya8dMKoLbnBxMF0Tf4fu4Tbzb/QEn5wZBTGmzKLas36ddjP28lA7Fah9srks KAl4ZsePdWZkQDga6x6rK1yxZvOCc/GyROO9H3FtUWCSLAmPUFtw4CA2scJwvxgivPgH wLDo/zKXZ+uAp1COJVIoJXD5SJ2tuoBi1e09K1t668G1rB1/HmvmskRHeUtBASCj/tUh wVMzq8B64DhJ/bClDoCTuUOPyZrxYrTZ10ahK+71sm4DRtgfUH8D2aZ6y48vulSDvByR eAZIKBDaFH5ICw0J0iVpiwZKFNKU327OtsrxLy2MQYBHUKvMbMxPnAUbkgrQqcQZa9hE K1kg== X-Gm-Message-State: AOAM532jXKcfThAzr2c/lXd+hXPRyS7GSReDhjd6zfv3wPzjrnmuzPW5 M5ohUYXJo+H74gAUuuRpLnzsqUoZEaPYPg== X-Google-Smtp-Source: ABdhPJyPtpI3I5Ms+tO16QeQyfx1c8sd3yC/rw3xfvP7LGgh33z1Uf37PQ30BC0yEFxv/a726ouB9g== X-Received: by 2002:a05:6808:91a:: with SMTP id w26mr92285oih.159.1603149155583; Mon, 19 Oct 2020 16:12:35 -0700 (PDT) Received: from localhost.localdomain (47-218-232-180.bcstcmtk03.res.dyn.suddenlink.net. [47.218.232.180]) by smtp.gmail.com with ESMTPSA id d27sm310848otc.6.2020.10.19.16.12.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Oct 2020 16:12:34 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v3 04/10] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Date: Mon, 19 Oct 2020 18:09:52 -0500 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: <20201009100122.GH2088@tanuki> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::243; envelope-from=development@efficientek.com; helo=mail-oi1-x243.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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, 19 Oct 2020 23:12:47 -0000 The total_length field is named confusingly because length usually refers to bytes, whereas in this case its really the total number of sectors on the device. Also counter-intuitively, grub_disk_get_size returns the total number of device native sectors. We need to convert the sectors from the size of the underlying device to the cryptodisk sector size. And segment.size is in bytes which need to be converted to cryptodisk 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 4e1e47161..311d18684 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -425,7 +425,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; @@ -611,9 +611,10 @@ luks2_recover_key (grub_disk_t disk, 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_length = grub_disk_get_size (disk) - crypt->offset; + crypt->total_length = (grub_disk_get_size (disk) >> (crypt->log_sector_size - disk->log_sector_size)) + - crypt->offset; else - crypt->total_length = grub_strtoull (segment.size, NULL, 10); + crypt->total_length = grub_strtoull (segment.size, NULL, 10) >> crypt->log_sector_size; ret = luks2_decrypt_key (candidate_key, disk, crypt, &keyslot, (const grub_uint8_t *) passphrase, grub_strlen (passphrase)); -- 2.27.0