Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 07 Mar 2010 13:10:57 +0200
From:      Andriy Gapon <avg@icyb.net.ua>
To:        freebsd-geom@freebsd.org, Marcel Moolenaar <xcllnt@mac.com>
Subject:   another gpt vs mbr (sanity) check
Message-ID:  <4B9389C1.9000102@icyb.net.ua>

next in thread | raw e-mail | index | archive | help

Please consider the following scenario:
- GPT scheme is used on a disk
- the disk changes hands
- the disk is repartitioned with MBR without explicitly wiping out any of old
data and thus GPT
- GPT data survives undamaged

So now we have the valid GPT but it points to wrong offsets and we have the
valid and correct MBR.
Currently FreeBSD would pick GPT scheme over MBR scheme when presented which
such a disk.  I think that this is incorrect.
I believe that our code should check if MBR is indeed a protective MBR when
deciding whether to use GPT.

Below is a simplistic patch that adds such a check.
Ideally it should probably check the whole MBR partition table instead of just a
type of the first entry.

What do you think?

--- a/sys/geom/part/g_part_gpt.c
+++ b/sys/geom/part/g_part_gpt.c
@@ -568,7 +568,7 @@ g_part_gpt_probe
 {
 	struct g_provider *pp;
 	char *buf;
-	int error, res;
+	int error, res, typ;

 	/* We don't nest, which means that our depth should be 0. */
 	if (table->gpt_depth != 0)
@@ -598,10 +598,12 @@ g_part_gpt_probe
 	if (buf == NULL)
 		return (error);
 	res = le16dec(buf + DOSMAGICOFFSET);
+	typ = *(unsigned char*)(buf + DOSPARTOFF + 0 * DOSPARTSIZE + 4);
 	g_free(buf);
 	if (res != DOSMAGIC)
 		return (ENXIO);
-
+	if (typ != DOSPTYP_PMBR)
+		return (ENXIO);
 	/* Check that there's a primary header. */
 	buf = g_read_data(cp, pp->sectorsize, pp->sectorsize, &error);
 	if (buf == NULL)

-- 
Andriy Gapon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B9389C1.9000102>