From: Ilya Dryomov Date: Fri, 21 May 2021 13:27:31 +0000 (+0200) Subject: librbd/cache/pwl/ssd: ensure first_{valid,free}_entry aren't bogus X-Git-Tag: v16.2.7~50^2~12 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=b263230f8e80a5f209eb71f19f171059b64b8a9e;p=ceph.git librbd/cache/pwl/ssd: ensure first_{valid,free}_entry aren't bogus Ensure first_{valid,free}_entry are inside the expected range when scheduling root updates and decoding the root on recovery. Signed-off-by: Ilya Dryomov (cherry picked from commit b46f81fbb22e67548e9825756da625d8e9017d10) --- diff --git a/src/librbd/cache/pwl/ssd/WriteLog.cc b/src/librbd/cache/pwl/ssd/WriteLog.cc index 56f73941f36c..7e7fc42e8656 100644 --- a/src/librbd/cache/pwl/ssd/WriteLog.cc +++ b/src/librbd/cache/pwl/ssd/WriteLog.cc @@ -42,6 +42,16 @@ static bool is_valid_pool_root(const WriteLogPoolRoot& root) { root.first_free_entry % MIN_WRITE_ALLOC_SSD_SIZE == 0; } +static bool is_valid_pool_root(const WriteLogPoolRoot& root) { + return root.pool_size % MIN_WRITE_ALLOC_SSD_SIZE == 0 && + root.first_valid_entry >= DATA_RING_BUFFER_OFFSET && + root.first_valid_entry < root.pool_size && + root.first_valid_entry % MIN_WRITE_ALLOC_SSD_SIZE == 0 && + root.first_free_entry >= DATA_RING_BUFFER_OFFSET && + root.first_free_entry < root.pool_size && + root.first_free_entry % MIN_WRITE_ALLOC_SSD_SIZE == 0; +} + template Builder>* WriteLog::create_builder() { m_builderobj = new Builder();