[dpdk-dev] [memnic PATCH 2/5] pmd: check frame length from host

Hiroshi Shimamoto h-shimamoto at ct.jp.nec.com
Tue Mar 11 06:38:12 CET 2014


From: Hiroshi Shimamoto <h-shimamoto at ct.jp.nec.com>

Drop packets which have invalid length.

Normally this must not happen while vSwitch works fine, however
it's better to put a sentinel to prevent memory corruption.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto at ct.jp.nec.com>
Reviewed-by: Hayato Momma <h-momma at ce.jp.nec.com>
---
 pmd/pmd_memnic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/pmd/pmd_memnic.c b/pmd/pmd_memnic.c
index 805f0b2..bf5fc2e 100644
--- a/pmd/pmd_memnic.c
+++ b/pmd/pmd_memnic.c
@@ -226,6 +226,8 @@ static uint16_t memnic_recv_pkts(void *rx_queue,
 		p = &data->packets[idx];
 		if (p->status != MEMNIC_PKT_ST_FILLED)
 			break;
+		if (p->len > MEMNIC_MAX_FRAME_LEN)
+			goto drop;
 		mb = rte_pktmbuf_alloc(adapter->mp);
 		if (!mb)
 			break;
@@ -238,6 +240,7 @@ static uint16_t memnic_recv_pkts(void *rx_queue,
 		mb->pkt.data_len = p->len;
 		rx_pkts[nr] = mb;
 
+drop:
 		rte_mb();
 		p->status = MEMNIC_PKT_ST_FREE;
 
-- 
1.8.4



More information about the dev mailing list