Fix zfs_ioc_pool_sync should not use fnvlist

Use fnvlist on user input would allow user to easily panic zfs.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Giuseppe Di Natale <dinatale2@llnl.gov>
Reviewed-by: Alek Pinchuk <apinchuk@datto.com>
Signed-off-by: Chunwei Chen <david.chen@osnexus.com>
Closes #6529
This commit is contained in:
Chunwei Chen 2017-08-21 13:11:11 -07:00 committed by Brian Behlendorf
parent 551905dd47
commit 05f85a6a64

View File

@ -5983,20 +5983,26 @@ static int
zfs_ioc_pool_sync(const char *pool, nvlist_t *innvl, nvlist_t *onvl) zfs_ioc_pool_sync(const char *pool, nvlist_t *innvl, nvlist_t *onvl)
{ {
int err; int err;
boolean_t force; boolean_t force = B_FALSE;
spa_t *spa; spa_t *spa;
if ((err = spa_open(pool, &spa, FTAG)) != 0) if ((err = spa_open(pool, &spa, FTAG)) != 0)
return (err); return (err);
force = fnvlist_lookup_boolean_value(innvl, "force"); if (innvl) {
if (nvlist_lookup_boolean_value(innvl, "force", &force) != 0) {
err = SET_ERROR(EINVAL);
goto out;
}
}
if (force) { if (force) {
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_WRITER); spa_config_enter(spa, SCL_CONFIG, FTAG, RW_WRITER);
vdev_config_dirty(spa->spa_root_vdev); vdev_config_dirty(spa->spa_root_vdev);
spa_config_exit(spa, SCL_CONFIG, FTAG); spa_config_exit(spa, SCL_CONFIG, FTAG);
} }
txg_wait_synced(spa_get_dsl(spa), 0); txg_wait_synced(spa_get_dsl(spa), 0);
out:
spa_close(spa, FTAG); spa_close(spa, FTAG);
return (err); return (err);