From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kbG90-0000oU-MD for mharc-grub-devel@gnu.org; Fri, 06 Nov 2020 23:48:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbG8z-0000kp-1z for grub-devel@gnu.org; Fri, 06 Nov 2020 23:48:05 -0500 Received: from mail-ot1-x344.google.com ([2607:f8b0:4864:20::344]:39675) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbG8x-0002wl-AM for grub-devel@gnu.org; Fri, 06 Nov 2020 23:48:04 -0500 Received: by mail-ot1-x344.google.com with SMTP id z16so3329674otq.6 for ; Fri, 06 Nov 2020 20:48:02 -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=GbxxKXC/k4iOsIAiXZ8QbZCLEFqmQiaUlDW07YZ87CM=; b=Niomyl/vXt21l54iXo0z2zm312AVlFOgEKXP2Oxgz+Kk3iUw+L1fbaftYBFAvLhkHE J/f+rKOdKAjs06zDj/hqkwsXmSlKU5L5U7FyeBWQZIbgesbXssweKfwuR23381Eq6z2X zpHxabZo14MkxQyMV3OS8n+Lv9UUEOBlrYp9wvCOKx0qr0aYzvq1gr+ub8aWoDgIzYoC s59V+HpKF8LrwpaJu1Lew5lKoainSAIPuRYM7Sj+rjF+aTcLcNkxjfpMUfhVJxXt72ze g4UuuT63IvE05XsCb2RoXstIqaX7RgMmyFRr5IBqPiDaQ1V5ultP7YsDi8j3Q4DL5Yy3 fOuQ== 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=GbxxKXC/k4iOsIAiXZ8QbZCLEFqmQiaUlDW07YZ87CM=; b=p1khSet2p+4+5QF1UsTbRR56MW1t4fjRsOVy/Gaa0Zmq+0O6d8mPBLnRX+HpncEj6P FqhqHsyA6x3BjwgwyujSSGo3Eqi0SKKpTt3kA8YrKecP4FnLtCYQF2QPpBhA9TeQpq5A LruCVS57P4/MerCnI1SPyfJZ2mueBS+P77bVwLptXbCxRQTnNZw89mU25k99IEjT5oWf OyDHkzwLkxGvImALfqAhU+I+H2W3oZN9HNEqQtcOLGvmkuGBYRzg9bQLeW+OTDGfhHWP gRgbEtlr1Gu1H9MWSfXKaSr71EUDA5YX2pRn7e4CRLmpjHZGXnuqK7wPWyTA9CGlqyf5 lfUg== X-Gm-Message-State: AOAM532YjJ0lXDnxT3tJf4KHgMenBotcHVJGxxlVNLTLFTVWH0pUz4ui ArqdiSgqGhQymitAPE5dCKeLcqLPtGsKdgiS X-Google-Smtp-Source: ABdhPJxEKqe3psFrewV+7Kqu1NkUagdInGL631cxs1tfoMtoPjhwnbFgIc6YLYtSfGJIDVvp5+rdSA== X-Received: by 2002:a05:6830:113:: with SMTP id i19mr3138301otp.372.1604724482040; Fri, 06 Nov 2020 20:48:02 -0800 (PST) Received: from localhost.localdomain ([136.49.44.103]) by smtp.gmail.com with ESMTPSA id x25sm836888oie.17.2020.11.06.20.47.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2020 20:48:01 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org Cc: Patrick Steinhardt , Daniel Kiper , Glenn Washburn Subject: [PATCH v4 12/15] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Date: Fri, 6 Nov 2020 22:44:32 -0600 Message-Id: <1bc8c867c40610ac6e7c33622cc89396941da4b6.1604723348.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::344; envelope-from=development@efficientek.com; helo=mail-ot1-x344.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: Sat, 07 Nov 2020 04:48:05 -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 ca830d73b..355bb4aec 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