[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211207175110.GB70682@nvidia.com>
Date: Tue, 7 Dec 2021 13:51:10 -0400
From: Jason Gunthorpe <jgg@...dia.com>
To: Christophe JAILLET <christophe.jaillet@...adoo.fr>
Cc: mustafa.ismail@...el.com, shiraz.saleem@...el.com,
linux-rdma@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org
Subject: Re: [PATCH] RDMA/irdma: Fix a potential memory allocation issue in
'irdma_prm_add_pble_mem()'
On Sun, Dec 05, 2021 at 09:17:24AM +0100, Christophe JAILLET wrote:
> 'pchunk->bitmapbuf' is a bitmap. Its size (in number of bits) is stored in
> 'pchunk->sizeofbitmap'.
>
> When it is allocated, the size (in bytes) is computed by:
> size_in_bits >> 3
>
> There are 2 issues (numbers bellow assume that longs are 64 bits):
> - there is no guarantee here that 'pchunk->bitmapmem.size' is modulo
> BITS_PER_LONG but bitmaps are stored as longs
> (sizeofbitmap=8 bits will only allocate 1 byte, instead of 8 (1 long))
>
> - the number of bytes is computed with a shift, not a round up, so we
> may allocate less memory than needed
> (sizeofbitmap=65 bits will only allocate 8 bytes (i.e. 1 long), when 2
> longs are needed = 16 bytes)
>
> Fix both issues by using 'bitmap_zalloc()' and remove the useless
> 'bitmapmem' from 'struct irdma_chunk'.
>
> While at it, remove some useless NULL test before calling
> kfree/bitmap_free.
>
> Fixes: 915cc7ac0f8e ("RDMA/irdma: Add miscellaneous utility definitions")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@...adoo.fr>
> ---
> drivers/infiniband/hw/irdma/pble.c | 6 ++----
> drivers/infiniband/hw/irdma/pble.h | 1 -
> drivers/infiniband/hw/irdma/utils.c | 9 ++-------
> 3 files changed, 4 insertions(+), 12 deletions(-)
Applied to for-rc, thanks
Jason
Powered by blists - more mailing lists