Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oKfiZ-0001fH-GV for mharc-grub-devel@gnu.org; Sun, 07 Aug 2022 08:49:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42804) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oKfiS-0001dm-04 for grub-devel@gnu.org; Sun, 07 Aug 2022 08:49:12 -0400 Received: from msg-1.mailo.com ([213.182.54.11]:55532) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oKfiO-000154-IB for grub-devel@gnu.org; Sun, 07 Aug 2022 08:49:11 -0400 Received: by www.mailo.com with http webmail; Sun, 7 Aug 2022 14:49:01 +0200 (CEST) X-EA-Auth: UkNjc9V1S3wrNSnf/38FR9biBZ+LeLDAajvaMPp04R7OYIhdvQviw49yQ1ylwxAHlsaU6Uxang769fkVKEexS/QVCsqrDprJ From: brutser@perso.be To: grub-devel@gnu.org, "Daniel Kiper" Cc: "Glenn Washburn" Date: Sun, 7 Aug 2022 14:49:01 +0200 (CEST) Subject: Re: [PATCH] cryptodisk: Support encrypted volumes using detached headers on a partition X-Priority: 3 MIME-Version: 1.0 X-Mailer: COMS/EA22.05/r20220615 Message-ID: In-Reply-To: <20220807051852.1783126-1-development@efficientek.com> Content-Type: multipart/alternative; boundary="----=_NextPart_001_62efb4bd_18de_1799b945" Received-SPF: pass client-ip=213.182.54.11; envelope-from=brutser@perso.be; helo=msg-1.mailo.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, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: Sun, 07 Aug 2022 12:49:12 -0000 ------=_NextPart_001_62efb4bd_18de_1799b945 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable This patch fixed the issue I had and now makes it possible to decrypt a par= tition with cryptomount when using a detached header. Glenn, thanks for the patience with my not always efficient approach, but = at least I reported something that needed a fix ;-) Van: Glenn Washburn Aan: grub-devel@gnu.org; =C2=A0=C2=A0=C2=A0Daniel Kiper Onderwerp: [PATCH] cryptodisk: Support encrypted volumes using detached he= aders on a partition Datum: 07/08/2022 07:18:52 Europe/Paris Cc: brutser@perso.be; =C2=A0=C2=A0=C2=A0Glenn Washburn 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 rea= d 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[] =3D 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, unsig= ned 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) =3D=3D (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 =3D grub_partition_get_start (source->partitio= n); read_hook_data.hdr_file =3D cargs->hdr_file; source->read_hook =3D cryptodisk_read_hook; source->read_hook_data =3D (void *) &read_hook_data; --=20 2.34.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel ------=_NextPart_001_62efb4bd_18de_1799b945 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
This patch fixed the issue I had and now makes it possible to decrypt = a partition with cryptomount when using a detached header.
Glenn,= thanks for the patience with my not always efficient approach, but at leas= t I reported something that needed a fix ;-)


Van: Glenn Washburn <development@efficientek.com>
Aan: grub-devel@gnu.org;
=C2=A0=C2=A0=C2=A0Daniel Kiper <dkiper@net-space.pl>
Onderwerp: [PATCH] cryptodisk: Support encrypted volumes using detached he= aders on a partition
Datum: 07/08/2022 07:18:52 Europe/Paris
Cc: brutser@perso.be;
=C2=A0=C2=A0=C2=A0Glenn Washburn <development@efficientek.com>

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 rea= d
into the detached header file.

Signed-off-by: Glenn Washburn <development@efficientek.com>
---
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[] =3D
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, unsig= ned offset,
return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("header file not fo= und"));

if (grub_file_seek (ctx->hdr_file,
- (sector * GRUB_DISK_SECTOR_SIZE) + offset)
+ ((sector - ctx->part_start) * GRUB_DISK_SECTOR_SIZE) + offset)=
=3D=3D (grub_off_t) -1)
return grub_errno;

@@ -1078,6 +1079,7 @@ grub_cryptodisk_scan_device_real (const char *name,<= br> * times by a backend. This is fine because of the assumptions ment= ioned
* and the read hook reads from absolute offsets and is stateless.<= br> */
+ read_hook_data.part_start =3D grub_partition_get_start (source->= partition);
read_hook_data.hdr_file =3D cargs->hdr_file;
source->read_hook =3D cryptodisk_read_hook;
source->read_hook_data =3D (void *) &read_hook_data;
--
2.34.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
------=_NextPart_001_62efb4bd_18de_1799b945--