lkml.org 
[lkml]   [2022]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH 4.19 014/239] orangefs: Fix the size of a memory allocation in orangefs_bufmap_alloc()
    Date
    From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

    commit 40a74870b2d1d3d44e13b3b73c6571dd34f5614d upstream.

    '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: ea2c9c9f6574 ("orangefs: bufmap rewrite")
    Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
    Signed-off-by: Mike Marshall <hubcap@omnibond.com>
    Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
    ---
    fs/orangefs/orangefs-bufmap.c | 7 +++----
    1 file changed, 3 insertions(+), 4 deletions(-)

    --- a/fs/orangefs/orangefs-bufmap.c
    +++ b/fs/orangefs/orangefs-bufmap.c
    @@ -179,7 +179,7 @@ orangefs_bufmap_free(struct orangefs_buf
    {
    kfree(bufmap->page_array);
    kfree(bufmap->desc_array);
    - kfree(bufmap->buffer_index_array);
    + bitmap_free(bufmap->buffer_index_array);
    kfree(bufmap);
    }

    @@ -229,8 +229,7 @@ orangefs_bufmap_alloc(struct ORANGEFS_de
    bufmap->desc_size = user_desc->size;
    bufmap->desc_shift = ilog2(bufmap->desc_size);

    - bufmap->buffer_index_array =
    - kzalloc(DIV_ROUND_UP(bufmap->desc_count, BITS_PER_LONG), GFP_KERNEL);
    + bufmap->buffer_index_array = bitmap_zalloc(bufmap->desc_count, GFP_KERNEL);
    if (!bufmap->buffer_index_array)
    goto out_free_bufmap;

    @@ -253,7 +252,7 @@ orangefs_bufmap_alloc(struct ORANGEFS_de
    out_free_desc_array:
    kfree(bufmap->desc_array);
    out_free_index_array:
    - kfree(bufmap->buffer_index_array);
    + bitmap_free(bufmap->buffer_index_array);
    out_free_bufmap:
    kfree(bufmap);
    out:

    \
     
     \ /
      Last update: 2022-01-24 20:40    [W:2.660 / U:1.780 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site