Skip to content

Commit c971037

Browse files
pcd1193182ahrens
authored andcommitted
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> Approved by: Richard Lowe <richlowe@richlowe.net>
1 parent 11ceac7 commit c971037

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

usr/src/lib/libzfs/common/libzfs_pool.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,12 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname,
17851785
case EEXIST:
17861786
(void) zpool_standard_error(hdl, error, desc);
17871787
break;
1788-
1788+
case ENAMETOOLONG:
1789+
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
1790+
"new name of at least one dataset is longer than "
1791+
"the maximum allowable length"));
1792+
(void) zfs_error(hdl, EZFS_NAMETOOLONG, desc);
1793+
break;
17891794
default:
17901795
(void) zpool_standard_error(hdl, error, desc);
17911796
zpool_explain_recover(hdl,

usr/src/test/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"

usr/src/uts/common/fs/zfs/spa.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,6 +1926,19 @@ spa_load_verify_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
19261926
return (0);
19271927
}
19281928

1929+
/* ARGSUSED */
1930+
int
1931+
verify_dataset_name_len(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
1932+
{
1933+
char namebuf[MAXPATHLEN];
1934+
dsl_dataset_name(ds, namebuf);
1935+
if (strlen(namebuf) > MAXNAMELEN) {
1936+
return (SET_ERROR(ENAMETOOLONG));
1937+
}
1938+
1939+
return (0);
1940+
}
1941+
19291942
static int
19301943
spa_load_verify(spa_t *spa)
19311944
{
@@ -1940,6 +1953,14 @@ spa_load_verify(spa_t *spa)
19401953
if (policy.zrp_request & ZPOOL_NEVER_REWIND)
19411954
return (0);
19421955

1956+
dsl_pool_config_enter(spa->spa_dsl_pool, FTAG);
1957+
error = dmu_objset_find_dp(spa->spa_dsl_pool,
1958+
spa->spa_dsl_pool->dp_root_dir_obj, verify_dataset_name_len, NULL,
1959+
DS_FIND_CHILDREN);
1960+
dsl_pool_config_exit(spa->spa_dsl_pool, FTAG);
1961+
if (error != 0)
1962+
return (error);
1963+
19431964
rio = zio_root(spa, NULL, &sle,
19441965
ZIO_FLAG_CANFAIL | ZIO_FLAG_SPECULATIVE);
19451966

0 commit comments

Comments
 (0)