From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pG6dj-0000xI-7l for mharc-grub-devel@gnu.org; Thu, 12 Jan 2023 18:05:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pG6da-0000vj-Hw for grub-devel@gnu.org; Thu, 12 Jan 2023 18:05:35 -0500 Received: from mail-yw1-x112a.google.com ([2607:f8b0:4864:20::112a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pG6dY-00054g-7G for grub-devel@gnu.org; Thu, 12 Jan 2023 18:05:33 -0500 Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-4d59d518505so92470687b3.1 for ; Thu, 12 Jan 2023 15:05:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=emzVMtUzUTHdgWddw+mdA11p5+sEb+SluhoQEjuGH/s=; b=YIKORFbMyJ6+wzdOIF/cdrvysWv+Dal/uo22a+DPxpwIDxhqdld/UpK73Eb62u9YJF NEzDhwekT52B4wJ1AsgEEg2gOcAslprYklNBT6JeicE7WUHhMYkPbKEfWKUn7kwaijMR raWM/8juLAT1o56jrR+RJVMubNKMQ7PPtIGiHdIlajx5JEosC3vY19V9f/T2QleP8ZIe tRJjoFKmbxNjePHWy/nEp6oMRN52B1f+SexOY240qNqNfTodqylM1KOLnBjqSzfysAXl 12S1ss9Sdi3OweiW/6mp+oO97M+TNxoptcasaUGiyvKXuvHvsW4E/tu2WOloBrwYFhns 5vqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=emzVMtUzUTHdgWddw+mdA11p5+sEb+SluhoQEjuGH/s=; b=g3Hh89zOXka1d45a3iHDWKGB5iQDgNRyn/yE5GpxGBJ87rHOq1CtrduA3uyDvj17pQ d2V7wQwrQvA7oasMIM3uG6eFjBHgYOlcd+f1vz4MFyZq1Y5VNUGIyOu85hnG32gFog+T 56UPAashQBRu9FLPgEO9jzQej++cxBipZT3pfMUf5kPe5K5mLFFJq11PRZVzf0XyE8pA nStIlX6f9n3lgk/O5uWwn80e1g8nO7M5xYgyREedUgtU+f4/DvHgROV8yTrAbUkRD2/z qQN8HtD1gr8rqePlFHlktrAHX+Zdax6PNzHNXiAZbRN3cAM+Z8yIINNfw0s9p8qKmFri iukg== X-Gm-Message-State: AFqh2kpppeFhsy1h6xlDa/SvtqdGuATUgsRbS8xkVnxq3xUNgzpDfwz9 yY30pNFpACeCQFHDa6kiy/ZNCL3pZsnlwxlt X-Google-Smtp-Source: AMrXdXupWAXeBqOfKcsPLCiaknfLy8HJ39XX8dbGPlnS9U0Idij5FB4Alzl6ymt2GB5dAIno/aeD1g== X-Received: by 2002:a81:be02:0:b0:4de:3bad:b77c with SMTP id i2-20020a81be02000000b004de3badb77cmr38199ywn.39.1673564730490; Thu, 12 Jan 2023 15:05:30 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id bq35-20020a05620a46a300b00704c9015e68sm11704446qkb.116.2023.01.12.15.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Jan 2023 15:05:29 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Patrick Steinhardt , Pierre-Louis Bonicoli , Josselin Poiret , Fabian Vogt , Glenn Washburn Subject: [PATCH 1/4] disk/cryptodisk: When cheatmounting, use the sector info of the cheat device Date: Thu, 12 Jan 2023 17:05:07 -0600 Message-Id: <20230112230510.1319896-2-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230112230510.1319896-1-development@efficientek.com> References: <20230112230510.1319896-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::112a; envelope-from=development@efficientek.com; helo=mail-yw1-x112a.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=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jan 2023 23:05:37 -0000 From: Fabian Vogt When using grub-probe with cryptodisk, the mapped block device from the host is used directly instead of decrypting the source device in GRUB code. In that case, the sector size and count of the host device needs to be used. This is especially important when using luks2, which does not assign total_sectors and log_sector_size when scanning, but only later when the segments in the JSON area are evaluated. With an unset log_sector_size, grub_open_device complains. This fixes grub-probe failing with "error: sector sizes of 1 bytes aren't supported yet." Signed-off-by: Fabian Vogt Reviewed-by: Patrick Steinhardt Tested-by: Glenn Washburn Reviewed-by: Glenn Washburn --- grub-core/disk/cryptodisk.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index 14308822aa..ed1769eabb 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -718,16 +718,31 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk) if (!dev) return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "No such device"); - disk->log_sector_size = dev->log_sector_size; - #ifdef GRUB_UTIL if (dev->cheat) { + grub_uint64_t cheat_dev_size; + unsigned int cheat_log_sector_size; + if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd)) dev->cheat_fd = grub_util_fd_open (dev->cheat, GRUB_UTIL_FD_O_RDONLY); if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd)) return grub_error (GRUB_ERR_IO, N_("cannot open `%s': %s"), dev->cheat, grub_util_fd_strerror ()); + + /* Use the sector size and count of the cheat device */ + cheat_dev_size = grub_util_get_fd_size (dev->cheat_fd, dev->cheat, &cheat_log_sector_size); + if (cheat_dev_size == -1) + { + const char *errmsg = grub_util_fd_strerror (); + grub_util_fd_close (dev->cheat_fd); + dev->cheat_fd = GRUB_UTIL_FD_INVALID; + return grub_error (GRUB_ERR_IO, N_("failed to query size of device `%s': %s"), + dev->cheat, errmsg); + } + + dev->log_sector_size = cheat_log_sector_size; + dev->total_sectors = cheat_dev_size >> cheat_log_sector_size; } #endif @@ -741,6 +756,7 @@ grub_cryptodisk_open (const char *name, grub_disk_t disk) } disk->data = dev; + disk->log_sector_size = dev->log_sector_size; disk->total_sectors = dev->total_sectors; disk->max_agglomerate = GRUB_DISK_MAX_MAX_AGGLOMERATE; disk->id = dev->id; -- 2.34.1