summaryrefslogtreecommitdiffstats
path: root/module
diff options
context:
space:
mode:
authorLOLi <[email protected]>2017-03-29 02:21:11 +0200
committerBrian Behlendorf <[email protected]>2017-03-28 17:21:11 -0700
commitff61d1a4959065aa99d52489438f6737765987c6 (patch)
treefd69cf41719b077ee6408b19cba70ae15c6491db /module
parent12aec7dcd9b1f4c86eb71d5b9dc737433ee93167 (diff)
Check ashift validity in 'zpool add'
df83110 added the ability to specify a custom "ashift" value from the command line in 'zpool add' and 'zpool attach'. This commit adds additional checks to the provided ashift to prevent invalid values from being used, which could result in disastrous consequences for the whole pool. Additionally provide ASHIFT_MAX and ASHIFT_MIN definitions in spa.h. Reviewed-by: Giuseppe Di Natale <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: loli10K <[email protected]> Closes #5878
Diffstat (limited to 'module')
-rw-r--r--module/zfs/vdev.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/module/zfs/vdev.c b/module/zfs/vdev.c
index e741a6998..613a9b51e 100644
--- a/module/zfs/vdev.c
+++ b/module/zfs/vdev.c
@@ -1345,8 +1345,15 @@ vdev_open(vdev_t *vd)
*/
vd->vdev_asize = asize;
vd->vdev_max_asize = max_asize;
- if (vd->vdev_ashift == 0)
- vd->vdev_ashift = ashift;
+ if (vd->vdev_ashift == 0) {
+ vd->vdev_ashift = ashift; /* use detected value */
+ }
+ if (vd->vdev_ashift != 0 && (vd->vdev_ashift < ASHIFT_MIN ||
+ vd->vdev_ashift > ASHIFT_MAX)) {
+ vdev_set_state(vd, B_TRUE, VDEV_STATE_CANT_OPEN,
+ VDEV_AUX_BAD_ASHIFT);
+ return (SET_ERROR(EDOM));
+ }
} else {
/*
* Detect if the alignment requirement has increased.
@@ -3487,6 +3494,9 @@ vdev_set_state(vdev_t *vd, boolean_t isopen, vdev_state_t state, vdev_aux_t aux)
case VDEV_AUX_BAD_LABEL:
class = FM_EREPORT_ZFS_DEVICE_BAD_LABEL;
break;
+ case VDEV_AUX_BAD_ASHIFT:
+ class = FM_EREPORT_ZFS_DEVICE_BAD_ASHIFT;
+ break;
default:
class = FM_EREPORT_ZFS_DEVICE_UNKNOWN;
}