Skip to content

Commit d1d19c7

Browse files
pcd1193182behlendorf
authored andcommitted
OpenZFS 6876 - Stack corruption after importing a pool with a too-long name
Reviewed by: Prakash Surya <prakash.surya@delphix.com> Reviewed by: Dan Kimmel <dan.kimmel@delphix.com> Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com> Ported-by: Brian Behlendorf <behlendorf1@llnl.gov> Calling dsl_dataset_name on a dataset with a 256 byte buffer is asking for trouble. We should check every dataset on import, using a 1024 byte buffer and checking each time to see if the dataset's new name is longer than 256 bytes. OpenZFS-issue: https://www.illumos.org/issues/6876 OpenZFS-commit: openzfs/openzfs@ca8674e
1 parent eca7b76 commit d1d19c7

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

lib/libzfs/libzfs_pool.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,12 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
19071907
"one or more devices are already in use\n"));
19081908
(void) zfs_error(hdl, EZFS_BADDEV, desc);
19091909
break;
1910-
1910+
case ENAMETOOLONG:
1911+
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
1912+
"new name of at least one dataset is longer than "
1913+
"the maximum allowable length"));
1914+
(void) zfs_error(hdl, EZFS_NAMETOOLONG, desc);
1915+
break;
19111916
default:
19121917
(void) zpool_standard_error(hdl, error, desc);
19131918
zpool_explain_recover(hdl,

module/zfs/spa.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,16 @@ spa_load_verify_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
20162016
return (0);
20172017
}
20182018

2019+
/* ARGSUSED */
2020+
int
2021+
verify_dataset_name_len(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
2022+
{
2023+
if (dsl_dataset_namelen(ds) >= ZFS_MAX_DATASET_NAME_LEN)
2024+
return (SET_ERROR(ENAMETOOLONG));
2025+
2026+
return (0);
2027+
}
2028+
20192029
static int
20202030
spa_load_verify(spa_t *spa)
20212031
{
@@ -2030,6 +2040,14 @@ spa_load_verify(spa_t *spa)
20302040
if (policy.zrp_request & ZPOOL_NEVER_REWIND)
20312041
return (0);
20322042

2043+
dsl_pool_config_enter(spa->spa_dsl_pool, FTAG);
2044+
error = dmu_objset_find_dp(spa->spa_dsl_pool,
2045+
spa->spa_dsl_pool->dp_root_dir_obj, verify_dataset_name_len, NULL,
2046+
DS_FIND_CHILDREN);
2047+
dsl_pool_config_exit(spa->spa_dsl_pool, FTAG);
2048+
if (error != 0)
2049+
return (error);
2050+
20332051
rio = zio_root(spa, NULL, &sle,
20342052
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE);
20352053

tests/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_rename_001_pos.ksh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#
2727

2828
#
29-
# Copyright (c) 2012 by Delphix. All rights reserved.
29+
# Copyright (c) 2012, 2015 by Delphix. All rights reserved.
3030
#
3131

3232
. $STF_SUITE/include/libtest.shlib
@@ -92,6 +92,8 @@ function cleanup
9292

9393
[[ -d $ALTER_ROOT ]] && \
9494
log_must $RM -rf $ALTER_ROOT
95+
[[ -e $VDEV_FILE ]] && \
96+
log_must $RM $VDEV_FILE
9597
}
9698

9799
log_onexit cleanup
@@ -159,4 +161,13 @@ while (( i < ${#pools[*]} )); do
159161
((i = i + 1))
160162
done
161163

164+
VDEV_FILE=$(mktemp /tmp/tmp.XXXXXX)
165+
166+
log_must $MKFILE -n 128M $VDEV_FILE
167+
log_must $ZPOOL create testpool $VDEV_FILE
168+
log_must $ZFS create testpool/testfs
169+
ID=$($ZPOOL get -Ho value guid testpool)
170+
log_must $ZPOOL export testpool
171+
log_mustnot $ZPOOL import $(echo $ID) $($PRINTF "%*s\n" 250 "" | $TR ' ' 'c')
172+
162173
log_pass "Successfully imported and renamed a ZPOOL"

0 commit comments

Comments
 (0)