ring: fix overflow in memory size calculation
authorZhihong Wang <wangzhihong.wzh@bytedance.com>
Tue, 14 Dec 2021 03:30:16 +0000 (11:30 +0800)
committerDavid Marchand <david.marchand@redhat.com>
Sat, 5 Feb 2022 17:15:33 +0000 (18:15 +0100)
Parameters count and esize are both unsigned int, and their product can
legaly exceed unsigned int and lead to runtime access violation.

Fixes: cc4b218790f6 ("ring: support configurable element size")
Cc: stable@dpdk.org
Signed-off-by: Zhihong Wang <wangzhihong.wzh@bytedance.com>
Reviewed-by: Liang Ma <liangma@liangbit.com>
Reviewed-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
lib/ring/rte_ring.c

index 185f9be..6a94a03 100644 (file)
@@ -75,7 +75,7 @@ rte_ring_get_memsize_elem(unsigned int esize, unsigned int count)
                return -EINVAL;
        }
 
-       sz = sizeof(struct rte_ring) + count * esize;
+       sz = sizeof(struct rte_ring) + (ssize_t)count * esize;
        sz = RTE_ALIGN(sz, RTE_CACHE_LINE_SIZE);
        return sz;
 }