From aef7e7ccce8ecf328c4e7963da662fba87085d9f Mon Sep 17 00:00:00 2001 From: Christopher Hoffman Date: Tue, 17 Jun 2025 16:44:08 +0000 Subject: [PATCH] client: Fix logic in fscrypt hole optimization In fscrypt decryption code path, ensure if a data block is hit when there are holes present in adjacent blocks, that we exit hole traversal and continue on to decrypt the block. Fixes: https://tracker.ceph.com/issues/71602 Signed-off-by: Christopher Hoffman --- src/client/FSCrypt.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/client/FSCrypt.cc b/src/client/FSCrypt.cc index d3f162c8af2..edb38898aff 100644 --- a/src/client/FSCrypt.cc +++ b/src/client/FSCrypt.cc @@ -898,11 +898,25 @@ int FSCryptFDataDenc::decrypt_bl(uint64_t off, uint64_t len, uint64_t pos, const while (pos < target_end) { bool has_hole = false; + /* + * Check to see if cur_block is part of a + * hole. We expect holes to ordered by offset. + * + * There is four states it can be in + * 1. If position is before hole offset, it cannot be part of a hole + * 2. If hole end is less than position, hole occurs completely before + * 3. If hole starts after target_end, hole occurs completely after + * 4. No conditionals are met, is a hole + */ + while (hiter != holes.end()) { uint64_t hofs = hiter->first; uint64_t hlen = hiter->second; uint64_t hend = hofs + hlen - 1; + if (pos < hofs) + break; + if (hend < pos) { ++hiter; continue; -- 2.39.5