Skip to content

Commit b01d7bd

Browse files
authored
ZTS: testing for leaked key mappings in encrypted non-raw send
This test covers a bug fixed by commit ea74cde: performing an incremental non-raw send from an encrypted filesystem followed by exporting the pool. Before that commit, exporting the sending pool in this scenario would trigger a panic: VERIFY(avl_is_empty(&sk->sk_dsl_keys)) failed PANIC at dsl_crypt.c:353:spa_keystore_fini() Call Trace: spl_dumpstack+0x29/0x2f [spl] spl_panic+0xd1/0xe9 [spl] spl_assert.constprop.0+0x1a/0x30 [zfs] spa_keystore_fini+0xc2/0xf0 [zfs] spa_deactivate+0x25f/0x610 [zfs] spa_evict_all+0xf4/0x200 [zfs] spa_fini+0x13/0x140 [zfs] zfs_kmod_fini+0x72/0xc0 [zfs] openzfs_fini_os+0x13/0x3a [zfs] openzfs_fini+0x9/0x6b8 [zfs] Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: George Amanakis <[email protected]> Closes #17366
1 parent 92157c8 commit b01d7bd

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ tests = ['recv_dedup', 'recv_dedup_encrypted_zvol', 'rsend_001_pos',
956956
'send_spill_block', 'send_holds', 'send_hole_birth', 'send_mixed_raw',
957957
'send-wR_encrypted_zvol', 'send_partial_dataset', 'send_invalid',
958958
'send_doall', 'send_raw_spill_block', 'send_raw_ashift',
959-
'send_raw_large_blocks']
959+
'send_raw_large_blocks', 'send_leak_keymaps']
960960
tags = ['functional', 'rsend']
961961

962962
[tests/functional/scrub_mirror]

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2003,6 +2003,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
20032003
functional/rsend/send_holds.ksh \
20042004
functional/rsend/send_hole_birth.ksh \
20052005
functional/rsend/send_invalid.ksh \
2006+
functional/rsend/send_leak_keymaps.ksh \
20062007
functional/rsend/send-L_toggle.ksh \
20072008
functional/rsend/send_mixed_raw.ksh \
20082009
functional/rsend/send_partial_dataset.ksh \
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/ksh -p
2+
# SPDX-License-Identifier: CDDL-1.0
3+
#
4+
# CDDL HEADER START
5+
#
6+
# This file and its contents are supplied under the terms of the
7+
# Common Development and Distribution License ("CDDL"), version 1.0.
8+
# You may only use this file in accordance with the terms of version
9+
# 1.0 of the CDDL.
10+
#
11+
# A full copy of the text of the CDDL should have accompanied this
12+
# source. A copy of the CDDL is also available via the Internet at
13+
# http://www.illumos.org/license/CDDL.
14+
#
15+
# CDDL HEADER END
16+
#
17+
18+
#
19+
# Copyright (c) 2025 by George Amanakis. All rights reserved.
20+
#
21+
22+
. $STF_SUITE/tests/functional/rsend/rsend.kshlib
23+
24+
#
25+
# DESCRIPTION:
26+
# Verify that an incremental non-raw zfs send from an encrypted filesystem
27+
# does not leak any keys or key mappings.
28+
#
29+
# STRATEGY:
30+
# 1. Create a new encrypted filesystem
31+
# 2. Write some files and create snapshots.
32+
# 3. Send to a new filesystem
33+
# 4. Do an incremental (-I) send and before that access all properties on the
34+
# sending filesystem (emulate sanoid)
35+
# 5. Export and re-import the pool. Upon exporting the pool if any keys/key
36+
# mappings leaked a panic will occur.
37+
#
38+
39+
verify_runnable "both"
40+
41+
function cleanup
42+
{
43+
datasetexists $TESTPOOL/$TESTFS2 && \
44+
destroy_dataset $TESTPOOL/$TESTFS2 -r
45+
datasetexists $TESTPOOL/recv && \
46+
destroy_dataset $TESTPOOL/recv -r
47+
[[ -f $keyfile ]] && log_must rm $keyfile
48+
}
49+
log_onexit cleanup
50+
51+
log_assert "Verify non-raw send with encryption does not leak any key mappings"
52+
53+
typeset keyfile=/$TESTPOOL/pkey
54+
55+
# Create an encrypted dataset
56+
log_must eval "echo 'password' > $keyfile"
57+
log_must zfs create -o encryption=on -o keyformat=passphrase \
58+
-o keylocation=file://$keyfile $TESTPOOL/$TESTFS2
59+
60+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/testfile bs=128K count=4 \
61+
status=none
62+
63+
for i in $(seq 0 20); do
64+
log_note "Taking snapshots"
65+
log_must zfs snapshot $TESTPOOL/$TESTFS2@snap_$i
66+
log_must dd if=/dev/urandom of=/$TESTPOOL/$TESTFS2/testfile bs=128K \
67+
count=4 status=none
68+
done
69+
70+
log_must eval "zfs send $TESTPOOL/$TESTFS2@snap_0 | zfs recv $TESTPOOL/recv"
71+
72+
for i in $(seq 3 3 20); do
73+
log_note "Sending incremental snapshot snap_$((i - 3)) -> snap_$i"
74+
log_must zfs get -Hpd 1 -t snapshot all $TESTPOOL/$TESTFS2 &>/dev/null
75+
log_must eval "zfs send -I $TESTPOOL/$TESTFS2@snap_$((i - 3)) \
76+
$TESTPOOL/$TESTFS2@snap_$i | zfs recv $TESTPOOL/recv"
77+
done
78+
79+
log_must zpool export $TESTPOOL
80+
log_must zpool import $TESTPOOL
81+
82+
log_pass "Verify non-raw send with encryption does not leak any key mappings"

0 commit comments

Comments
 (0)