From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oKYhn-0005tX-Vz for mharc-grub-devel@gnu.org; Sun, 07 Aug 2022 01:20:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oKYhl-0005sq-Ga for grub-devel@gnu.org; Sun, 07 Aug 2022 01:20:01 -0400 Received: from mail-qt1-x835.google.com ([2607:f8b0:4864:20::835]:37814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oKYhj-0006PZ-Ho for grub-devel@gnu.org; Sun, 07 Aug 2022 01:20:01 -0400 Received: by mail-qt1-x835.google.com with SMTP id l5so4605686qtv.4 for ; Sat, 06 Aug 2022 22:19:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=WAXA2MuknIa/2fQSaqttdIgvUkmAodT6VfYVg7ZlN2k=; b=G2BQ02pEbyYWlyIqaJaSooxUE8c1FcLAAU/pQiXT2Ik5rfn2pK1lOOabeSP5HzjiLM yzxX+NAGwlFJw3C4ZJpgHBsmMSlTcGqOJwnpWeHLQiufQhlqB6xq4L/Ok4nRHTrrqNj6 gfpu7K5cVB+wZX/SjO0EqYaIm6DtY93g3/Mr3i1AeRSmZb2lGGT5AgSXhVkBVFaphIXN jXYfz0OoV/ys+2uuzCHO2oG4ACzQaxmVDIw3wO7Us+pKnUve9lUKuwDyXlhIqQlN0RHH jtgn3Yqb6u1SjXyzMomfN7h86ynyPDM81TKL64NpWe3rk+dCV0J408XWjpy4RoK2UsLg vupA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=WAXA2MuknIa/2fQSaqttdIgvUkmAodT6VfYVg7ZlN2k=; b=4Oopu7gKEoRD+X/uGFDbkPkiF0/2W9mkWaStkw3NXWN2V5J9VeO0K74FohnwEaeqrp DwYsl8xSO0HJhe1ekrL5jX1mcp0tJDtUAJ4SI6EBCxJdT6WreGH721O0TO0VZkCrPmGg wBDI4en+uBGV9WUrMJtjmkkyDCCffai5tF/TelLUQZKfnoNDnn7LpFpniw12dZB7LeMf tq0BWP3su9gABQzaA1JK/AoSCZntI4O8OvZQOiO+GegRgJbLZuw38RKtAg6u+jzPfuIO GAYGuGkOCAQEOibAy29HHFIO6DiGVRvYbW7wojIPl3fMYqdGncJINC3kAK2dlf3IYTmj I4kg== X-Gm-Message-State: ACgBeo3lMqudSjb2OXU7nsCH2IB98iP1ddakarIwS9fnqOz3Ta0dplXS YZBECyjcU+3Acm6eN70qJl8NNtnMM/wmgw== X-Google-Smtp-Source: AA6agR7V1M8GQBXahCVhyGgsMw8N4Bk2YnOQFmtJBc0eSn29XpyrH1GJ9VgZ1zPXJEIlZJhATwr7cw== X-Received: by 2002:ac8:7c56:0:b0:341:fab1:9450 with SMTP id o22-20020ac87c56000000b00341fab19450mr11152713qtv.589.1659849597995; Sat, 06 Aug 2022 22:19:57 -0700 (PDT) Received: from localhost.localdomain ([185.220.103.12]) by smtp.gmail.com with ESMTPSA id j10-20020a05620a410a00b006a65c58db99sm6834830qko.64.2022.08.06.22.19.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Aug 2022 22:19:57 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: brutser@perso.be, Glenn Washburn Subject: [PATCH] cryptodisk: Support encrypted volumes using detached headers on a partition Date: Sun, 7 Aug 2022 00:18:52 -0500 Message-Id: <20220807051852.1783126-1-development@efficientek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::835; envelope-from=development@efficientek.com; helo=mail-qt1-x835.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: Sun, 07 Aug 2022 05:20:01 -0000 Update the read hook to take into account encrypted volumes on a partition. Grub disk read hooks supply an absolute sector number at which the read is started from. If the encrypted volume is in a partition, the sector number given to the read hook will be offset by the number of the sector at the start of the partition. The read hook then needs to subtract the partition start from the supplied sector to get the correct start sector for the read into the detached header file. Signed-off-by: Glenn Washburn --- grub-core/disk/cryptodisk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c index f1fe0d390..e89430812 100644 --- a/grub-core/disk/cryptodisk.c +++ b/grub-core/disk/cryptodisk.c @@ -64,6 +64,7 @@ static const struct grub_arg_option options[] = struct cryptodisk_read_hook_ctx { grub_file_t hdr_file; + grub_disk_addr_t part_start; }; typedef struct cryptodisk_read_hook_ctx *cryptodisk_read_hook_ctx_t; @@ -1022,7 +1023,7 @@ cryptodisk_read_hook (grub_disk_addr_t sector, unsigned offset, return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("header file not found")); if (grub_file_seek (ctx->hdr_file, - (sector * GRUB_DISK_SECTOR_SIZE) + offset) + ((sector - ctx->part_start) * GRUB_DISK_SECTOR_SIZE) + offset) == (grub_off_t) -1) return grub_errno; @@ -1078,6 +1079,7 @@ grub_cryptodisk_scan_device_real (const char *name, * times by a backend. This is fine because of the assumptions mentioned * and the read hook reads from absolute offsets and is stateless. */ + read_hook_data.part_start = grub_partition_get_start (source->partition); read_hook_data.hdr_file = cargs->hdr_file; source->read_hook = cryptodisk_read_hook; source->read_hook_data = (void *) &read_hook_data; -- 2.34.1