Commit ed8b45a3 authored by Joe Thornber's avatar Joe Thornber Committed by Mike Snitzer

dm btree: fix bufio buffer leaks in dm_btree_del() error path

If dm_btree_del()'s call to push_frame() fails, e.g. due to
btree_node_validator finding invalid metadata, the dm_btree_del() error
path must unlock all frames (which have active dm-bufio buffers) that
were pushed onto the del_stack.

Otherwise, dm_bufio_client_destroy() will BUG_ON() because dm-bufio
buffers have leaked, e.g.:
  device-mapper: bufio: leaked buffer 3, hold count 1, list 0
Signed-off-by: default avatarJoe Thornber <ejt@redhat.com>
Signed-off-by: default avatarMike Snitzer <snitzer@redhat.com>
Cc: stable@vger.kernel.org
parent 50dd842a
...@@ -257,6 +257,16 @@ static void pop_frame(struct del_stack *s) ...@@ -257,6 +257,16 @@ static void pop_frame(struct del_stack *s)
dm_tm_unlock(s->tm, f->b); dm_tm_unlock(s->tm, f->b);
} }
static void unlock_all_frames(struct del_stack *s)
{
struct frame *f;
while (unprocessed_frames(s)) {
f = s->spine + s->top--;
dm_tm_unlock(s->tm, f->b);
}
}
int dm_btree_del(struct dm_btree_info *info, dm_block_t root) int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
{ {
int r; int r;
...@@ -313,9 +323,13 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root) ...@@ -313,9 +323,13 @@ int dm_btree_del(struct dm_btree_info *info, dm_block_t root)
pop_frame(s); pop_frame(s);
} }
} }
out: out:
if (r) {
/* cleanup all frames of del_stack */
unlock_all_frames(s);
}
kfree(s); kfree(s);
return r; return r;
} }
EXPORT_SYMBOL_GPL(dm_btree_del); EXPORT_SYMBOL_GPL(dm_btree_del);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment