loader: zfs reader vdev_probe should check for minimum device size

The smallest device we can have in the pool is 64MB, since we are trying to
walk all four labels to find the most up to date uberblock, this limit will
also give us good method to check if we even should attempt to probe.

Enforcing the check also will make sure we are not getting wrapped while
calculating the label offset.

Also, after label check, we should verify if we actually got any UB or not.

PR:		218473
Reported by:	Masachika ISHIZUKA
Reviewed by:	allanjude
Differential Revision:	https://reviews.freebsd.org/D10381
This commit is contained in:
tsoome 2017-04-18 15:43:47 +00:00
parent b86af7ea9c
commit 49f4f2c3b8

View File

@ -929,7 +929,7 @@ vdev_probe(vdev_phys_read_t *_read, void *read_priv, spa_t **spap)
{
vdev_t vtmp;
vdev_phys_t *vdev_label = (vdev_phys_t *) zap_scratch;
vdev_phys_t *tmp_label = zfs_alloc(sizeof(vdev_phys_t));
vdev_phys_t *tmp_label;
spa_t *spa;
vdev_t *vdev, *top_vdev, *pool_vdev;
off_t off;
@ -957,6 +957,12 @@ vdev_probe(vdev_phys_read_t *_read, void *read_priv, spa_t **spap)
psize = P2ALIGN(ldi_get_size(read_priv),
(uint64_t)sizeof (vdev_label_t));
/* Test for minimum pool size. */
if (psize < SPA_MINDEVSIZE)
return (EIO);
tmp_label = zfs_alloc(sizeof(vdev_phys_t));
for (l = 0; l < VDEV_LABELS; l++) {
off = vdev_label_offset(psize, l,
offsetof(vdev_label_t, vl_vdev_phys));
@ -988,6 +994,9 @@ vdev_probe(vdev_phys_read_t *_read, void *read_priv, spa_t **spap)
zfs_free(tmp_label, sizeof (vdev_phys_t));
if (best_txg == 0)
return (EIO);
if (vdev_label->vp_nvlist[0] != NV_ENCODE_XDR)
return (EIO);