From 417fb4e10817e0448b9ea119302ca2f2d3e9cd17 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Tue, 1 Aug 2023 13:55:43 +0200 Subject: [PATCH] tresor: fix bad hash update during rekeying in vbd The re-keying state machine in the VBD module would use block data of the wrong block for the hash update of an inner node in a certain circumstance. On re-keying, the VBD iterates for a given VBA over all snapshots, beginning with the newest and re-keys the VBA in each of the snapshots. At each snapshot it therefore loads the branch of the VBA top-down, and then updates the branch bottom-up. However, if loading a certain level of the branch of a certain snapshot runs into the same physical block as with the last snapshot on this level, the algorithm turns around and updates the branch from this point upwards instead of going further down the whole way to the leaf. This is because everything below this point has already been re-keyed in the course of a newer snapshot. The case where this turning around is not right above the leaf (i.e., the first shared physical block is a metadata block) that's were the bug was located. In this situation, we have to re-encode the highest shared metadata block into a buffer again before starting to update. The update code acts as if the mentioned block was just written back (which is true when going down all the way to the leaf before updating) and consequently is present in the encoded buffer. Ref #4971 --- repos/gems/src/lib/tresor/virtual_block_device.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/repos/gems/src/lib/tresor/virtual_block_device.cc b/repos/gems/src/lib/tresor/virtual_block_device.cc index 0709ba45cb..9ffffbe0e4 100644 --- a/repos/gems/src/lib/tresor/virtual_block_device.cc +++ b/repos/gems/src/lib/tresor/virtual_block_device.cc @@ -1299,6 +1299,7 @@ void Virtual_block_device::_execute_rekey_vba(Channel &chan, break; chan._log_rekeying_pba_alloc(); + chan._t1_blks.items[chan._t1_blk_idx].encode_to_blk(chan._encoded_blk); chan._state = Channel::WRITE_INNER_NODE_COMPLETED; if (VERBOSE_REKEYING)