Skip to content

Commit

Permalink
Restrict filesystem creation if name referred either '.' or '..'
Browse files Browse the repository at this point in the history
This change restricts filesystem creation if the given name
contains either '.' or '..'

Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Richard Elling <Richard.Elling@RichardElling.com>
Signed-off-by: TulsiJain <tulsi.jain@delphix.com>
Closes #8842
Closes #8564
  • Loading branch information
TulsiJain authored and tonyhutter committed Aug 13, 2019
1 parent 0826e12 commit 5379280
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/zfs_namecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ typedef enum {
NAME_ERR_RESERVED, /* entire name is reserved */
NAME_ERR_DISKLIKE, /* reserved disk name (c[0-9].*) */
NAME_ERR_TOOLONG, /* name is too long */
NAME_ERR_SELF_REF, /* reserved self path name ('.') */
NAME_ERR_PARENT_REF, /* reserved parent path name ('..') */
NAME_ERR_NO_AT, /* permission set is missing '@' */
} namecheck_err_t;

Expand Down
10 changes: 10 additions & 0 deletions lib/libzfs/libzfs_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ zfs_validate_name(libzfs_handle_t *hdl, const char *path, int type,
"reserved disk name"));
break;

case NAME_ERR_SELF_REF:
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"self reference, '.' is found in name"));
break;

case NAME_ERR_PARENT_REF:
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"parent reference, '..' is found in name"));
break;

default:
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"(%d) not defined"), why);
Expand Down
21 changes: 21 additions & 0 deletions module/zcommon/zfs_namecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,27 @@ entity_namecheck(const char *path, namecheck_err_t *why, char *what)
}
}

if (*end == '\0' || *end == '/') {
int component_length = end - start;
/* Validate the contents of this component is not '.' */
if (component_length == 1) {
if (start[0] == '.') {
if (why)
*why = NAME_ERR_SELF_REF;
return (-1);
}
}

/* Validate the content of this component is not '..' */
if (component_length == 2) {
if (start[0] == '.' && start[1] == '.') {
if (why)
*why = NAME_ERR_PARENT_REF;
return (-1);
}
}
}

/* Snapshot or bookmark delimiter found */
if (*end == '@' || *end == '#') {
/* Multiple delimiters are not allowed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ set -A args "$TESTPOOL/" "$TESTPOOL//blah" "$TESTPOOL/@blah" \
"$TESTPOOL/blah*blah" "$TESTPOOL/blah blah" \
"-s $TESTPOOL/$TESTFS1" "-b 1092 $TESTPOOL/$TESTFS1" \
"-b 64k $TESTPOOL/$TESTFS1" "-s -b 32k $TESTPOOL/$TESTFS1" \
"$TESTPOOL/$BYND_MAX_NAME" "$TESTPOOL/$BYND_NEST_LIMIT"
"$TESTPOOL/$BYND_MAX_NAME" "$TESTPOOL/$BYND_NEST_LIMIT" \
"$TESTPOOL/." "$TESTPOOL/.." "$TESTPOOL/../blah" "$TESTPOOL/./blah" \
"$TESTPOOL/blah/./blah" "$TESTPOOL/blah/../blah"

log_assert "Verify 'zfs create <filesystem>' fails with bad <filesystem> argument."

Expand Down

0 comments on commit 5379280

Please sign in to comment.