From bf3785fbd887c4a0be5b416c0800b1c1581c3081 Mon Sep 17 00:00:00 2001 From: Andrew Rybchenko Date: Wed, 27 May 2020 15:31:41 +0100 Subject: [PATCH] net: check first segment length on SW VLAN insertion SW VLAN insertion relies on Ethernet addresses location in contiguous memory (do not split across mbuf segments). There is no any formal requirements on data location and mbuf structure which guarantee it. So, check it explicitly to avoid corrupted packets if the condition is violated. Typically software VLAN insertion is done on Tx prepare stage and application will get indication that the packet is invalid and cannot be transmitted. Signed-off-by: Andrew Rybchenko Reviewed-by: Ferruh Yigit --- lib/librte_net/rte_ether.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h index 42f2c3288c..060b63fc9b 100644 --- a/lib/librte_net/rte_ether.h +++ b/lib/librte_net/rte_ether.h @@ -353,6 +353,10 @@ static inline int rte_vlan_insert(struct rte_mbuf **m) if (!RTE_MBUF_DIRECT(*m) || rte_mbuf_refcnt_read(*m) > 1) return -EINVAL; + /* Can't insert header if the first segment is too short */ + if (rte_pktmbuf_data_len(*m) < 2 * RTE_ETHER_ADDR_LEN) + return -EINVAL; + oh = rte_pktmbuf_mtod(*m, struct rte_ether_hdr *); nh = (struct rte_ether_hdr *) rte_pktmbuf_prepend(*m, sizeof(struct rte_vlan_hdr)); -- 2.20.1