All of lore.kernel.org
 help / color / mirror / Atom feed
From: Massimo Maggi <me@massimo-maggi.eu>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: [PATCH 1/5] Fix reporting of RAIDZ vdevs in zfsinfo
Date: Fri, 09 Aug 2013 02:00:51 +0200	[thread overview]
Message-ID: <52043133.6080603@massimo-maggi.eu> (raw)
In-Reply-To: <51881A91.6050603@massimo-maggi.eu>


[-- Attachment #1.1: Type: text/plain, Size: 728 bytes --]

On 06/05/2013 23:03, Massimo Maggi wrote:
> 
> 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 data.
You can find the patch attached.
Regards,
Massimo Maggi


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-ZFS-label-detection-improvements.patch --]
[-- Type: text/x-patch; name="0001-ZFS-label-detection-improvements.patch", Size: 2225 bytes --]

From 82eb1143c7bfef816d3f875041c5d65e7a69c8a5 Mon Sep 17 00:00:00 2001
From: Massimo Maggi <me@massimo-maggi.eu>
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 structure,
       which is the first possible magic number met when analyzing a block
       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<me@massimo-maggi.eu>
---
 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;
 
   *inserted = 0;
 
@@ -976,6 +979,28 @@ check_pool_label (struct grub_zfs_data *data,
   if (err)
     return err;
 
+  phys=(vdev_phys_t*)nvlist;
+  if( grub_zfs_to_cpu64(phys->vp_zbt.zec_magic,
+	  GRUB_ZFS_LITTLE_ENDIAN) == ZEC_MAGIC)
+    {
+      endian = GRUB_ZFS_LITTLE_ENDIAN;
+    }
+  else if(grub_zfs_to_cpu64(phys->vp_zbt.zec_magic,
+	  GRUB_ZFS_BIG_ENDIAN) != ZEC_MAGIC)
+    {
+      endian = GRUB_ZFS_BIG_ENDIAN;
+    }
+  else
+    {
+      grub_error (GRUB_ERR_BAD_FS, "bad vdev_phys_t.vp_zbt.zec_magic number");
+      return grub_errno;
+    }
+  // Now check the integrity of the vdev_phys_t structure though checksum.
+  ZIO_SET_CHECKSUM(&emptycksum, diskdesc->vdev_phys_sector << 9, 0, 0, 0);
+  err = zio_checksum_verify (emptycksum, ZIO_CHECKSUM_LABEL, endian, nvlist, VDEV_PHYS_SIZE);
+  if(err)
+     return err;
+
   grub_dprintf ("zfs", "check 2 passed\n");
 
   found = grub_zfs_nvlist_lookup_uint64 (nvlist, ZPOOL_CONFIG_POOL_STATE,
-- 
1.8.2.1


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 555 bytes --]

  reply	other threads:[~2013-08-09  0:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1359973957.git.me@massimo-maggi.eu>
2013-02-04 11:08 ` [PATCH 1/5] Fix reporting of RAIDZ vdevs in zfsinfo Massimo Maggi
2013-05-04 22:58   ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-06 15:05     ` Massimo Maggi
2013-05-06 18:10       ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-06 21:03         ` Massimo Maggi
2013-08-09  0:00           ` Massimo Maggi [this message]
2013-08-09  2:39             ` Andrey Borzenkov
2013-08-09 18:46               ` Massimo Maggi
2013-02-04 11:09 ` [PATCH 2/5] Accept pool version 5000 for feature flags Massimo Maggi
2013-02-04 11:09 ` [PATCH 3/5] Refactoring of function nvlist_find_value Massimo Maggi
2013-02-04 11:09 ` [PATCH 4/5] Check for feature flags needed to read from the pool Massimo Maggi
2013-02-04 11:10 ` [PATCH 5/5] LZ4 compression in ZFS Massimo Maggi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52043133.6080603@massimo-maggi.eu \
    --to=me@massimo-maggi.eu \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.