All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] malloc: fix finding maximum contiguous IOVA size
@ 2018-12-12 11:10 Yongseok Koh
  2018-12-12 11:26 ` Burakov, Anatoly
  0 siblings, 1 reply; 3+ messages in thread
From: Yongseok Koh @ 2018-12-12 11:10 UTC (permalink / raw)
  To: anatoly.burakov; +Cc: dev, stable

malloc_elem_find_max_iova_contig() could return invalid size due to a
missing sanity check. The following gdb output shows how 'cur_size' can be
invalid in find_biggest_element().

	(gdb) p/x cur_size
	$4 = 0xffffffffffe42900
	(gdb) p elem
	$1 = (struct malloc_elem *) 0x12e842000
	(gdb) p *elem
	$2 = {heap = 0x7ffff7ff387c, prev = 0x12e831fc0, next =
		0x12e842900, free_list = {le_next = 0x109538000, le_prev =
		0x7ffff7ff3894}, msl = 0x7ffff7ff107c, state = ELEM_FREE,
		pad = 0, size = 2304}
	(gdb) p *elem->msl
	$5 = {{base_va = 0x100200000, addr_64 = 4297064448}, page_sz =
		2097152, socket_id = 0, version = 790, len = 17179869184,
		external = 0, memseg_arr = {name = "memseg-2048k-0-0",
		'\000' <repeats 47 times>, count = 493, len = 8192, elt_sz
		= 48, data = 0x10002e000, rwlock = {cnt = 0}}}

Fixes: 9fe6bceafd51 ("malloc: add finding biggest free IOVA-contiguous element")
Cc: stable@dpdk.org
Cc: anatoly.burakov@intel.com

Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
---
 lib/librte_eal/common/malloc_elem.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/librte_eal/common/malloc_elem.c b/lib/librte_eal/common/malloc_elem.c
index 9d3dcb6a9e..052aeeb7be 100644
--- a/lib/librte_eal/common/malloc_elem.c
+++ b/lib/librte_eal/common/malloc_elem.c
@@ -38,6 +38,10 @@ malloc_elem_find_max_iova_contig(struct malloc_elem *elem, size_t align)
 	/* segment must start after header and with specified alignment */
 	contig_seg_start = RTE_PTR_ALIGN_CEIL(data_start, align);
 
+	/* return if aligned address is already out of malloc element */
+	if (contig_seg_start > data_end)
+		return 0;
+
 	/* if we're in IOVA as VA mode, or if we're in legacy mode with
 	 * hugepages, all elements are IOVA-contiguous. however, we can only
 	 * make these assumptions about internal memory - externally allocated
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] malloc: fix finding maximum contiguous IOVA size
  2018-12-12 11:10 [PATCH] malloc: fix finding maximum contiguous IOVA size Yongseok Koh
@ 2018-12-12 11:26 ` Burakov, Anatoly
  2018-12-20 14:18   ` [dpdk-stable] " Thomas Monjalon
  0 siblings, 1 reply; 3+ messages in thread
From: Burakov, Anatoly @ 2018-12-12 11:26 UTC (permalink / raw)
  To: Yongseok Koh; +Cc: dev, stable

On 12-Dec-18 11:10 AM, Yongseok Koh wrote:
> malloc_elem_find_max_iova_contig() could return invalid size due to a
> missing sanity check. The following gdb output shows how 'cur_size' can be
> invalid in find_biggest_element().
> 
> 	(gdb) p/x cur_size
> 	$4 = 0xffffffffffe42900
> 	(gdb) p elem
> 	$1 = (struct malloc_elem *) 0x12e842000
> 	(gdb) p *elem
> 	$2 = {heap = 0x7ffff7ff387c, prev = 0x12e831fc0, next =
> 		0x12e842900, free_list = {le_next = 0x109538000, le_prev =
> 		0x7ffff7ff3894}, msl = 0x7ffff7ff107c, state = ELEM_FREE,
> 		pad = 0, size = 2304}
> 	(gdb) p *elem->msl
> 	$5 = {{base_va = 0x100200000, addr_64 = 4297064448}, page_sz =
> 		2097152, socket_id = 0, version = 790, len = 17179869184,
> 		external = 0, memseg_arr = {name = "memseg-2048k-0-0",
> 		'\000' <repeats 47 times>, count = 493, len = 8192, elt_sz
> 		= 48, data = 0x10002e000, rwlock = {cnt = 0}}}
> 
> Fixes: 9fe6bceafd51 ("malloc: add finding biggest free IOVA-contiguous element")
> Cc: stable@dpdk.org
> Cc: anatoly.burakov@intel.com
> 
> Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-stable] [PATCH] malloc: fix finding maximum contiguous IOVA size
  2018-12-12 11:26 ` Burakov, Anatoly
@ 2018-12-20 14:18   ` Thomas Monjalon
  0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2018-12-20 14:18 UTC (permalink / raw)
  To: Yongseok Koh; +Cc: stable, Burakov, Anatoly, dev

12/12/2018 12:26, Burakov, Anatoly:
> On 12-Dec-18 11:10 AM, Yongseok Koh wrote:
> > malloc_elem_find_max_iova_contig() could return invalid size due to a
> > missing sanity check. The following gdb output shows how 'cur_size' can be
> > invalid in find_biggest_element().
> > 
> > 	(gdb) p/x cur_size
> > 	$4 = 0xffffffffffe42900
> > 	(gdb) p elem
> > 	$1 = (struct malloc_elem *) 0x12e842000
> > 	(gdb) p *elem
> > 	$2 = {heap = 0x7ffff7ff387c, prev = 0x12e831fc0, next =
> > 		0x12e842900, free_list = {le_next = 0x109538000, le_prev =
> > 		0x7ffff7ff3894}, msl = 0x7ffff7ff107c, state = ELEM_FREE,
> > 		pad = 0, size = 2304}
> > 	(gdb) p *elem->msl
> > 	$5 = {{base_va = 0x100200000, addr_64 = 4297064448}, page_sz =
> > 		2097152, socket_id = 0, version = 790, len = 17179869184,
> > 		external = 0, memseg_arr = {name = "memseg-2048k-0-0",
> > 		'\000' <repeats 47 times>, count = 493, len = 8192, elt_sz
> > 		= 48, data = 0x10002e000, rwlock = {cnt = 0}}}
> > 
> > Fixes: 9fe6bceafd51 ("malloc: add finding biggest free IOVA-contiguous element")
> > Cc: stable@dpdk.org
> > Cc: anatoly.burakov@intel.com
> > 
> > Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
> > ---
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-20 14:18 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-12 11:10 [PATCH] malloc: fix finding maximum contiguous IOVA size Yongseok Koh
2018-12-12 11:26 ` Burakov, Anatoly
2018-12-20 14:18   ` [dpdk-stable] " Thomas Monjalon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.