From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1ZZLun-0006Iy-Me for mharc-grub-devel@gnu.org; Tue, 08 Sep 2015 12:38:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZLuc-0006De-W1 for grub-devel@gnu.org; Tue, 08 Sep 2015 12:38:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZZLuY-00024M-UP for grub-devel@gnu.org; Tue, 08 Sep 2015 12:38:26 -0400 Received: from mail-pa0-x229.google.com ([2607:f8b0:400e:c03::229]:33602) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZZLuY-00023r-Lc for grub-devel@gnu.org; Tue, 08 Sep 2015 12:38:22 -0400 Received: by pacex6 with SMTP id ex6so128436088pac.0 for ; Tue, 08 Sep 2015 09:38:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type; bh=CPWTtivX+CeiNragLutJk6lc4bbF0+IKEXWjb1OrzoA=; b=YAMrK8HvUyEliXAsuL2opDhO2hv2C7O4hk14FiTvvMGmg0Az2/kEwkhF/p2nHv+8d9 fBSRxIowWFM1855fpC+TmXI2udcWX4qU9XS21KaXvLThuClEIr8ooYnzDX5n3rS9vG5c I1Q5E/dN9wWk9CqGtYQkGhcOIfwhbYw6c65oXNI3m9MshDEU2d3hJFJa+hU2i8E8hLO2 HPUQCIuVopYQA/lGZsNWQo+nVJwZzs9uzNErmRHfn4d0KxnMDfRSNR0WV4upGYt2N7CE ZyXwWwG58SBQ3Lde4T6pCAMAYf6l5N3BSITlGSDKocKRm0VhJ40JZpv/Y4db+F6awi/N ToKQ== X-Received: by 10.67.12.196 with SMTP id es4mr12124616pad.83.1441730301500; Tue, 08 Sep 2015 09:38:21 -0700 (PDT) Received: from [192.168.10.113] ([207.198.105.23]) by smtp.gmail.com with ESMTPSA id ga1sm3969037pbb.80.2015.09.08.09.38.20 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Sep 2015 09:38:20 -0700 (PDT) Subject: Re: cryptodisk: teach grub_cryptodisk_insert() about partitions (bug #45889) To: The development of GNU GRUB References: From: =?UTF-8?Q?Vladimir_'=cf=86-coder/phcoder'_Serbinenko?= Message-ID: <55EF0EFB.5060103@gmail.com> Date: Tue, 8 Sep 2015 09:38:19 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="hCL7mj3TrcQWrRJ8vel6PGnODv72nVbj7" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::229 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Sep 2015 16:38:31 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --hCL7mj3TrcQWrRJ8vel6PGnODv72nVbj7 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 06.09.2015 21:10, TJ wrote: > https://savannah.gnu.org/bugs/index.php?45889 >=20 > Boot disk with 3 LUKS/dm-crypt GPT partitions >=20 > (hd0,gpt3) (hd0,gpt4) (hd0,gpt5) >=20 > grub is in (hd0,gpt3). The others have a LVM VG each. >=20 > Using GRUB_ENABLE_CRYPTODISK=3Dy I deliberately fail the first pass-phr= ase > entry to get the rescue environment. I then >=20 > cryptomount hd0,gpt3 >=20 > (crypto0) device is now present and prefix/root are set correctly. I > insmod some other modules (exploring available functions) and >=20 > set debug=3Dcryptodisk >=20 > I try to >=20 > cryptomount hd0,gpt4 > cryptomount hd0,gpt4 >=20 > and see the message >=20 > disk/cryptodisk.c:978: already mounted as crypto0 >=20 > But ls shows only (crypto0) >=20 > With the attached patch the mounts now work: >=20 > Attempting to decrypt master key... > Enter passphrase for hd0,gpt3 ( ...UUID...) > Slot 0 opened > <<<< next line comes from temporary grub_dprintf() not included in patc= h >>>>> > disk/cryptodisk.c:718: insert 0, source 'hd0,gpt3', id 128, dev_id 0 > grub rescue> ls > (hd0) (hd0,gpt5) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1) (crypto0) > (proc) > grub rescue> cryptomount hd0,gpt4 > Attempting to decrypt master key... > Enter passphrase for hd0,gpt4 (...UUID...) > Slot 0 opened > disk/cryptodisk.c:718: insert 1, source 'hd0,gpt4', id 128, dev_id 0 > grub rescue> cryptomount hd0,gpt5 > Attempting to decrypt master key... > Enter passphrase for hd0,gpt5 (...UUID...) > Slot 0 opened > disk/cryptodisk.c:718: insert 2, source 'hd0,gpt4', id 128, dev_id 0 > grub rescue> insmod lvm > grub rescue> ls > (lvm/VG_OS-x86_64.usr_local) (lvm/VG_OS-ubuntu_15.10_var) > (lvm/VG_OS-ubuntu_15.10_rootfs) (lvm/VG_DATA-home) (hd0) (hd0,gpt5) > (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1) (crypto2) (crypto1) > (crypto0) (proc) >=20 > --- > grub-core/disk/cryptodisk.c | 7 ++++++- > include/grub/cryptodisk.h | 1 + > 2 files changed, 7 insertions(+), 1 deletion(-) >=20 > diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c > index 82a3dcb..0e6bc3f 100644 > --- a/grub-core/disk/cryptodisk.c > +++ b/grub-core/disk/cryptodisk.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include >=20 > #ifdef GRUB_UTIL > #include > @@ -718,6 +719,7 @@ grub_cryptodisk_insert (grub_cryptodisk_t newdev, > const char *name, > newdev->id =3D last_cryptodisk_id++; > newdev->source_id =3D source->id; > newdev->source_dev_id =3D source->dev->id; > + newdev->partition_number =3D source->partition ? > source->partition->number : 0; > newdev->next =3D cryptodisk_list; > cryptodisk_list =3D newdev; >=20 > @@ -740,7 +742,9 @@ grub_cryptodisk_get_by_source_disk (grub_disk_t dis= k) > grub_cryptodisk_t dev; > for (dev =3D cryptodisk_list; dev !=3D NULL; dev =3D dev->next) > if (dev->source_id =3D=3D disk->id && dev->source_dev_id =3D=3D di= sk->dev->id) > - return dev; > + if ((disk->partition && disk->partition->number =3D=3D > dev->partition_number) || > + (!disk->partition && dev->partition_number =3D=3D 0)) > + return dev; Please store and compare partition start, not parition number as the same partition can be available several times through different partiton schemes under different numbers. Additionally this allows to use get_partition_start which already has the logic of handling empty partiti= ons > return NULL; > } >=20 > @@ -761,6 +765,7 @@ grub_cryptodisk_cheat_insert (grub_cryptodisk_t > newdev, const char *name, > newdev->cheat_fd =3D GRUB_UTIL_FD_INVALID; > newdev->source_id =3D source->id; > newdev->source_dev_id =3D source->dev->id; > + newdev->partition_number =3D source->partition ? > source->partition->number : 0; > newdev->id =3D last_cryptodisk_id++; > newdev->next =3D cryptodisk_list; > cryptodisk_list =3D newdev; > diff --git a/include/grub/cryptodisk.h b/include/grub/cryptodisk.h > index f2ad2a7..b638f2e 100644 > --- a/include/grub/cryptodisk.h > +++ b/include/grub/cryptodisk.h > @@ -97,6 +97,7 @@ struct grub_cryptodisk > grub_uint8_t rekey_key[64]; > grub_uint64_t last_rekey; > int rekey_derived_size; > + int partition_number; > }; > typedef struct grub_cryptodisk *grub_cryptodisk_t; >=20 --hCL7mj3TrcQWrRJ8vel6PGnODv72nVbj7 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iF4EAREKAAYFAlXvDvsACgkQmBXlbbo5nOtwOgD9GMDDrxO7z1dJ9qkb+jrWhVWa 9IPRFanyPGFWPHaY7KABAJSR6It9MRfWpR+s+Sl7uXTEHquB+4NOrIXEvhRVuTH0 =qlm1 -----END PGP SIGNATURE----- --hCL7mj3TrcQWrRJ8vel6PGnODv72nVbj7--