From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1V7a8k-0003uR-IB for mharc-grub-devel@gnu.org; Thu, 08 Aug 2013 20:01:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7a8f-0003t3-1R for grub-devel@gnu.org; Thu, 08 Aug 2013 20:01:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V7a8a-0007nH-Jy for grub-devel@gnu.org; Thu, 08 Aug 2013 20:01:04 -0400 Received: from mmserver.massimo-maggi.eu ([94.23.66.90]:55762) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V7a8a-0007mr-77 for grub-devel@gnu.org; Thu, 08 Aug 2013 20:01:00 -0400 Received: from [IPv6:2001:b05:f:ffff::25] (unknown [IPv6:2001:b05:f:ffff::25]) by mmserver.massimo-maggi.eu (Postfix) with ESMTPSA id 67208284 for ; Fri, 9 Aug 2013 02:00:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=massimo-maggi.eu; s=mmserver; t=1376006456; bh=7PytJ71kBOxUu6CCSc335y3BplJYeZcv4KOo2ECKWpc=; h=Date:From:To:Subject:References:In-Reply-To; b=Wp7wglQn0KOzJqePODlSwQS9wqoMxNaFUcRAGWQ6BQoP3qDG9ovS+hGv5sDLq50zg IthrrE5HHkuhconIx8/tLPgQLzB6W2ea+1JLoBg2oGv/xt29B3Fev22waXoDu2AIqX cojsEp3IA1ZwfdsZc1388FKKbiWfB97TlloTmEpE= Message-ID: <52043133.6080603@massimo-maggi.eu> Date: Fri, 09 Aug 2013 02:00:51 +0200 From: Massimo Maggi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130619 Thunderbird/17.0.6 MIME-Version: 1.0 To: The development of GNU GRUB Subject: Re: [PATCH 1/5] Fix reporting of RAIDZ vdevs in zfsinfo References: <510F96B1.6080509@massimo-maggi.eu> <5185928A.9060905@gmail.com> <5187C6B6.1060709@massimo-maggi.eu> <5187F205.8000105@gmail.com> <51881A91.6050603@massimo-maggi.eu> In-Reply-To: <51881A91.6050603@massimo-maggi.eu> X-Enigmail-Version: 1.6a1pre Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="----enig2OOCWJVRXDXOIINWATPAU" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 94.23.66.90 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: Fri, 09 Aug 2013 00:01:09 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2OOCWJVRXDXOIINWATPAU Content-Type: multipart/mixed; boundary="------------020907010401020503040307" This is a multi-part message in MIME format. --------------020907010401020503040307 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/05/2013 23:03, Massimo Maggi wrote: >=20 > When the issue about the infinite loop gets fully understood and fixed,= > I'll send an updated set of patches. Sorry for the long wait, I was really busy. I've seen that the previous patches were merged. :) In https://github.com/maxximino/grub2/issues/1, Christopher Siden suggested as a proper fix to check the zio_eck_t structure inside the vdev_phys_t structure, which includes a magic number, to be sure that the code is looking as a real ZFS filesystem. I've added also the validation of the SHA256 checksum of the structure itself, so we know that we are not dealing with corrupted or improper dat= a. You can find the patch attached. Regards, Massimo Maggi --------------020907010401020503040307 Content-Type: text/x-patch; name="0001-ZFS-label-detection-improvements.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-ZFS-label-detection-improvements.patch" =46rom 82eb1143c7bfef816d3f875041c5d65e7a69c8a5 Mon Sep 17 00:00:00 2001 From: Massimo Maggi Date: Fri, 9 Aug 2013 00:39:33 +0200 Subject: [PATCH] ZFS label detection improvements. In order to not let zfs code mistakenly analyze a block device as a ZFS filesystem when it contains some other filesystem,let's analyze better the label and fail as soon as possible. In details: * Check the magic number of the zio_eck_t in the vdev_phys_t structu= re, which is the first possible magic number met when analyzing a bloc= k device. * Verify the SHA256 checksum of the vdev_phys_t structure, which contains the nvlists that are going to be read later. Signed-off-by: Massimo Maggi --- grub-core/fs/zfs/zfs.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c index f4acfd8..ceb4df7 100644 --- a/grub-core/fs/zfs/zfs.c +++ b/grub-core/fs/zfs/zfs.c @@ -969,6 +969,9 @@ check_pool_label (struct grub_zfs_data *data, grub_uint64_t version; int found; grub_err_t err; + int endian; + vdev_phys_t *phys; + zio_cksum_t emptycksum; =20 *inserted =3D 0; =20 @@ -976,6 +979,28 @@ check_pool_label (struct grub_zfs_data *data, if (err) return err; =20 + phys=3D(vdev_phys_t*)nvlist; + if( grub_zfs_to_cpu64(phys->vp_zbt.zec_magic, + GRUB_ZFS_LITTLE_ENDIAN) =3D=3D ZEC_MAGIC) + { + endian =3D GRUB_ZFS_LITTLE_ENDIAN; + } + else if(grub_zfs_to_cpu64(phys->vp_zbt.zec_magic, + GRUB_ZFS_BIG_ENDIAN) !=3D ZEC_MAGIC) + { + endian =3D GRUB_ZFS_BIG_ENDIAN; + } + else + { + grub_error (GRUB_ERR_BAD_FS, "bad vdev_phys_t.vp_zbt.zec_magic num= ber"); + return grub_errno; + } + // Now check the integrity of the vdev_phys_t structure though checksu= m. + ZIO_SET_CHECKSUM(&emptycksum, diskdesc->vdev_phys_sector << 9, 0, 0, 0= ); + err =3D zio_checksum_verify (emptycksum, ZIO_CHECKSUM_LABEL, endian, n= vlist, VDEV_PHYS_SIZE); + if(err) + return err; + grub_dprintf ("zfs", "check 2 passed\n"); =20 found =3D grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_STA= TE, --=20 1.8.2.1 --------------020907010401020503040307-- ------enig2OOCWJVRXDXOIINWATPAU 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.0.20 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBAgAGBQJSBDE7AAoJEEO073X3hHDOb8UH/3nGTIkyDK5ZUzf/dCsX2Gm6 otbVWJcdMW8xkzeLUfTCe/0sfDSrC5ocZhkU9FISLM44LUglzy33YkUTGWhP8S7d SuHkt5b3bb+j25hOgoLsTMurBALOZr6UjY8gOCwtkS9biq/xN3GTfwtLMpGifPGO 5pkW+F3XfDEp5553B9qL+m/XXA/PjRQkUbzLSzjsGSm87O/f5HIWJERDt2QNkkip Nvz7ZPCO9puw2YKyMX28mL6PeCy0uGCHkrNqUiVd7LMhfWKtb1fLDjsOQUqrEBvd AHMl0WaoUsHwrNhZv0evIQbJXyFCP27ARCdmUriypISNYGyXGDzMCHofV/fr6AI= =kka6 -----END PGP SIGNATURE----- ------enig2OOCWJVRXDXOIINWATPAU--