]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
dm-thin: fix metadata refcount underflow
authorMikulas Patocka <mpatocka@redhat.com>
Mon, 20 Apr 2026 17:56:44 +0000 (19:56 +0200)
committerMikulas Patocka <mpatocka@redhat.com>
Mon, 20 Apr 2026 17:56:44 +0000 (19:56 +0200)
commit09a65adc7d8bbfce06392cb6d375468e2728ead5
tree6cbdebd3c238239725d8b6479c5fa57723f0db81
parent028ef9c96e96197026887c0f092424679298aae8
dm-thin: fix metadata refcount underflow

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: 3241b1d3e0aa ("dm: add persistent data library")
Cc: stable@vger.kernel.org
drivers/md/persistent-data/dm-btree-remove.c