linux/drivers/md/persistent-data
Mikulas Patocka f49b41c9eb dm-thin: fix metadata refcount underflow
commit 09a65adc7d upstream.

There's a bug in dm-thin in the function rebalance_children. If the
internal btree node has one entry, the code tries to copy all btree
entries from the node's child to the node itself and then decrement the
child's reference count.

If the child node is shared (it has reference count > 1), we won't free
it, so there would be two pointers to each of the grandchildren nodes.
But the reference counts of the grandchildren is not increased, thus the
reference count doesn't match the number of pointers that point to the
grandchildren. This results in "device mapper: space map common: unable
to decrement block" errors.

Fix this bug by incrementing reference counts on the grandchildren if the
btree node is shared.

Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Fixes: 3241b1d3e0 ("dm: add persistent data library")
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2026-06-01 17:35:22 +02:00
..
dm-array.c dm array: fix cursor index when skipping across block boundaries 2025-01-23 17:15:48 +01:00
dm-array.h dm persistent data: add cursor skip functions to the cursor APIs 2017-02-16 13:12:50 -05:00
dm-bitset.c dm persistent data: add cursor skip functions to the cursor APIs 2017-02-16 13:12:50 -05:00
dm-bitset.h dm persistent data: add cursor skip functions to the cursor APIs 2017-02-16 13:12:50 -05:00
dm-block-manager.c dm thin metadata: Fix use-after-free in dm_bm_set_read_only 2020-09-02 13:38:40 -04:00
dm-block-manager.h dm block manager: remove an unused argument from dm_block_manager_create() 2017-04-27 17:08:41 -04:00
dm-btree-internal.h dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
dm-btree-remove.c dm-thin: fix metadata refcount underflow 2026-06-01 17:35:22 +02:00
dm-btree-spine.c dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
dm-btree.c dm btree: add a defensive bounds check to insert_at() 2022-01-27 11:04:52 +01:00
dm-btree.h dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
dm-persistent-data-internal.h dm: add persistent data library 2011-10-31 20:19:11 +00:00
dm-space-map-common.c dm space map common: add bounds check to sm_ll_lookup_bitmap() 2022-01-27 11:04:53 +01:00
dm-space-map-common.h dm space map disk: cache a small number of index entries 2021-06-04 12:07:23 -04:00
dm-space-map-disk.c dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
dm-space-map-disk.h dm: add persistent data library 2011-10-31 20:19:11 +00:00
dm-space-map-metadata.c dm persistent data: fix memory allocation failure 2024-09-04 13:23:16 +02:00
dm-space-map-metadata.h dm thin: allow metadata space larger than supported to go unused 2014-02-27 11:49:08 -05:00
dm-space-map.h dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
dm-transaction-manager.c dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
dm-transaction-manager.h dm space maps: improve performance with inc/dec on ranges of blocks 2021-06-04 12:07:22 -04:00
Kconfig treewide: replace '---help---' in Kconfig files with 'help' 2020-06-14 01:57:21 +09:00
Makefile License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00