mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-26 04:07:45 +03:00
OpenZFS 6314 - buffer overflow in dsl_dataset_name
Reviewed by: George Wilson <george.wilson@delphix.com> Reviewed by: Prakash Surya <prakash.surya@delphix.com> Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com> Approved by: Dan McDonald <danmcd@omniti.com> Ported-by: Brian Behlendorf <behlendorf1@llnl.gov> OpenZFS-issue: https://www.illumos.org/issues/6314 OpenZFS-commit: https://github.com/openzfs/openzfs/commit/d6160ee
This commit is contained in:
committed by
Brian Behlendorf
parent
43e52eddb1
commit
eca7b76001
+15
-12
@@ -299,13 +299,14 @@ dsl_dir_async_rele(dsl_dir_t *dd, void *tag)
|
||||
dmu_buf_rele(dd->dd_dbuf, tag);
|
||||
}
|
||||
|
||||
/* buf must be long enough (MAXNAMELEN + strlen(MOS_DIR_NAME) + 1 should do) */
|
||||
/* buf must be at least ZFS_MAX_DATASET_NAME_LEN bytes */
|
||||
void
|
||||
dsl_dir_name(dsl_dir_t *dd, char *buf)
|
||||
{
|
||||
if (dd->dd_parent) {
|
||||
dsl_dir_name(dd->dd_parent, buf);
|
||||
(void) strcat(buf, "/");
|
||||
VERIFY3U(strlcat(buf, "/", ZFS_MAX_DATASET_NAME_LEN), <,
|
||||
ZFS_MAX_DATASET_NAME_LEN);
|
||||
} else {
|
||||
buf[0] = '\0';
|
||||
}
|
||||
@@ -315,10 +316,12 @@ dsl_dir_name(dsl_dir_t *dd, char *buf)
|
||||
* dprintf_dd() with dd_lock held
|
||||
*/
|
||||
mutex_enter(&dd->dd_lock);
|
||||
(void) strcat(buf, dd->dd_myname);
|
||||
VERIFY3U(strlcat(buf, dd->dd_myname, ZFS_MAX_DATASET_NAME_LEN),
|
||||
<, ZFS_MAX_DATASET_NAME_LEN);
|
||||
mutex_exit(&dd->dd_lock);
|
||||
} else {
|
||||
(void) strcat(buf, dd->dd_myname);
|
||||
VERIFY3U(strlcat(buf, dd->dd_myname, ZFS_MAX_DATASET_NAME_LEN),
|
||||
<, ZFS_MAX_DATASET_NAME_LEN);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,12 +370,12 @@ getcomponent(const char *path, char *component, const char **nextp)
|
||||
if (p != NULL &&
|
||||
(p[0] != '@' || strpbrk(path+1, "/@") || p[1] == '\0'))
|
||||
return (SET_ERROR(EINVAL));
|
||||
if (strlen(path) >= MAXNAMELEN)
|
||||
if (strlen(path) >= ZFS_MAX_DATASET_NAME_LEN)
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
(void) strcpy(component, path);
|
||||
p = NULL;
|
||||
} else if (p[0] == '/') {
|
||||
if (p - path >= MAXNAMELEN)
|
||||
if (p - path >= ZFS_MAX_DATASET_NAME_LEN)
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
(void) strncpy(component, path, p - path);
|
||||
component[p - path] = '\0';
|
||||
@@ -384,7 +387,7 @@ getcomponent(const char *path, char *component, const char **nextp)
|
||||
*/
|
||||
if (strchr(path, '/'))
|
||||
return (SET_ERROR(EINVAL));
|
||||
if (p - path >= MAXNAMELEN)
|
||||
if (p - path >= ZFS_MAX_DATASET_NAME_LEN)
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
(void) strncpy(component, path, p - path);
|
||||
component[p - path] = '\0';
|
||||
@@ -412,7 +415,7 @@ dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
|
||||
dsl_dir_t *dd;
|
||||
uint64_t ddobj;
|
||||
|
||||
buf = kmem_alloc(MAXNAMELEN, KM_SLEEP);
|
||||
buf = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP);
|
||||
err = getcomponent(name, buf, &next);
|
||||
if (err != 0)
|
||||
goto error;
|
||||
@@ -479,7 +482,7 @@ dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
|
||||
*tailp = next;
|
||||
*ddp = dd;
|
||||
error:
|
||||
kmem_free(buf, MAXNAMELEN);
|
||||
kmem_free(buf, ZFS_MAX_DATASET_NAME_LEN);
|
||||
return (err);
|
||||
}
|
||||
|
||||
@@ -974,7 +977,7 @@ dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv)
|
||||
|
||||
if (dsl_dir_is_clone(dd)) {
|
||||
dsl_dataset_t *ds;
|
||||
char buf[MAXNAMELEN];
|
||||
char buf[ZFS_MAX_DATASET_NAME_LEN];
|
||||
|
||||
VERIFY0(dsl_dataset_hold_obj(dd->dd_pool,
|
||||
dsl_dir_phys(dd)->dd_origin_obj, FTAG, &ds));
|
||||
@@ -1691,11 +1694,11 @@ static int
|
||||
dsl_valid_rename(dsl_pool_t *dp, dsl_dataset_t *ds, void *arg)
|
||||
{
|
||||
int *deltap = arg;
|
||||
char namebuf[MAXNAMELEN];
|
||||
char namebuf[ZFS_MAX_DATASET_NAME_LEN];
|
||||
|
||||
dsl_dataset_name(ds, namebuf);
|
||||
|
||||
if (strlen(namebuf) + *deltap >= MAXNAMELEN)
|
||||
if (strlen(namebuf) + *deltap >= ZFS_MAX_DATASET_NAME_LEN)
|
||||
return (SET_ERROR(ENAMETOOLONG));
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user