From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kOpMz-0003XM-6z for mharc-grub-devel@gnu.org; Sat, 03 Oct 2020 17:47:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOpMt-0003S1-Rl for grub-devel@gnu.org; Sat, 03 Oct 2020 17:47:03 -0400 Received: from mail-oo1-xc42.google.com ([2607:f8b0:4864:20::c42]:36445) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOpMr-0002K0-Ug for grub-devel@gnu.org; Sat, 03 Oct 2020 17:47:03 -0400 Received: by mail-oo1-xc42.google.com with SMTP id z1so1301917ooj.3 for ; Sat, 03 Oct 2020 14:47:01 -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=+rBFdPdMc8pe8IYjGU+MEenTkNlYBGCGJ8+1y1xGWyQ=; b=qsv6bKGEu+NcbWgtB+GgzRauWOmz9l7pjb0E0Bfbx48g/5hNFDaQN4q8OIy7mPXbhZ AElwH4eYFTRbrtwcFc+10JozqtS7HVt7nm1wjWNWGeEA0Y8yoo0QuifcQEFxZzZ0xuqa JMDeKOiaGu0xRBdp8lbYcoWh5XjXUyNK6QctY3dIF8IPtM8JYxnQb6DNG0vcswR50f2w HX/PLYaxXHBzgq8fHva6nD9GBPgKM5/9BaOX7FFi+kFKpEg4HT+qyidQfzONy/3o0n/e 4eP8ss9QzEgdtekfP/LfN/U9mBebsfCMrC2877pFXMhZR5Cx+7KMhV3r3G9PWEhOAILC pUXg== 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=+rBFdPdMc8pe8IYjGU+MEenTkNlYBGCGJ8+1y1xGWyQ=; b=R0iK06duSq4TPoXGbHhVPBrGbE4l9xW0ZQl53kitV5PBit0fLP2QhkpYYK0Kf+sIN6 /MDETpk4Mz5goVo395/i7hzxa8UdtFxrZK3Dd4Hbi/6xRdrf+Fv+mVGaU5YuF1XjxHe7 UkzcUWYNiIXbsDhS94LnMJbXf2fsk7B9xOm69lW9Ym4WBahX/uZHQfO58Uoh3Deccwux IJq65HM6upu2F3CcTsIJKjYPN4Exmkcv30fakfxkXc98m4agnTe9jRaauN3C/gE1ScHB 0+pVoKF1UbVAB/JKj52XaTLtxgQningk2K/zYxSS9PDElwJvp2MjVq2mECR3OY5HB9eq 5w2w== X-Gm-Message-State: AOAM530U5kWAKLV2OntjzadE0qCl3g2zCn23Q+zzLam29Q9HV6nunxSB IF/TKEkhUU4dar2WRHLkAGR/PDqx7r/vcA== X-Google-Smtp-Source: ABdhPJwUch8Qe9OdOQKp9GjYEEowrhW1rNCtEPNHX8pTPXt2q9Ir7VUQAzJkk6YWWicglqelQyS2ag== X-Received: by 2002:a4a:d38c:: with SMTP id i12mr6809641oos.81.1601761620652; Sat, 03 Oct 2020 14:47:00 -0700 (PDT) Received: from crass-HP-ZBook-15-G2.lan ([136.49.44.103]) by smtp.gmail.com with ESMTPSA id f26sm1495415otq.50.2020.10.03.14.47.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Oct 2020 14:47:00 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Patrick Steinhardt , Glenn Washburn Subject: [PATCH 04/10] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Date: Sat, 3 Oct 2020 16:45:57 -0500 Message-Id: <137909929a3d158f11dc8441762bfe2cf9641fa7.1601760922.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::c42; envelope-from=development@efficientek.com; helo=mail-oo1-xc42.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, 03 Oct 2020 21:47:04 -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 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 7917e02cd..8e99a1820 100644 --- a/grub-core/disk/luks2.c +++ b/grub-core/disk/luks2.c @@ -424,7 +424,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