From: Ferruh Yigit Date: Wed, 24 Jun 2020 09:35:20 +0000 (+0100) Subject: ethdev: verify reserved HW ring X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=cacd2bb786b80e19417d9ea4b85c90e97533d378;p=dpdk.git ethdev: verify reserved HW ring Function 'rte_eth_dma_zone_reserve()' returns an existing memzone based on name match, but other requested attributes are discarded. This may cause driver using a memzone with wrong size or alignment. Verify size, alignment and socket_id for matched memzone, and do not use memzone if any one of the attributes are not justified. It is possible to free the existing memzone and allocate again with the requested attributes but it is better caller do the explicit free. Reported-by: Renata Saiakhova Signed-off-by: Ferruh Yigit Reviewed-by: Andrew Rybchenko --- diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 5f10f2d8d2..7022bd7f56 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -4200,8 +4200,18 @@ rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name, } mz = rte_memzone_lookup(z_name); - if (mz) + if (mz) { + if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) || + size > mz->len || + ((uintptr_t)mz->addr & (align - 1)) != 0) { + RTE_ETHDEV_LOG(ERR, + "memzone %s does not justify the requested attributes\n", + mz->name); + return NULL; + } + return mz; + } return rte_memzone_reserve_aligned(z_name, size, socket_id, RTE_MEMZONE_IOVA_CONTIG, align);