aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/dsl_crypt.c
diff options
context:
space:
mode:
authorRob N <[email protected]>2023-03-08 09:05:14 +1100
committerGitHub <[email protected]>2023-03-07 14:05:14 -0800
commitb988f32c701760da8793f83f22f2043578e11b67 (patch)
tree7c69988ae907867bd285b9081cdde4ef31f9be30 /module/zfs/dsl_crypt.c
parent12a240ac0b3b89e9210b3a2a539c1f74488e927d (diff)
Better handling for future crypto parameters
The intent is that this is like ENOTSUP, but specifically for when something can't be done because we have no support for the requested crypto parameters; eg unlocking a dataset or receiving a stream encrypted with a suite we don't support. Its not intended to be recoverable without upgrading ZFS itself. If the request could be made to work by enabling a feature or modifying some other configuration item, then some other code should be used. load-key: In the future we might have more crypto suites (ie new values for the `encryption` property. Right now trying to load a key on such a future crypto suite will look up suite parameters off the end of the crypto table, resulting in misbehaviour and/or crashes (or, with debug enabled, trip the assertion in `zio_crypt_key_unwrap`). Instead, lets check the value we got from the dataset, and if we can't handle it, abort early. recv: When receiving a raw stream encrypted with an unknown crypto suite, `zfs recv` would report a generic `invalid backup stream` (EINVAL). While technically correct, its not super helpful, so lets ship a more specific error code and message. Reviewed-by: Tino Reichardt <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Richard Yao <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #14577
Diffstat (limited to 'module/zfs/dsl_crypt.c')
-rw-r--r--module/zfs/dsl_crypt.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/module/zfs/dsl_crypt.c b/module/zfs/dsl_crypt.c
index 408d038b4..dd936e74b 100644
--- a/module/zfs/dsl_crypt.c
+++ b/module/zfs/dsl_crypt.c
@@ -541,6 +541,12 @@ dsl_crypto_key_open(objset_t *mos, dsl_wrapping_key_t *wkey,
if (ret != 0)
goto error;
+ /* handle a future crypto suite that we don't support */
+ if (crypt >= ZIO_CRYPT_FUNCTIONS) {
+ ret = (SET_ERROR(ZFS_ERR_CRYPTO_NOTSUP));
+ goto error;
+ }
+
ret = zap_lookup(mos, dckobj, DSL_CRYPTO_KEY_GUID, 8, 1, &guid);
if (ret != 0)
goto error;
@@ -2141,10 +2147,16 @@ dsl_crypto_recv_raw_key_check(dsl_dataset_t *ds, nvlist_t *nvl, dmu_tx_t *tx)
* wrapping key.
*/
ret = nvlist_lookup_uint64(nvl, DSL_CRYPTO_KEY_CRYPTO_SUITE, &intval);
- if (ret != 0 || intval >= ZIO_CRYPT_FUNCTIONS ||
- intval <= ZIO_CRYPT_OFF)
+ if (ret != 0 || intval <= ZIO_CRYPT_OFF)
return (SET_ERROR(EINVAL));
+ /*
+ * Flag a future crypto suite that we don't support differently, so
+ * we can return a more useful error to the user.
+ */
+ if (intval >= ZIO_CRYPT_FUNCTIONS)
+ return (SET_ERROR(ZFS_ERR_CRYPTO_NOTSUP));
+
ret = nvlist_lookup_uint64(nvl, DSL_CRYPTO_KEY_GUID, &intval);
if (ret != 0)
return (SET_ERROR(EINVAL));