DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v3] net/mlx5: fix possible NULL deref in Rx path
@ 2016-08-02 14:41 Sagi Grimberg
  2016-09-19 15:06 ` Bruce Richardson
  0 siblings, 1 reply; 2+ messages in thread
From: Sagi Grimberg @ 2016-08-02 14:41 UTC (permalink / raw)
  To: dev; +Cc: Adrien Mazarguil

The user is allowed to call ->rx_pkt_burst() even without free
mbufs in the pool. In this scenario we'll fail allocating a rep mbuf
on the first iteration (where pkt is still NULL). This would cause us
to deref a NULL pkt (reset refcount and free).

Fix this by checking the pkt before freeing it.

Fixes: a1bdb71a32da ("net/mlx5: fix crash in Rx")

Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
---
Changes from v2:
- fix check-git-log.sh complaints
- collected acked-by tag

Changes from v1:
- check pkt only once in case we failed to allocate a buffer

 drivers/net/mlx5/mlx5_rxtx.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c
index fce3381ae87a..37573668e43e 100644
--- a/drivers/net/mlx5/mlx5_rxtx.c
+++ b/drivers/net/mlx5/mlx5_rxtx.c
@@ -1572,6 +1572,14 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		rte_prefetch0(wqe);
 		rep = rte_mbuf_raw_alloc(rxq->mp);
 		if (unlikely(rep == NULL)) {
+			++rxq->stats.rx_nombuf;
+			if (!pkt) {
+				/*
+				 * no buffers before we even started,
+				 * bail out silently.
+				 */
+				break;
+			}
 			while (pkt != seg) {
 				assert(pkt != (*rxq->elts)[idx]);
 				seg = NEXT(pkt);
@@ -1579,7 +1587,6 @@ mlx5_rx_burst(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 				__rte_mbuf_raw_free(pkt);
 				pkt = seg;
 			}
-			++rxq->stats.rx_nombuf;
 			break;
 		}
 		if (!pkt) {
-- 
1.9.1

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

* Re: [dpdk-dev] [PATCH v3] net/mlx5: fix possible NULL deref in Rx path
  2016-08-02 14:41 [dpdk-dev] [PATCH v3] net/mlx5: fix possible NULL deref in Rx path Sagi Grimberg
@ 2016-09-19 15:06 ` Bruce Richardson
  0 siblings, 0 replies; 2+ messages in thread
From: Bruce Richardson @ 2016-09-19 15:06 UTC (permalink / raw)
  To: Sagi Grimberg; +Cc: dev, Adrien Mazarguil

On Tue, Aug 02, 2016 at 05:41:21PM +0300, Sagi Grimberg wrote:
> The user is allowed to call ->rx_pkt_burst() even without free
> mbufs in the pool. In this scenario we'll fail allocating a rep mbuf
> on the first iteration (where pkt is still NULL). This would cause us
> to deref a NULL pkt (reset refcount and free).
> 
> Fix this by checking the pkt before freeing it.
> 
> Fixes: a1bdb71a32da ("net/mlx5: fix crash in Rx")
> 
> Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
> Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
> ---
Applied to dpdk-next-net/rel_16_11

/Bruce

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

end of thread, other threads:[~2016-09-19 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-02 14:41 [dpdk-dev] [PATCH v3] net/mlx5: fix possible NULL deref in Rx path Sagi Grimberg
2016-09-19 15:06 ` Bruce Richardson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).