Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nvCgl-0004V3-QG for mharc-grub-devel@gnu.org; Sun, 29 May 2022 02:46:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvCgf-0004Ul-BR for grub-devel@gnu.org; Sun, 29 May 2022 02:46:05 -0400 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]:43331) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nvCgM-0004PQ-UK for grub-devel@gnu.org; Sun, 29 May 2022 02:46:04 -0400 Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 66FA7320046F; Sun, 29 May 2022 02:45:44 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Sun, 29 May 2022 02:45:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc:cc :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm1; t=1653806743; x=1653893143; bh=leqS9Va7VG PApdoAwPCHeAozohLfjYUDGLnKv5DgdVE=; b=y/IyKXs9cRhrH7Qin+VWWr+lrh wwhqQ+2/gYcLQkIFNqU7/f6cWWwz1CeRCnrilI+xLqW/B0UcxPt0YVNTaIf2xi3B GCD7XZBrqWVRb7i5/DUKeYni+LQthGIsoj75298UiXgtDCi5FIh8p8+pAJN3nYhx Ud73cq5KiC5F1fnKb14K5wu2YHKd3Ho6sKaUT61fTTbR2SrUh2NLN8f/Nf5SykMc zB9v0mZ8H06aQ1ZOY4sSmUOfzTde4JNl61kiSILZoyTG4aQJnUA8yvnCxZ3w7o3q U8iMKUFI5/SDHNwfsPAgZ2onY8hxzfwjFHF33Ol+BJzHIJaq/z8bGer68qsw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1653806743; x=1653893143; bh=leqS9Va7VGPApdoAwPCHeAozohLf jYUDGLnKv5DgdVE=; b=IIkeDeT/gQ+v9as69Fz1H95c0+ABCCE94UhoCuwJ3kLJ i9MUCMSinfytPQ7WDSQ2cYk9DglxFQWtHY+9uRn9FGocIR4xJkIy41efNbb6T+BI lcfhLWhItkrLoVSP5/5CIjwa9gdCYBzciYlQ3XJmNOeuKOz7ITC/PdTqFkC//wbx ObLmaexhbs0hzX8z04PnZ8pVnTbl3qyH+GUqtujTGW1BrFQkpHB6mPeLrHIUKCsD bpKOdghqWRIeoJAyAr4KibXWvS6pwKeswPq7GKtnV/0tc2mPOWW6zA6Lc5PUAgMU V3/LKCX+JgfqcbT/kAcxX+98TeZxOqgUacru5EMrKA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrkeefgddtjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfhfgggtuggjsehgtdorredttddvnecuhfhrohhmpefrrghtrhhi tghkucfuthgvihhnhhgrrhguthcuoehpshesphhkshdrihhmqeenucggtffrrghtthgvrh hnpeehfefhuedtvedtfeeiteeugefgfeelgeelveehffeukeelfefhieekteevudfhffen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 29 May 2022 02:45:42 -0400 (EDT) Received: from localhost (xps [10.192.0.12]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 0cb9dcf5 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 29 May 2022 06:45:40 +0000 (UTC) Date: Sun, 29 May 2022 08:45:39 +0200 From: Patrick Steinhardt To: Glenn Washburn Cc: grub-devel@gnu.org, Daniel Kiper , Denis 'GNUtoo' Carikli , John Lane Subject: Re: [PATCH v2 2/3] cryptodisk: Add support for using detached header files Message-ID: References: <25db3635ff873144d749c29e12e996af03600ab2.1652736873.git.development@efficientek.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="KOSGKpjqt1QEmXKw" Content-Disposition: inline In-Reply-To: <25db3635ff873144d749c29e12e996af03600ab2.1652736873.git.development@efficientek.com> Received-SPF: pass client-ip=64.147.123.19; envelope-from=ps@pks.im; helo=wout3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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, 29 May 2022 06:46:07 -0000 --KOSGKpjqt1QEmXKw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 16, 2022 at 04:49:47PM -0500, Glenn Washburn wrote: > Using the disk read hook mechanism, setup a read hook on the source disk > which will read from the given header file during the scan and recovery > cryptodisk backend functions. Disk read hooks are executed after the data > has been read from the disk. This is okay, because the read hook is given > the read buffer before its sent back to the caller. In this case, the hook > can then overwrite the data read from the disk device with data from the > header file sent in as the read hook data. This is transparent to the > read caller. Since the callers of this function have just opened the > source disk, there are no current read hooks, so there's no need to > save/restore them nor consider if they should be called or not. >=20 > This hook assumes that the header is at the start of the volume, which > is not the case for some formats (eg. GELI). So GELI will return an > error if a detached header is specified. It also can only be used > with formats where the detached header file can be written to the > first blocks of the volume and the volume could still be unlocked. > So the header file can not be formatted differently from the on-disk > header. If these assumpts are not met, detached header file processing > must be specially handled in the cryptodisk backend module. >=20 > The hook will be called potentially many times by a backend. This is fine > because of the assumptions mentioned and the read hook reads from absolute > offsets and is stateless. >=20 > Also add a --header (short -H) option to cryptomount which takes a file > argument. >=20 > Signed-off-by: Glenn Washburn > --- > grub-core/disk/cryptodisk.c | 93 +++++++++++++++++++++++++++++++++++-- > grub-core/disk/geli.c | 4 ++ > include/grub/cryptodisk.h | 2 + > include/grub/file.h | 2 + > 4 files changed, 97 insertions(+), 4 deletions(-) >=20 > diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c > index ecbda7ce9..fdb0461a8 100644 > --- a/grub-core/disk/cryptodisk.c > +++ b/grub-core/disk/cryptodisk.c > @@ -43,7 +43,8 @@ enum > OPTION_PASSWORD, > OPTION_KEYFILE, > OPTION_KEYFILE_OFFSET, > - OPTION_KEYFILE_SIZE > + OPTION_KEYFILE_SIZE, > + OPTION_HEADER > }; > =20 > static const struct grub_arg_option options[] =3D > @@ -56,9 +57,16 @@ static const struct grub_arg_option options[] =3D > {"key-file", 'k', 0, N_("Key file"), 0, ARG_TYPE_STRING}, > {"keyfile-offset", 'O', 0, N_("Key file offset (bytes)"), 0, ARG_TYP= E_INT}, > {"keyfile-size", 'S', 0, N_("Key file data size (bytes)"), 0, ARG_TY= PE_INT}, > + {"header", 'H', 0, N_("Read header from file"), 0, ARG_TYPE_STRING}, > {0, 0, 0, 0, 0, 0} > }; > =20 > +struct cryptodisk_read_hook_ctx > +{ > + grub_file_t hdr_file; > +}; > +typedef struct cryptodisk_read_hook_ctx *cryptodisk_read_hook_ctx_t; > + > /* Our irreducible polynom is x^128+x^7+x^2+x+1. Lowest byte of it is: = */ > #define GF_POLYNOM 0x87 > static inline int GF_PER_SECTOR (const struct grub_cryptodisk *dev) > @@ -1004,6 +1012,31 @@ cryptodisk_close (grub_cryptodisk_t dev) > grub_free (dev); > } > =20 > +static grub_err_t > +cryptodisk_read_hook (grub_disk_addr_t sector, unsigned offset, > + unsigned length, char *buf, void *data) > +{ > + grub_err_t ret =3D GRUB_ERR_NONE; Nit: `ret` is effectively unused. We only set it here and then return it at the end of this function. It prompted me to search whether I just missed it being set, but it's not. So I'd just remove this variable and return `GRUB_ERR_NONE` directly to simplify this. Patrick --KOSGKpjqt1QEmXKw Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEF9hrgiFbCdvenl/rVbJhu7ckPpQFAmKTFpIACgkQVbJhu7ck PpTz+Q/8Dc4z2Fhi+MsT4bo1KX0fmcodQ9GtDbvqS9qtBY/wgNRL5N6X64NqYk58 vjgsjCcHw54ZIkfFBO8t3JE40zcL6tSy5bbwqA0HcaB3Rj/k96tiW2fzIn38AzVz qkPIArPjLJ9+abY+ULdFpwWQe4r/gjhseA8St4u7QctmnCXw61LU9ztYLqOmcDy2 6Eh3Kgu+gH+Njvo38x/rI+/Q/OCAj2xkfll8OsHMl255PsNqR22rQrmM6Ak88H57 TsnFMTpJQ6itRqyOHD59YxIHIEH2vbms4Cc3JQIx7QwmpUyQINbBVTW3fXMjl7yw w9EhQhyPtCVrKj8nKIBfem+7PueJpDWSMGXhoIIUlxDOfdt6o42BAxUKeQ5ox4J5 A5GooZcsxJtVU+/03Wkgioy/WgnFN2/ChLr4fGPj8ANKwd7NI9vIjR2tkPN2CnuF ySMW6a5gmqnyjioJSeKCpXo5gvnHGicyU78rombKeoncEnGvbjZXLNKFO2+lcpdD BK1/Gj221j/ApnwTC0VngZ5NygSLUoxiqvtZsSMHEnUH/MGnhvTRvsQRPFUL1ZPG Agt5Evs5XblTec+tESfPP/hA54ASSTaMKgUYcW4U0L6MXCJYzKmtx1ZGN7/I3utC 5F5Opjk+yhJv/rwoRdoWIyB0wWyM2wNqSAflDtpIh2juEeme3/E= =Na/r -----END PGP SIGNATURE----- --KOSGKpjqt1QEmXKw--