From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1kOqRo-0007ag-Sj for mharc-grub-devel@gnu.org; Sat, 03 Oct 2020 18:56:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kOqRj-0007Xd-EM for grub-devel@gnu.org; Sat, 03 Oct 2020 18:56:07 -0400 Received: from mail-oo1-xc41.google.com ([2607:f8b0:4864:20::c41]:42442) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kOqRh-0000FN-NI for grub-devel@gnu.org; Sat, 03 Oct 2020 18:56:07 -0400 Received: by mail-oo1-xc41.google.com with SMTP id l18so202796ooa.9 for ; Sat, 03 Oct 2020 15:56:05 -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=TzuVKZ6cAJrxqO1Q57VAC8MoqyMn5yATAz8NQ/ewZQs=; b=DnZojAXC43/8TswGN6FpqjnZxMCf2tbtGadowLGJyOPjLbY3f2fcENQYwHuI4t+QWD kh4HXtk/gGVbK6PqCKz+AvPK0cyPhs4kkyovTKvuzmv5Il/4n49Ndn0avBaO+stsW10z mCtgd3afPU63w2YXnxz2T7OHa+h59yZBxo1SXCu/HWcdwIsI6oeXlmzZqg+DvDl87P0V w8jPFpT3qH+1XDJlRyjsZmLE+29+KyQzIBnwVxfLQ9p2S6c+8ZS5Sa6nsUgxup0FRth+ CnjgmdCY2moP07BKjfSJUeq8n11rgkEgz1ojot1bDkOYe6Gy448datoo31O3SvdUhSHH lbPA== 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=TzuVKZ6cAJrxqO1Q57VAC8MoqyMn5yATAz8NQ/ewZQs=; b=mqDkV9khBo6FV8iFqKK9eZRh2KuoBsoZ0L62ysJcGT3uUdz6whXDsyP6QW24I9ZKrs Dk4m5B5YRBiR4rEtXfYWH6dsFISuOIVHacznvYcU3LW0mLOX4jJkeAlDqIXUTumj5ma1 TuI7XhLh7vKCokeVIeCNhxoIDGQuTX6wyfJdYudp5zVYczT5YEuJmfT/bUKn07Fc96Yu Nds+oTOkPx79pplFiBF58SZ16CHRX9HItDjOXacIPw5pWMhgyBO/vpBM/h79MBDItX2E pXKzOL8KVt1QhRusqteqbURwrv48jWfqCfVqZ/6xBx0Q3tTus/Te+BHYwjIjdaWX9ACs YroQ== X-Gm-Message-State: AOAM5302mvkziFYOntVot17CRSF3F9RyZcOsoUQPAAUJk7RRzOTTpocv KywzNffQMyl8ios9AsGCSptrmxm8bTFCww== X-Google-Smtp-Source: ABdhPJziKgKuvP+hJVp+CNcSBDDLZet9qRjvHK/33s6cBCnuVwtUFmCZO0W/DLX64ndiaGlbex0cCQ== X-Received: by 2002:a4a:c3ca:: with SMTP id e10mr242449ooq.41.1601765764407; Sat, 03 Oct 2020 15:56:04 -0700 (PDT) Received: from crass-HP-ZBook-15-G2.lan ([136.49.44.103]) by smtp.gmail.com with ESMTPSA id d17sm1524580oth.73.2020.10.03.15.56.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Oct 2020 15:56:04 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org Cc: Daniel Kiper , Patrick Steinhardt , Glenn Washburn Subject: [PATCH v2 04/10] luks2: grub_cryptodisk_t->total_length is the max number of device native sectors Date: Sat, 3 Oct 2020 17:55:28 -0500 Message-Id: <3baffdd4f0abceb0cc513dbee0075617f342eadf.1601765266.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::c41; envelope-from=development@efficientek.com; helo=mail-oo1-xc41.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 22:56:07 -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 db251cce0..9f7d6e12b 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