When __create_snap() fails after the mapping tree insertion, the error
path at the bad: label tries to revert the details tree, which is
unnecessary. The details entry is not present during __create_snap(),
so dm_btree_remove() returns -ENODATA.

The failed removal leaves the metadata inconsistent. Even on -ENODATA,
the removal is not a no-op. It leaks shadow copies and drops the old
root's reference count, while details_root still points at the old root.
The next metadata commit writes this stale details_root and the leaked
blocks to disk, corrupting the metadata.

Fix by removing the dm_btree_remove() call on the details tree.

Fixes: 991d9fa02da0 ("dm: add thin provisioning target")
Signed-off-by: Ming-Hung Tsai <[email protected]>
---
 drivers/md/dm-thin-metadata.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
index 03df0b1aab78..88c3342ef4df 100644
--- a/drivers/md/dm-thin-metadata.c
+++ b/drivers/md/dm-thin-metadata.c
@@ -1234,8 +1234,6 @@ static int __create_snap(struct dm_pool_metadata *pmd,
        kfree(td);
 bad:
        dm_btree_remove(&pmd->tl_info, pmd->root, &key, &pmd->root);
-       dm_btree_remove(&pmd->details_info, pmd->details_root,
-                       &key, &pmd->details_root);
        return r;
 }
 
-- 
2.49.0


Reply via email to