Skip to content

Commit

Permalink
get_key_material: skip passphrase validation when loading keys
Browse files Browse the repository at this point in the history
The restriction that an encryption key must be at least
MIN_PASSPHRASE_LEN characters long make sense when changing the
encryption key, but not when loading: as this restriction is not
enforced in the libraries, it is possible to bypass zfs change-key's
restrictions and end up with a key that becomes impossible to load with
zfs load-key, for example through pam_zfs_key.

Reviewed-by: Felix Dörre <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Harald van Dijk <[email protected]>
Closes openzfs#12765
  • Loading branch information
hvdijk authored and nicman23 committed Aug 22, 2022
1 parent 7ebe2ee commit 166ede8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/libzfs/libzfs_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ get_format_prompt_string(zfs_keyformat_t format)
/* do basic validation of the key material */
static int
validate_key(libzfs_handle_t *hdl, zfs_keyformat_t keyformat,
const char *key, size_t keylen)
const char *key, size_t keylen, boolean_t do_verify)
{
switch (keyformat) {
case ZFS_KEYFORMAT_RAW:
Expand Down Expand Up @@ -245,7 +245,10 @@ validate_key(libzfs_handle_t *hdl, zfs_keyformat_t keyformat,
}
break;
case ZFS_KEYFORMAT_PASSPHRASE:
/* verify the length is within bounds */
/* verify the length is within bounds when setting a new key,
* but not when loading an existing key */
if (!do_verify)
break;
if (keylen > MAX_PASSPHRASE_LEN) {
zfs_error_aux(hdl, dgettext(TEXT_DOMAIN,
"Passphrase too long (max %u)."),
Expand Down Expand Up @@ -380,7 +383,8 @@ get_key_interactive(libzfs_handle_t *restrict hdl, const char *fsname,
if (!confirm_key)
goto out;

if ((ret = validate_key(hdl, keyformat, buf, buflen)) != 0) {
if ((ret = validate_key(hdl, keyformat, buf, buflen, confirm_key)) !=
0) {
free(buf);
return (ret);
}
Expand Down Expand Up @@ -740,7 +744,8 @@ get_key_material(libzfs_handle_t *hdl, boolean_t do_verify, boolean_t newkey,
goto error;
}

if ((ret = validate_key(hdl, keyformat, (const char *)km, kmlen)) != 0)
if ((ret = validate_key(hdl, keyformat, (const char *)km, kmlen,
do_verify)) != 0)
goto error;

*km_out = km;
Expand Down

0 comments on commit 166ede8

Please sign in to comment.