crypto/aesni_mb: fix possible array overrun
authorPablo de Lara <pablo.de.lara.guarch@intel.com>
Thu, 2 Aug 2018 04:49:40 +0000 (05:49 +0100)
committerAkhil Goyal <akhil.goyal@nxp.com>
Tue, 25 Sep 2018 15:57:25 +0000 (17:57 +0200)
commit95978a85a410e7fa1a03d4f3b90c8770f7f29e72
treea735f7999e0bc4ef9bee0d80f79dbd767164a93e
parentc61518ed86a02118322c9250be1797a58e3974ba
crypto/aesni_mb: fix possible array overrun

In order to process crypto operations in the AESNI MB PMD,
they need to be sent to the buffer manager of the Multi-buffer library,
through the "job" structure.

Currently, it is checked if there are outstanding operations to process
in the ring, before getting a new job. However, if there are no available
jobs in the manager, a flush operation needs to take place, freeing some
of the jobs, so it can be used for the outstanding operation.

In order to avoid leaving the dequeued operation without being processed,
the maximum number of operations that can be flushed is the remaining
operations to return, which is the maximum number of operations that can
be return minus the number of operations ready to be returned
(nb_ops - processed_jobs), minus 1 (for the new operation).

The problem comes when (nb_ops - processed_jobs) is 1 (last operation to
dequeue). In that case, flush_mb_mgr is called with maximum number of
operations equal to 0, which is wrong, causing a potential overrun in the
"ops" array.
Besides, the operation dequeued from the ring will be leaked, as no more
operations can be returned.

The solution is to first check if there are jobs available in the manager.
If there are not, flush operation gets called, and if enough operations
are returned from the manager, then no more outstanding operations get
dequeued from the ring, avoiding both the memory leak and the array
overrun.
If there are enough jobs, PMD tries to dequeue an operation from the ring.
If there are no operations in the ring, the new job pointer is not used,
and it will be used in the next get_next_job call, so no memory leak
happens.

Fixes: 0f548b50a160 ("crypto/aesni_mb: process crypto op on dequeue")
Cc: stable@dpdk.org
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
drivers/crypto/aesni_mb/rte_aesni_mb_pmd.c