DPDK patches and discussions
 help / color / mirror / Atom feed
From: Yongseok Koh <yskoh@mellanox.com>
To: shahafs@mellanox.com, adrien.mazarguil@6wind.com,
	nelio.laranjeiro@6wind.com
Cc: dev@dpdk.org, Yongseok Koh <yskoh@mellanox.com>
Subject: [dpdk-dev] [PATCH 2/4] net/mlx5: fix potential buffer overflow
Date: Fri, 11 May 2018 18:35:43 -0700	[thread overview]
Message-ID: <20180512013545.22279-2-yskoh@mellanox.com> (raw)
In-Reply-To: <20180512013545.22279-1-yskoh@mellanox.com>

Fixes: f0d61f8f8953 ("net/mlx5: add Multi-Packet Rx support")

Signed-off-by: Yongseok Koh <yskoh@mellanox.com>
---
 drivers/net/mlx5/mlx5_rxtx.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c
index 387463792..c887d550f 100644
--- a/drivers/net/mlx5/mlx5_rxtx.c
+++ b/drivers/net/mlx5/mlx5_rxtx.c
@@ -2180,6 +2180,15 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 		 * - Out of buffer in the Mempool for Multi-Packet RQ.
 		 */
 		if (len <= rxq->mprq_max_memcpy_len || rxq->mprq_repl == NULL) {
+			/*
+			 * When memcpy'ing packet due to out-of-buffer, the
+			 * packet must be smaller than the target mbuf.
+			 */
+			if (unlikely(rte_pktmbuf_tailroom(pkt) < len)) {
+				rte_pktmbuf_free_seg(pkt);
+				++rxq->stats.idropped;
+				continue;
+			}
 			rte_memcpy(rte_pktmbuf_mtod(pkt, void *), addr, len);
 		} else {
 			rte_iova_t buf_iova;
@@ -2214,8 +2223,11 @@ mlx5_rx_burst_mprq(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
 			 * Prevent potential overflow due to MTU change through
 			 * kernel interface.
 			 */
-			len = RTE_MIN(len, (uint16_t)(pkt->buf_len -
-						      pkt->data_off));
+			if (unlikely(rte_pktmbuf_tailroom(pkt) < len)) {
+				rte_pktmbuf_free_seg(pkt);
+				++rxq->stats.idropped;
+				continue;
+			}
 		}
 		rxq_cq_to_mbuf(rxq, pkt, cqe, rss_hash_res);
 		PKT_LEN(pkt) = len;
-- 
2.11.0

  reply	other threads:[~2018-05-12  1:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-12  1:35 [dpdk-dev] [PATCH 1/4] net/mlx5: fix offset calculation of Multi-Packet Rx Yongseok Koh
2018-05-12  1:35 ` Yongseok Koh [this message]
2018-05-14 12:03   ` [dpdk-dev] [PATCH 2/4] net/mlx5: fix potential buffer overflow Ferruh Yigit
2018-05-12  1:35 ` [dpdk-dev] [PATCH 3/4] net/mlx5: use coherent I/O memory barrier Yongseok Koh
2018-05-12  1:35 ` [dpdk-dev] [PATCH 4/4] net/mlx5: use correct field in a union structure Yongseok Koh
2018-05-13  6:42 ` [dpdk-dev] [PATCH 1/4] net/mlx5: fix offset calculation of Multi-Packet Rx Shahaf Shuler
2018-05-14 12:04 ` Ferruh Yigit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180512013545.22279-2-yskoh@mellanox.com \
    --to=yskoh@mellanox.com \
    --cc=adrien.mazarguil@6wind.com \
    --cc=dev@dpdk.org \
    --cc=nelio.laranjeiro@6wind.com \
    --cc=shahafs@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).