[dpdk-dev] [PATCH 09/12] net/sfc: add TSO header length check to Tx prepare

Andrew Rybchenko arybchenko at solarflare.com
Tue Apr 2 11:28:41 CEST 2019


From: Igor Romanov <igor.romanov at oktetlabs.ru>

Make Tx prepare function able to detect packets with invalid header
size when header linearization is required.

Signed-off-by: Igor Romanov <igor.romanov at oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <arybchenko at solarflare.com>
---
 drivers/net/sfc/sfc_dp_tx.h   | 11 ++++++++++-
 drivers/net/sfc/sfc_ef10_tx.c |  2 ++
 drivers/net/sfc/sfc_tso.c     |  2 ++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/drivers/net/sfc/sfc_dp_tx.h b/drivers/net/sfc/sfc_dp_tx.h
index ebc941857..ae5524f24 100644
--- a/drivers/net/sfc/sfc_dp_tx.h
+++ b/drivers/net/sfc/sfc_dp_tx.h
@@ -14,6 +14,7 @@
 
 #include "sfc_dp.h"
 #include "sfc_debug.h"
+#include "sfc_tso.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -230,8 +231,16 @@ sfc_dp_tx_prepare_pkt(struct rte_mbuf *m,
 		 * Extra descriptor that is required when a packet header
 		 * is separated from remaining content of the first segment.
 		 */
-		if (rte_pktmbuf_data_len(m) > header_len)
+		if (rte_pktmbuf_data_len(m) > header_len) {
 			descs_required++;
+		} else if (rte_pktmbuf_data_len(m) < header_len &&
+			 unlikely(header_len > SFC_TSOH_STD_LEN)) {
+			/*
+			 * Header linearization is required and
+			 * the header is too big to be linearized
+			 */
+			return EINVAL;
+		}
 	}
 
 	/*
diff --git a/drivers/net/sfc/sfc_ef10_tx.c b/drivers/net/sfc/sfc_ef10_tx.c
index e7ab993dd..959408449 100644
--- a/drivers/net/sfc/sfc_ef10_tx.c
+++ b/drivers/net/sfc/sfc_ef10_tx.c
@@ -447,6 +447,8 @@ sfc_ef10_xmit_tso_pkt(struct sfc_ef10_txq * const txq, struct rte_mbuf *m_seg,
 		/*
 		 * Discard a packet if header linearization is needed but
 		 * the header is too big.
+		 * Duplicate Tx prepare check here to avoid spoil of
+		 * memory if Tx prepare is skipped.
 		 */
 		if (unlikely(header_len > SFC_TSOH_STD_LEN))
 			return EMSGSIZE;
diff --git a/drivers/net/sfc/sfc_tso.c b/drivers/net/sfc/sfc_tso.c
index f46c0e912..a882e64dd 100644
--- a/drivers/net/sfc/sfc_tso.c
+++ b/drivers/net/sfc/sfc_tso.c
@@ -119,6 +119,8 @@ sfc_efx_tso_do(struct sfc_efx_txq *txq, unsigned int idx,
 		/*
 		 * Discard a packet if header linearization is needed but
 		 * the header is too big.
+		 * Duplicate Tx prepare check here to avoid spoil of
+		 * memory if Tx prepare is skipped.
 		 */
 		if (unlikely(header_len > SFC_TSOH_STD_LEN))
 			return EMSGSIZE;
-- 
2.17.1



More information about the dev mailing list