changeset 2717:ed589a32259d

6469385 zfs_set_prop_nvlist range checking is busted 6469830 'zfs set' panics non-debug systems
author eschrock
date Tue, 12 Sep 2006 19:44:44 -0700
parents bb7a9ab4a572
children 17c511718258
files usr/src/common/zfs/zfs_prop.c usr/src/common/zfs/zfs_prop.h usr/src/uts/common/fs/zfs/zfs_ioctl.c usr/src/uts/common/sys/fs/zfs.h
diffstat 4 files changed, 18 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/common/zfs/zfs_prop.c	Tue Sep 12 15:12:02 2006 -0700
+++ b/usr/src/common/zfs/zfs_prop.c	Tue Sep 12 19:44:44 2006 -0700
@@ -295,8 +295,6 @@
 	return (zfs_prop_table[prop].pd_attr == prop_inherit);
 }
 
-#ifndef _KERNEL
-
 typedef struct zfs_index {
 	const char *name;
 	uint64_t index;
@@ -345,19 +343,14 @@
 	switch (prop) {
 	case ZFS_PROP_CHECKSUM:
 		return (checksum_table);
-		break;
 	case ZFS_PROP_COMPRESSION:
 		return (compress_table);
-		break;
 	case ZFS_PROP_SNAPDIR:
 		return (snapdir_table);
-		break;
 	case ZFS_PROP_ACLMODE:
 		return (acl_mode_table);
-		break;
 	case ZFS_PROP_ACLINHERIT:
 		return (acl_inherit_table);
-		break;
 	default:
 		return (NULL);
 	}
@@ -406,6 +399,8 @@
 	return (-1);
 }
 
+#ifndef _KERNEL
+
 /*
  * Returns TRUE if the property applies to the given dataset types.
  */
--- a/usr/src/common/zfs/zfs_prop.h	Tue Sep 12 15:12:02 2006 -0700
+++ b/usr/src/common/zfs/zfs_prop.h	Tue Sep 12 19:44:44 2006 -0700
@@ -47,8 +47,6 @@
 } zfs_proptype_t;
 
 zfs_proptype_t zfs_prop_get_type(zfs_prop_t);
-int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
-int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
 size_t zfs_prop_width(zfs_prop_t, boolean_t *);
 
 #ifdef	__cplusplus
--- a/usr/src/uts/common/fs/zfs/zfs_ioctl.c	Tue Sep 12 15:12:02 2006 -0700
+++ b/usr/src/uts/common/fs/zfs/zfs_ioctl.c	Tue Sep 12 19:44:44 2006 -0700
@@ -738,6 +738,7 @@
 	zfs_prop_t prop;
 	uint64_t intval;
 	char *strval;
+	const char *unused;
 
 	elem = NULL;
 	while ((elem = nvlist_next_nvpair(nvl, elem)) != NULL) {
@@ -832,54 +833,27 @@
 				if (zfs_prop_get_type(prop) !=
 				    prop_type_string)
 					return (EINVAL);
-				ASSERT(nvpair_value_string(elem, &strval) == 0);
-				error = dsl_prop_set(name,
+				VERIFY(nvpair_value_string(elem, &strval) == 0);
+				if ((error = dsl_prop_set(name,
 				    nvpair_name(elem), 1, strlen(strval) + 1,
-				    strval);
+				    strval)) != 0)
+					return (error);
 			} else if (nvpair_type(elem) == DATA_TYPE_UINT64) {
-				ASSERT(nvpair_value_uint64(elem, &intval) == 0);
+				VERIFY(nvpair_value_uint64(elem, &intval) == 0);
 
 				switch (zfs_prop_get_type(prop)) {
 				case prop_type_number:
 					break;
 				case prop_type_boolean:
 					if (intval > 1)
-						error = EINVAL;
+						return (EINVAL);
 					break;
 				case prop_type_string:
-					error = EINVAL;
-					break;
+					return (EINVAL);
 				case prop_type_index:
-					switch (prop) {
-					case ZFS_PROP_CHECKSUM:
-						if (intval >=
-						    ZIO_CHECKSUM_FUNCTIONS)
-							error = EINVAL;
-						break;
-					case ZFS_PROP_COMPRESSION:
-						if (intval >=
-						    ZIO_COMPRESS_FUNCTIONS)
-							error = EINVAL;
-						break;
-					case ZFS_PROP_SNAPDIR:
-						if (intval >
-						    ZFS_SNAPDIR_VISIBLE)
-							error = EINVAL;
-						break;
-					case ZFS_PROP_ACLMODE:
-						if (intval >
-						    ZFS_ACL_PASSTHROUGH)
-							error = EINVAL;
-						break;
-					case ZFS_PROP_ACLINHERIT:
-						if (intval > ZFS_ACL_SECURE ||
-						    intval == ZFS_ACL_GROUPMASK)
-							error = EINVAL;
-						break;
-					default:
-						cmn_err(CE_PANIC,
-						    "unknown index property");
-					}
+					if (zfs_prop_index_to_string(prop,
+					    intval, &unused) != 0)
+						return (EINVAL);
 					break;
 				default:
 					cmn_err(CE_PANIC, "unknown property "
@@ -887,8 +861,9 @@
 					break;
 				}
 
-				error = dsl_prop_set(name, propname, 8, 1,
-				    &intval);
+				if ((error = dsl_prop_set(name, propname,
+				    8, 1, &intval)) != 0)
+					return (error);
 			} else {
 				return (EINVAL);
 			}
--- a/usr/src/uts/common/sys/fs/zfs.h	Tue Sep 12 15:12:02 2006 -0700
+++ b/usr/src/uts/common/sys/fs/zfs.h	Tue Sep 12 19:44:44 2006 -0700
@@ -109,6 +109,8 @@
 const char *zfs_prop_to_name(zfs_prop_t);
 uint64_t zfs_prop_default_numeric(zfs_prop_t);
 int zfs_prop_inheritable(zfs_prop_t);
+int zfs_prop_string_to_index(zfs_prop_t, const char *, uint64_t *);
+int zfs_prop_index_to_string(zfs_prop_t, uint64_t, const char **);
 
 /*
  * On-disk version number.