Commit 40a74870 authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Mike Marshall

orangefs: Fix the size of a memory allocation in orangefs_bufmap_alloc()

'buffer_index_array' really looks like a bitmap. So it should be allocated
as such.
When kzalloc is called, a number of bytes is expected, but a number of
longs is passed instead.

In get(), if not enough memory is allocated, un-allocated memory may be
read or written.

So use bitmap_zalloc() to safely allocate the correct memory size and
avoid un-expected behavior.

While at it, change the corresponding kfree() into bitmap_free() to keep
the semantic.

Fixes: ea2c9c9f ("orangefs: bufmap rewrite")
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarMike Marshall <hubcap@omnibond.com>
parent 063e458c
...@@ -176,7 +176,7 @@ orangefs_bufmap_free(struct orangefs_bufmap *bufmap) ...@@ -176,7 +176,7 @@ orangefs_bufmap_free(struct orangefs_bufmap *bufmap)
{ {
kfree(bufmap->page_array); kfree(bufmap->page_array);
kfree(bufmap->desc_array); kfree(bufmap->desc_array);
kfree(bufmap->buffer_index_array); bitmap_free(bufmap->buffer_index_array);
kfree(bufmap); kfree(bufmap);
} }
...@@ -226,8 +226,7 @@ orangefs_bufmap_alloc(struct ORANGEFS_dev_map_desc *user_desc) ...@@ -226,8 +226,7 @@ orangefs_bufmap_alloc(struct ORANGEFS_dev_map_desc *user_desc)
bufmap->desc_size = user_desc->size; bufmap->desc_size = user_desc->size;
bufmap->desc_shift = ilog2(bufmap->desc_size); bufmap->desc_shift = ilog2(bufmap->desc_size);
bufmap->buffer_index_array = bufmap->buffer_index_array = bitmap_zalloc(bufmap->desc_count, GFP_KERNEL);
kzalloc(DIV_ROUND_UP(bufmap->desc_count, BITS_PER_LONG), GFP_KERNEL);
if (!bufmap->buffer_index_array) if (!bufmap->buffer_index_array)
goto out_free_bufmap; goto out_free_bufmap;
...@@ -250,7 +249,7 @@ orangefs_bufmap_alloc(struct ORANGEFS_dev_map_desc *user_desc) ...@@ -250,7 +249,7 @@ orangefs_bufmap_alloc(struct ORANGEFS_dev_map_desc *user_desc)
out_free_desc_array: out_free_desc_array:
kfree(bufmap->desc_array); kfree(bufmap->desc_array);
out_free_index_array: out_free_index_array:
kfree(bufmap->buffer_index_array); bitmap_free(bufmap->buffer_index_array);
out_free_bufmap: out_free_bufmap:
kfree(bufmap); kfree(bufmap);
out: out:
......
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