Raw receive should change key atomically

Currently, raw zfs sends transfer the encrypted master keys and
objset_phys_t encryption parameters in the DRR_BEGIN payload of
each send file. Both of these are processed as soon as they are
read in dmu_recv_stream(), meaning that the new keys are set
before the new snapshot is received. In addition to the fact that
this changes the user's keys for the dataset earlier than they
might expect, the keys were never reset to what they originally
were in the event that the receive failed. This patch splits the
processing into objset handling and key handling, the later of
which is moved to dmu_recv_end() so that they key change can be
done atomically.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tom Caputi <tcaputi@datto.com>
Closes #7200
This commit is contained in:
Tom Caputi
2018-02-21 15:31:03 -05:00
committed by Brian Behlendorf
parent 4a385862b7
commit b0918402dc
5 changed files with 312 additions and 225 deletions
@@ -30,9 +30,12 @@
# 3. Create a file and get its checksum
# 4. Snapshot the dataset
# 5. Attempt to receive a raw send stream of the first snapshot
# 6. Attempt to receive a raw incremental send stream of the second snapshot
# 7. Attempt load the key and mount the dataset
# 8. Verify the cheksum of the file is the same as the original
# 6. Change the passphrase required to unlock the original filesystem
# 7. Attempt and intentionally fail to receive the second snapshot
# 8. Verify that the required passphrase hasn't changed on the receive side
# 9. Attempt a real raw incremental send stream of the second snapshot
# 10. Attempt load the key and mount the dataset
# 11. Verify the checksum of the file is the same as the original
#
verify_runnable "both"
@@ -44,13 +47,18 @@ function cleanup
datasetexists $TESTPOOL/$TESTFS2 && \
log_must zfs destroy -r $TESTPOOL/$TESTFS2
[[ -f $ibackup ]] && log_must rm -f $ibackup
}
log_onexit cleanup
log_assert "ZFS should receive streams from raw incremental sends"
typeset ibackup="/var/tmp/ibackup.$$"
typeset ibackup_trunc="/var/tmp/ibackup_trunc.$$"
typeset passphrase="password"
typeset passphrase2="password2"
typeset snap1="$TESTPOOL/$TESTFS1@snap1"
typeset snap2="$TESTPOOL/$TESTFS1@snap2"
@@ -65,8 +73,20 @@ typeset checksum=$(md5sum /$TESTPOOL/$TESTFS1/$TESTFILE0 | awk '{ print $1 }')
log_must zfs snapshot $snap2
log_must eval "zfs send -w $snap1 | zfs receive $TESTPOOL/$TESTFS2"
log_must eval "zfs send -w -i $snap1 $snap2 | zfs receive $TESTPOOL/$TESTFS2"
log_must eval "echo $passphrase | zfs mount -l $TESTPOOL/$TESTFS2"
log_must eval "echo $passphrase2 | zfs change-key $TESTPOOL/$TESTFS1"
log_must eval "zfs send -w -i $snap1 $snap2 > $ibackup"
typeset trunc_size=$(stat -c %s $ibackup)
trunc_size=$(expr $trunc_size - 64)
log_must cp $ibackup $ibackup_trunc
log_must truncate -s $trunc_size $ibackup_trunc
log_mustnot eval "zfs receive $TESTPOOL/$TESTFS2 < $ibackup_trunc"
log_mustnot eval "echo $passphrase2 | zfs load-key $TESTPOOL/$TESTFS2"
log_must eval "echo $passphrase | zfs load-key $TESTPOOL/$TESTFS2"
log_must zfs unload-key $TESTPOOL/$TESTFS2
log_must eval "zfs receive $TESTPOOL/$TESTFS2 < $ibackup"
log_must eval "echo $passphrase2 | zfs mount -l $TESTPOOL/$TESTFS2"
typeset cksum1=$(md5sum /$TESTPOOL/$TESTFS2/$TESTFILE0 | awk '{ print $1 }')
[[ "$cksum1" == "$checksum" ]] || \