Skip to content

Commit

Permalink
dsl_prop_known_index(): check for invalid prop
Browse files Browse the repository at this point in the history
Resolve UBSAN array-index-out-of-bounds error in zprop_desc_t.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: szubersk <szuberskidamian@gmail.com>
Closes #14142
Closes #14147
  • Loading branch information
szubersk authored Nov 8, 2022
1 parent 4171577 commit 109731c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions module/zcommon/zfs_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ zfs_prop_init(void)
boolean_t
zfs_prop_delegatable(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
zprop_desc_t *pd = &zfs_prop_table[prop];

/* The mlslabel property is never delegatable. */
Expand Down Expand Up @@ -858,6 +860,8 @@ zfs_prop_valid_for_type(int prop, zfs_type_t types, boolean_t headcheck)
zprop_type_t
zfs_prop_get_type(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_proptype);
}

Expand All @@ -867,6 +871,8 @@ zfs_prop_get_type(zfs_prop_t prop)
boolean_t
zfs_prop_readonly(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_attr == PROP_READONLY ||
zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
Expand All @@ -878,6 +884,8 @@ zfs_prop_readonly(zfs_prop_t prop)
boolean_t
zfs_prop_visible(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_visible &&
zfs_prop_table[prop].pd_zfs_mod_supported);
}
Expand All @@ -888,19 +896,25 @@ zfs_prop_visible(zfs_prop_t prop)
boolean_t
zfs_prop_setonce(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_attr == PROP_ONETIME ||
zfs_prop_table[prop].pd_attr == PROP_ONETIME_DEFAULT);
}

const char *
zfs_prop_default_string(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_strdefault);
}

uint64_t
zfs_prop_default_numeric(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_numdefault);
}

Expand All @@ -911,6 +925,8 @@ zfs_prop_default_numeric(zfs_prop_t prop)
const char *
zfs_prop_to_name(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_name);
}

Expand All @@ -920,6 +936,8 @@ zfs_prop_to_name(zfs_prop_t prop)
boolean_t
zfs_prop_inheritable(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_attr == PROP_INHERIT ||
zfs_prop_table[prop].pd_attr == PROP_ONETIME);
}
Expand Down Expand Up @@ -972,6 +990,8 @@ zfs_prop_valid_keylocation(const char *str, boolean_t encrypted)
const char *
zfs_prop_values(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_values);
}

Expand All @@ -983,6 +1003,8 @@ zfs_prop_values(zfs_prop_t prop)
int
zfs_prop_is_string(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_proptype == PROP_TYPE_STRING ||
zfs_prop_table[prop].pd_proptype == PROP_TYPE_INDEX);
}
Expand All @@ -994,6 +1016,8 @@ zfs_prop_is_string(zfs_prop_t prop)
const char *
zfs_prop_column_name(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_colname);
}

Expand All @@ -1004,6 +1028,8 @@ zfs_prop_column_name(zfs_prop_t prop)
boolean_t
zfs_prop_align_right(zfs_prop_t prop)
{
ASSERT3S(prop, >=, 0);
ASSERT3S(prop, <, ZFS_NUM_PROPS);
return (zfs_prop_table[prop].pd_rightalign);
}

Expand Down
3 changes: 2 additions & 1 deletion module/zfs/dsl_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ static int
dsl_prop_known_index(zfs_prop_t prop, uint64_t value)
{
const char *str = NULL;
if (zfs_prop_get_type(prop) == PROP_TYPE_INDEX)
if (prop != ZPROP_CONT && prop != ZPROP_INVAL &&
zfs_prop_get_type(prop) == PROP_TYPE_INDEX)
return (!zfs_prop_index_to_string(prop, value, &str));

return (-1);
Expand Down

0 comments on commit 109731c

Please sign in to comment.