[v2] bitmap: fix buffer overrun in bitmap init function

Message ID 20210602094922.3507384-1-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [v2] bitmap: fix buffer overrun in bitmap init function |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Andrew Rybchenko June 2, 2021, 9:49 a.m. UTC
  From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>

Bitmap initialization function is allowed to memset()
caller-provided buffer with number of bytes exceeded
this buffer size. This happens due to wrong comparison
sign between buffer size and number of bytes required
to initialize bitmap.

Fixes: 602c9ca33a4 ("sched: bitmap is now dynamically allocated")
Cc: stable@dpdk.org

Reported-by: Andy Moreton <amoreton@xilinx.com>
Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
Reviewed-by: Andy Moreton <amoreton@xilinx.com>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 lib/eal/include/rte_bitmap.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
  

Comments

Cristian Dumitrescu June 8, 2021, 10:25 a.m. UTC | #1
> -----Original Message-----
> From: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Sent: Wednesday, June 2, 2021 10:49 AM
> To: Dumitrescu, Cristian <cristian.dumitrescu@intel.com>
> Cc: dev@dpdk.org; Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>;
> stable@dpdk.org; Andy Moreton <amoreton@xilinx.com>
> Subject: [PATCH v2] bitmap: fix buffer overrun in bitmap init function
> 
> From: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> 
> Bitmap initialization function is allowed to memset()
> caller-provided buffer with number of bytes exceeded
> this buffer size. This happens due to wrong comparison
> sign between buffer size and number of bytes required
> to initialize bitmap.
> 
> Fixes: 602c9ca33a4 ("sched: bitmap is now dynamically allocated")
> Cc: stable@dpdk.org
> 
> Reported-by: Andy Moreton <amoreton@xilinx.com>
> Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> Reviewed-by: Andy Moreton <amoreton@xilinx.com>
> Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> ---
>  lib/eal/include/rte_bitmap.h | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/lib/eal/include/rte_bitmap.h b/lib/eal/include/rte_bitmap.h
> index 9e2b8f2cbf..e4623bb176 100644
> --- a/lib/eal/include/rte_bitmap.h
> +++ b/lib/eal/include/rte_bitmap.h
> @@ -185,9 +185,8 @@ rte_bitmap_init(uint32_t n_bits, uint8_t *mem,
> uint32_t mem_size)
>  	size = __rte_bitmap_get_memory_footprint(n_bits,
>  		&array1_byte_offset, &array1_slabs,
>  		&array2_byte_offset, &array2_slabs);
> -	if (size < mem_size) {
> +	if (size > mem_size)
>  		return NULL;
> -	}
> 
>  	/* Setup bitmap */
>  	memset(mem, 0, size);
> --
> 2.30.2

Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
  
David Marchand June 11, 2021, 9:13 a.m. UTC | #2
On Tue, Jun 8, 2021 at 12:27 PM Dumitrescu, Cristian
<cristian.dumitrescu@intel.com> wrote:
> > Bitmap initialization function is allowed to memset()
> > caller-provided buffer with number of bytes exceeded
> > this buffer size. This happens due to wrong comparison
> > sign between buffer size and number of bytes required
> > to initialize bitmap.
> >
> > Fixes: 602c9ca33a4 ("sched: bitmap is now dynamically allocated")
> > Cc: stable@dpdk.org
> >
> > Reported-by: Andy Moreton <amoreton@xilinx.com>
> > Signed-off-by: Ivan Ilchenko <ivan.ilchenko@oktetlabs.ru>
> > Reviewed-by: Andy Moreton <amoreton@xilinx.com>
> > Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>

Applied, thanks.
  

Patch

diff --git a/lib/eal/include/rte_bitmap.h b/lib/eal/include/rte_bitmap.h
index 9e2b8f2cbf..e4623bb176 100644
--- a/lib/eal/include/rte_bitmap.h
+++ b/lib/eal/include/rte_bitmap.h
@@ -185,9 +185,8 @@  rte_bitmap_init(uint32_t n_bits, uint8_t *mem, uint32_t mem_size)
 	size = __rte_bitmap_get_memory_footprint(n_bits,
 		&array1_byte_offset, &array1_slabs,
 		&array2_byte_offset, &array2_slabs);
-	if (size < mem_size) {
+	if (size > mem_size)
 		return NULL;
-	}
 
 	/* Setup bitmap */
 	memset(mem, 0, size);