dm btree: fix leak of bufio-backed block in btree_split_sibling error path

This change “dm btree: fix leak of bufio-backed block in btree_split_sibling error path” in Linux kernel is authored by Mike Snitzer <snitzer [at] redhat.com> on Mon Nov 23 16:24:45 2015 -0500.

dm btree: fix leak of bufio-backed block in btree_split_sibling error path

The block allocated at the start of btree_split_sibling() is never
released if later insert_at() fails.

Fix this by releasing the previously allocated bufio block using
unlock_block().

Reported-by: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 30ce6e1.

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/md/persistent-data/dm-btree.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/md/persistent-data/dm-btree.c b/drivers/md/persistent-data/dm-btree.c
index c573402..0918a7c 100644
--- a/drivers/md/persistent-data/dm-btree.c
+++ b/drivers/md/persistent-data/dm-btree.c
@@ -473,8 +473,10 @@ static int btree_split_sibling(struct shadow_spine *s, unsigned parent_index,
 
 	r = insert_at(sizeof(__le64), pn, parent_index + 1,
 		      le64_to_cpu(rn->keys[0]), &location);
-	if (r)
+	if (r) {
+		unlock_block(s->info, right);
 		return r;
+	}
 
 	if (key < le64_to_cpu(rn->keys[0])) {
 		unlock_block(s->info, right);

The commit for this change in Linux stable tree is 30ce6e1 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *