Skip to content

Commit 3ad8826

Browse files
lundmantonyhutter
authored andcommitted
Avoid calling rw_destroy() on uninitialized rwlock
First the function `memset(&key, 0, ...)` but any call to "goto error;" would call zio_crypt_key_destroy(key) which calls `rw_destroy()`. The `rw_init()` is moved up to be right after the memset. This way the rwlock can be released. The ctx does allocate memory, but that is handled by the memset to 0 and icp skips NULL ptrs. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Richard Yao <[email protected]> Signed-off-by: Jorgen Lundman <[email protected]> Closes #13976
1 parent 00a3821 commit 3ad8826

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

module/os/linux/zfs/zio_crypt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ zio_crypt_key_init(uint64_t crypt, zio_crypt_key_t *key)
249249
#pragma GCC diagnostic pop
250250
#endif
251251
memset(key, 0, sizeof (zio_crypt_key_t));
252+
rw_init(&key->zk_salt_lock, NULL, RW_DEFAULT, NULL);
252253

253254
/* fill keydata buffers and salt with random data */
254255
ret = random_get_bytes((uint8_t *)&key->zk_guid, sizeof (uint64_t));
@@ -302,7 +303,6 @@ zio_crypt_key_init(uint64_t crypt, zio_crypt_key_t *key)
302303
key->zk_crypt = crypt;
303304
key->zk_version = ZIO_CRYPT_KEY_CURRENT_VERSION;
304305
key->zk_salt_count = 0;
305-
rw_init(&key->zk_salt_lock, NULL, RW_DEFAULT, NULL);
306306

307307
return (0);
308308

0 commit comments

Comments
 (0)